Browse Source

Dashboard search filters out mismatched data.

zhuth 6 years ago
parent
commit
17f2c63376
1 changed files with 18 additions and 8 deletions
  1. 18 8
      src/components/dashboard/menu.jsx

+ 18 - 8
src/components/dashboard/menu.jsx

@@ -35,15 +35,27 @@ class DashboardMenu extends React.Component {
         return arr;
     }
 
-    reduceTree = (tree) => {
-        let arr = [ ...tree ];
+    reduceTree = (mode, tree, regLabel) => {
+        let arr = tree ? [ ...tree ] : [];
         for(let i = arr.length - 1; i >= 0; i--) {
             let t = arr[i];
             if(t.children && t.children.length > 0) {
-                t.children = this.reduceTree(t.children);
+                t.children = this.reduceTree(mode, t.children, regLabel);
             }
-            if((!t.children || t.children.length === 0) && t.type !== 'dashboard') {
-                arr.splice(i, 1);
+            if(mode === 'view') {
+                if((!t.children || t.children.length === 0) && t.type !== 'dashboard') {
+                    arr.splice(i, 1);
+                }
+                if(t.type === 'dashboard' && !!regLabel && t.name.search(new RegExp('(' + regLabel + '){1}', 'ig')) === -1) {
+                    arr.splice(i, 1);
+                }
+            }else {
+                if(t.type === 'dashboard') {
+                    arr.splice(i, 1);
+                }
+                if(t.type === 'menu' && !!regLabel && (t.name.search(new RegExp('(' + regLabel + '){1}', 'ig')) === -1) && (t.children.length === 0)) {
+                    arr.splice(i, 1);
+                }
             }
         }
         return arr;
@@ -53,9 +65,7 @@ class DashboardMenu extends React.Component {
         const { mode, dispatch } = this.props;
         const { editingKey } = this.state;
         let ftree = this.cloneTree(tree);
-        if(mode === 'view') {
-            ftree = this.reduceTree(ftree)
-        }
+        ftree = this.reduceTree(mode, ftree, regLabel)
         return ftree.filter(t => (mode === 'view' || t.type === 'menu')).sort((a, b) => a.index - b.index).map(t => {
             let title = <div className='node-title'>
                 <span>{ (t.code !== editingKey) ?