summaryrefslogtreecommitdiffstats
path: root/src/utils/chartUtils.js
blob: 7d48a38a5378c89afebc4fd29b6f72882e4b2f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { generateUrl } from '@nextcloud/router'
import { GROUP_ALL_CONTACTS } from '../models/constants.ts'

export const getChart = (allNodes, currentNode) => {
	const result = [currentNode]
	const children = allNodes.filter(node => {
		return node.nodeId !== currentNode.nodeId && node.parentNodeId === currentNode.nodeId
	})

	return [
		...result,
		...children.flatMap(child => getChart(allNodes, child)),
	]
}

export const transformNode = (contact) => {
	return {
		nodeId: contact.uid,
		key: contact.key,
		parentNodeId: contact.managersName,
		fullName: contact.displayName,
		org: contact.org,
		photoUrl: `${contact.url}?photo`,
		title: contact.title,
		link: generateUrl(`apps/contacts/${GROUP_ALL_CONTACTS}/${contact.key}`),
		expanded: !contact.managersName,
	}
}