Skip to content

Commit

Permalink
Allow user to filter and select modules; display reasons why module w…
Browse files Browse the repository at this point in the history
…as included
  • Loading branch information
dgieselaar committed Jun 4, 2017
1 parent 59d087e commit bfb13db
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 44 deletions.
38 changes: 38 additions & 0 deletions client/components/ModuleButton.css
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;
}
16 changes: 16 additions & 0 deletions client/components/ModuleButton.jsx
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;
17 changes: 17 additions & 0 deletions client/components/ModuleInfo.css
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;
}
43 changes: 43 additions & 0 deletions client/components/ModuleInfo.jsx
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;
10 changes: 10 additions & 0 deletions client/components/ModuleList.css
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;
}
19 changes: 19 additions & 0 deletions client/components/ModuleList.jsx
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;
13 changes: 13 additions & 0 deletions client/components/ModuleSearch.css
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;
}
55 changes: 55 additions & 0 deletions client/components/ModuleSearch.jsx
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;
}

}
14 changes: 13 additions & 1 deletion client/components/ModulesTreemap.css
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;
}

0 comments on commit bfb13db

Please sign in to comment.