mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feature(Sidebar): BIG-374 filtering the sidebar items based on each item feature support.
This commit is contained in:
33
src/utils/deep.js
Normal file
33
src/utils/deep.js
Normal 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,
|
||||
},
|
||||
),
|
||||
);
|
||||
};
|
||||
@@ -14,6 +14,8 @@ import { isEqual } from 'lodash';
|
||||
|
||||
import jsCookie from 'js-cookie';
|
||||
|
||||
export * from './deep';
|
||||
|
||||
export const getCookie = (name, defaultValue) =>
|
||||
_.defaultTo(jsCookie.get(name), defaultValue);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user