fix(store): remove action not properly removing elements

This commit is contained in:
braks
2022-10-08 02:01:03 +02:00
committed by Braks
parent 660fb366f7
commit 9168d7bd75
2 changed files with 22 additions and 9 deletions

View File

@@ -8,18 +8,19 @@ export function getElements(xElements = 10, yElements = 10) {
for (let y = 0; y < yElements; y++) {
for (let x = 0; x < xElements; x++) {
const position = { x: x * 100, y: y * 50 }
const node = {
initialNodes.push({
id: nodeId.toString(),
style: { width: 50, fontSize: 11 },
label: `Node ${nodeId}`,
type: '',
position,
style: (node) => {
const style: Record<string, any> = { width: `50px`, fontSize: `11px`, zIndex: 1 }
if (node.selected) style.border = '1px solid red'
return style
},
position: { x: x * 100, y: y * 50 },
data: {
randomData: Math.floor(Math.random() * 1e3),
},
}
initialNodes.push(node)
})
if (recentNodeId && nodeId <= xElements * yElements) {
initialEdges.push({

View File

@@ -169,11 +169,23 @@ export default (state: State, getters: ComputedGetters): Actions => {
}
const removeSelectedNodes: Actions['removeSelectedNodes'] = (nodes) => {
nodeSelectionHandler(nodes, false)
if (!nodes.length) return nodeSelectionHandler(nodes, false)
const nodeIds = nodes.map((n) => n.id)
const changedNodes = nodeIds.map((nodeId) => createSelectionChange(nodeId, false))
if (changedNodes.length) state.hooks.nodesChange.trigger(changedNodes)
}
const removeSelectedEdges: Actions['removeSelectedEdges'] = (edges) => {
edgeSelectionHandler(edges, false)
if (!edges.length) edgeSelectionHandler(edges, false)
const edgeIds = edges.map((e) => e.id)
const changedEdges = edgeIds.map((edgeId) => createSelectionChange(edgeId, false))
if (changedEdges.length) state.hooks.edgesChange.trigger(changedEdges)
}
const removeSelectedElements: Actions['removeSelectedElements'] = (elements) => {