feat(store): Enable using a parentNode / parentNodeId to add child nodes

This commit is contained in:
Braks
2022-03-23 17:43:27 +01:00
parent 6a2c1b00d7
commit 9a8caf444c
3 changed files with 13 additions and 4 deletions
+4 -2
View File
@@ -214,10 +214,12 @@ export default (state: State, getters: ComputedGetters): Actions => {
setEdges(elements.filter(isEdge))
}
const addNodes: Actions['addNodes'] = (nodes, extent) => {
const addNodes: Actions['addNodes'] = (nodes, options) => {
const parsed = nodes.flatMap((node) => {
const children: GraphNode[] = []
parseChildren(node, undefined, children, extent ?? state.nodeExtent, getters.getNode.value)
const parent =
options && (typeof options.parentNode === 'string' ? getters.getNode.value(options.parentNode) : options.parentNode)
parseChildren(node, parent, children, options?.extent ?? state.nodeExtent, getters.getNode.value)
return children
})
state.nodes.push(...parsed)