feature(Sidebar): BIG-374 filtering the sidebar items based on each item feature support.

This commit is contained in:
a.bouhuolia
2022-04-18 00:16:37 +02:00
parent 5e4e9c37c3
commit 8d1825a065
4 changed files with 198 additions and 59 deletions

33
src/utils/deep.js Normal file
View File

@@ -0,0 +1,33 @@
import _ from 'lodash';
import Deepdash from 'deepdash';
export const deepdash = Deepdash(_);
export const filterValuesDeep = (predicate, nodes) => {
return deepdash.condense(
deepdash.reduceDeep(
nodes,
(accumulator, value, key, parent, context) => {
const newValue = { ...value };
if (newValue.children) {
_.set(newValue, 'children', deepdash.condense(value.children));
}
const isTrue = predicate(newValue, key, parent, context);
if (isTrue === true) {
_.set(accumulator, context.path, newValue);
} else if (isTrue === false) {
_.unset(accumulator, context.path);
}
return accumulator;
},
[],
{
childrenPath: 'children',
pathFormat: 'array',
callbackAfterIterate: true,
},
),
);
};