import React, {PropTypes} from "react"; import {List, ListItem} from "material-ui/List"; import formatSize from "prettysize"; /* eslint-disable max-statements, react/jsx-indent-props, no-magic-numbers */ const listPkg = (totalSize, pkg, key) => { const nestModules = (modules) => Object.keys(modules).map((name, i) => { const m = modules[name]; const pt = `${name} [${formatSize(m.size)}]`; return ; }); const parentsStr = (parents) => parents.substr(1).split(":").join("/"); const byParents = Object.keys(pkg).filter((k) => k.startsWith("$")); const $ = pkg[byParents[0]]; let dups = ""; let nestedItems; let size = 0; if (byParents.length > 1) { dups = [{byParents.length} dups] ; size = byParents.reduce((acc, k) => acc + pkg[k].size, 0); nestedItems = byParents.sort().map((p, i) => { const pt = p === "$" ? "at top level" : `under ${parentsStr(p)}`; return (); }); } else { nestedItems = nestModules($.modules); size = $.size; } const pct = (size / totalSize) * 100; const name = $.name === "." ? "under app CWD" : $.name; const primaryText = (
{name} {dups} [{formatSize(size)}] [{pct.toFixed(2)}%]
); return (); }; const ModulesByPkg = (props) => { return ( {Object.keys(props.modulesByPkg).sort().map((name, key) => listPkg(props.totalSize, props.modulesByPkg[name], key))} ); }; ModulesByPkg.propTypes = { totalSize: PropTypes.number, modulesByPkg: PropTypes.object }; export default ModulesByPkg;