diff options
Diffstat (limited to 'src/utils/chartUtils.js')
-rw-r--r-- | src/utils/chartUtils.js | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/utils/chartUtils.js b/src/utils/chartUtils.js index 66bc75a5..7d48a38a 100644 --- a/src/utils/chartUtils.js +++ b/src/utils/chartUtils.js @@ -1,20 +1,16 @@ import { generateUrl } from '@nextcloud/router' import { GROUP_ALL_CONTACTS } from '../models/constants.ts' -export const getChart = (list, parent, nodes = []) => { - if (!nodes.length) { - nodes.push(list.find(node => node.nodeId === parent)) - } - const children = list.filter(node => { - return node.parentNodeId === parent - }) - - children.forEach(node => { - nodes.push(node) - getChart(list, node.nodeId, nodes) +export const getChart = (allNodes, currentNode) => { + const result = [currentNode] + const children = allNodes.filter(node => { + return node.nodeId !== currentNode.nodeId && node.parentNodeId === currentNode.nodeId }) - return nodes + return [ + ...result, + ...children.flatMap(child => getChart(allNodes, child)), + ] } export const transformNode = (contact) => { |