-
-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user to filter and select modules; display reasons why module w…
…as included
- Loading branch information
1 parent
59d087e
commit bfb13db
Showing
16 changed files
with
371 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.button { | ||
display: block; | ||
background: none; | ||
border: none; | ||
font-family: inherit; | ||
font-size: inherit; | ||
max-width: 100%; | ||
float: right; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: initial; | ||
line-height: 1.25em; | ||
cursor: pointer; | ||
} | ||
|
||
.button:after { | ||
content: "."; | ||
display: block; | ||
float: left; | ||
width: 4em; | ||
margin: -1em -2em; | ||
color: #fff; | ||
background: #fff; | ||
background: linear-gradient(to right, rgba(255,255,255,1) 50%,rgba(255,255,255,0) 100%); | ||
} | ||
|
||
.content { | ||
float: right; | ||
min-width: 100%; | ||
margin-top: 0; | ||
margin-left: -1px; | ||
} | ||
|
||
|
||
|
||
.button:hover { | ||
text-decoration: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** @jsx h */ | ||
import { h } from 'preact'; | ||
import s from './ModuleButton.css'; | ||
|
||
const ModuleButton = ( { module, onClick } ) => ( | ||
<button className={s.button} type="button" onClick={onClick}> | ||
<div className={s.content}> | ||
{module.path.replace('./node_modules/', '~') | ||
.replace(/\/index\.(js|jsx)$/, '') | ||
} | ||
{module.reasons.length > 0 && ` (${module.reasons.length})`} | ||
</div> | ||
</button> | ||
); | ||
|
||
export default ModuleButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.wrapper { | ||
font-size: 11px; | ||
font-family: Verdana; | ||
} | ||
|
||
.path { | ||
overflow-wrap: break-word; | ||
} | ||
|
||
.reasons { | ||
margin-top: 10px; | ||
font-weight: bold; | ||
} | ||
|
||
.list { | ||
margin-top: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** @jsx h */ | ||
/* eslint-disable react/no-multi-comp */ | ||
import { h } from 'preact'; | ||
import cls from 'classnames'; | ||
import ModuleList from './ModuleList'; | ||
import s from './ModuleInfo.css'; | ||
import filesize from 'filesize'; | ||
|
||
import { SIZE_SWITCH_ITEMS } from '../constants'; | ||
|
||
const ModuleSize = ({ module, sizeType } ) => { | ||
const sizeProp = `${sizeType}Size`; | ||
const size = module[sizeProp]; | ||
const sizeLabel = SIZE_SWITCH_ITEMS.find(item => item.prop === sizeProp).label; | ||
|
||
return (typeof size === 'number') ? | ||
<div> | ||
{sizeLabel} size: <strong>{filesize(size)}</strong> | ||
</div> | ||
: | ||
null; | ||
}; | ||
|
||
const ModuleInfo = ({ module, className, onModuleClick } ) => ( | ||
<div className={cls(className, s.wrapper)}> | ||
<div><strong>{module.label}</strong></div> | ||
<br/> | ||
<ModuleSize module={module} sizeType="stat"/> | ||
<ModuleSize module={module} sizeType="parsed"/> | ||
<ModuleSize module={module} sizeType="gzip"/> | ||
{module.path && | ||
<span className={s.path}>Path: <strong>{module.path}</strong></span> | ||
} | ||
{module.reasons && | ||
[ | ||
<div key="reasons-header" className={s.reasons}>Reasons:</div>, | ||
<ModuleList key="reasons-list" className={s.list} modules={module.reasons} onModuleClick={onModuleClick}/> | ||
] | ||
} | ||
</div> | ||
); | ||
|
||
export default ModuleInfo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.list { | ||
padding: 0; | ||
margin: 0; | ||
list-style: none; | ||
} | ||
|
||
.listItem { | ||
display: flex; | ||
padding: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** @jsx h */ | ||
import { h } from 'preact'; | ||
import cls from 'classnames'; | ||
import ModuleButton from './ModuleButton'; | ||
import s from './ModuleList.css'; | ||
|
||
const ModuleList = ( { modules, onModuleClick, className } ) => ( | ||
<ul className={cls(s.list, className)}> | ||
{modules.map(module => ( | ||
<li key={module.id} className={s.listItem}> | ||
{ | ||
// eslint-disable-next-line react/jsx-no-bind | ||
}<ModuleButton module={module} onClick={onModuleClick.bind(null, module)}/> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
|
||
export default ModuleList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.wrapper { | ||
font-family: Verdana; | ||
font-size: 11px; | ||
} | ||
|
||
.input { | ||
padding: 2px; | ||
width: 100%; | ||
} | ||
|
||
.list { | ||
padding: 10px 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** @jsx h */ | ||
import { h, Component } from 'preact'; | ||
import ModuleList from './ModuleList'; | ||
import s from './ModuleSearch.css'; | ||
|
||
export default class ModuleSearch extends Component { | ||
|
||
constructor( props ) { | ||
super(props); | ||
this.state = { | ||
query: '' | ||
}; | ||
} | ||
|
||
componentDidMount( ) { | ||
this.input.focus(); | ||
} | ||
|
||
componentWillReceiveProps( nextProps ) { | ||
if (nextProps.query !== this.props.query) { | ||
this.setState({ query: nextProps.query }); | ||
} | ||
} | ||
|
||
render( ) { | ||
|
||
const { query } = this.state; | ||
let modules = []; | ||
|
||
if (query) { | ||
modules = this.props.modules.filter(module => ( | ||
module.path.indexOf(query) !== -1 | ||
)); | ||
} | ||
|
||
return ( | ||
<div className={s.wrapper}> | ||
<input ref={this.onRef} | ||
value={query} | ||
className={s.input} | ||
onInput={this.handleChange}/> | ||
<ModuleList className={s.list} modules={modules} onModuleClick={this.props.onModuleClick}/> | ||
</div> | ||
); | ||
} | ||
|
||
handleChange = event => { | ||
this.setState({ query: event.target.value }); | ||
} | ||
|
||
onRef = ref => { | ||
this.input = ref; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
.container, .map { | ||
position: relative; | ||
position: absolute; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.sidebarGroup { | ||
margin-bottom: 20px; | ||
clear: both; | ||
} | ||
|
||
.activeSize { | ||
font-weight: bold; | ||
} | ||
|
||
.moduleInfo { | ||
padding-bottom: 10px; | ||
border-bottom: 1px solid lightgrey; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.backButton { | ||
margin-bottom: 10px; | ||
} |
Oops, something went wrong.