Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display reasons why module was included #85

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
42 changes: 42 additions & 0 deletions client/components/ModuleSearch.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/** @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);
}

componentDidMount( ) {
this.input.focus();
}

render( ) {

const { query } = this.props;
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.props.onChange}/>
<ModuleList className={s.list} modules={modules} onModuleClick={this.props.onModuleClick}/>
</div>
);
}

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;
}