diff --git a/client/components/ModulesTreemap.css b/client/components/ModulesTreemap.css index 2ff07cd7..46af0a23 100644 --- a/client/components/ModulesTreemap.css +++ b/client/components/ModulesTreemap.css @@ -53,3 +53,12 @@ .foundModulesList { margin-left: 7px; } + +.searchMode { + border: 1px solid #aaa; + border-radius: 4px; + display: block; + flex: 1; + padding: 5px; +} + diff --git a/client/components/ModulesTreemap.jsx b/client/components/ModulesTreemap.jsx index 1afe3a9b..597d3b63 100644 --- a/client/components/ModulesTreemap.jsx +++ b/client/components/ModulesTreemap.jsx @@ -17,6 +17,7 @@ import s from './ModulesTreemap.css'; import Search from './Search'; import {store} from '../store'; import ModulesList from './ModulesList'; +import SEARCH_MODE from '../searchMode'; const SIZE_SWITCH_ITEMS = [ {label: 'Stat', prop: 'statSize'}, @@ -79,7 +80,18 @@ export default class ModulesTreemap extends Component { }
- + + + +
+
+ @@ -254,6 +266,10 @@ export default class ModulesTreemap extends Component { store.searchQuery = query; } + handleSearchModeChange = e => { + store.searchMode = e.target.value; + } + handleSelectedChunksChange = selectedChunks => { store.selectedChunks = selectedChunks; }; diff --git a/client/components/Search.jsx b/client/components/Search.jsx index 1e5a8772..eaea989e 100644 --- a/client/components/Search.jsx +++ b/client/components/Search.jsx @@ -17,12 +17,12 @@ export default class Search extends PureComponent { } render() { - const {label, query} = this.props; + const {label, query, mode} = this.props; return (
- {label}: + {label + ' ' + mode}:
{ let foundGroups = []; - walkModules(chunk.groups, module => { - let weight = 0; - - /** - * Splitting found modules/directories into groups: - * - * 1) Module with matched label (weight = 4) - * 2) Directory with matched label (weight = 3) - * 3) Module with matched path (weight = 2) - * 4) Directory with matched path (weight = 1) - */ - if (query.test(module.label)) { - weight += 3; - } else if (module.path && query.test(module.path)) { - weight++; - } - - if (!weight) return; - - if (!module.groups) { - weight += 1; + if (this.searchMode === SEARCH_MODE.MODULES) { + walkModules(chunk.groups, module => { + let weight = 0; + + /** + * Splitting found modules/directories into groups: + * + * 1) Module with matched label (weight = 4) + * 2) Directory with matched label (weight = 3) + * 3) Module with matched path (weight = 2) + * 4) Directory with matched path (weight = 1) + */ + if (query.test(module.label)) { + weight += 3; + } else if (module.path && query.test(module.path)) { + weight++; + } + + if (!weight) return; + + if (!module.groups) { + weight += 1; + } + + const foundModules = foundGroups[weight - 1] = foundGroups[weight - 1] || []; + foundModules.push(module); + }); + + const {activeSize} = this; + + // Filtering out missing groups + foundGroups = foundGroups.filter(Boolean).reverse(); + // Sorting each group by active size + foundGroups.forEach(modules => + modules.sort((m1, m2) => m2[activeSize] - m1[activeSize]) + ); + + return { + chunk, + modules: [].concat(...foundGroups) + }; + } else { + let modules = []; + if (query.test(chunk.label)) { + modules = chunk.groups; } - const foundModules = foundGroups[weight - 1] = foundGroups[weight - 1] || []; - foundModules.push(module); - }); - - const {activeSize} = this; - - // Filtering out missing groups - foundGroups = foundGroups.filter(Boolean).reverse(); - // Sorting each group by active size - foundGroups.forEach(modules => - modules.sort((m1, m2) => m2[activeSize] - m1[activeSize]) - ); - - return { - chunk, - modules: [].concat(...foundGroups) - }; + return { + chunk, + modules + }; + } }) .filter(result => result.modules.length > 0) .sort((c1, c2) => c1.modules.length - c2.modules.length); diff --git a/gulpfile.js b/gulpfile.js index 3a5a9e6e..b57056ae 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,8 +2,9 @@ const gulp = require('gulp'); -const NODE_SRC = './src/**/*.js'; +const NODE_SRC = ['./src/**/*.js']; const NODE_DEST = './lib'; +const VIEWER_SRC = ['./client/**/*']; const cli = require('commander') .usage(' [options]') @@ -32,7 +33,7 @@ class TaskError extends Error { function watch() { gulp - .watch(NODE_SRC, gulp.series(cleanNodeScripts, compileNodeScripts)) + .watch(NODE_SRC.concat(VIEWER_SRC), gulp.series(cleanNodeScripts, compileNodeScripts, compileViewerScripts)) // TODO: replace with `emitErrors: false` option after https://github.com/gulpjs/glob-watcher/pull/34 will be merged .on('error', () => {}); }