Skip to content

Commit

Permalink
fix(ui): SubWork Flow Multi Select Deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
billcookie committed Jan 7, 2025
1 parent e549d70 commit e90df18
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions ui/src/lib/yjs/useYWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,38 @@ export default ({
(nodeIds: string[]) =>
undoTrackerActionWrapper(() => {
const workflowIds: string[] = [];

const removeNodes = (nodeIds: string[]) => {
nodeIds.forEach((nid) => {
if (nid === DEFAULT_ENTRY_GRAPH_ID) return;

const index = rawWorkflows.findIndex((w) => w.id === nid);
if (index === -1) return;

// Loop over workflow at current index and remove any subworkflow nodes
(rawWorkflows[index].nodes as Node[]).forEach((node) => {
nodeIds.forEach((nid) => {
if (nid === DEFAULT_ENTRY_GRAPH_ID) return;
workflowIds.push(nid);
const workflow = rawWorkflows.find((w) => w.id === nid);
const nodes = workflow?.nodes;
// Loop over workflow and remove any subworkflow nodes
if (nodes && Array.isArray(nodes)) {
(nodes as Node[]).forEach((node) => {
if (node.type === "subworkflow") {
removeNodes([node.id]);
workflowIds.push(node.id);
}
});
}
});

workflowIds.push(nid);
yWorkflows.delete(index);
});
};
// Indexes in descending order to avoid index shifting problems
const indexesToRemove = workflowIds
.map((id) => rawWorkflows.findIndex((w) => w.id === id))
.filter((index) => index !== -1)
.sort((a, b) => b - a);

indexesToRemove.forEach((index) => {
yWorkflows.delete(index);
});

removeNodes(nodeIds);
setWorkflows((currentWorkflows) => {
const remainingWorkflows = currentWorkflows.filter(
(w) => !workflowIds.includes(w.id),
);
return remainingWorkflows;
});

setWorkflows((w) => w.filter((w) => !workflowIds.includes(w.id)));
setOpenWorkflowIds((ids) =>
ids.filter((id) => !workflowIds.includes(id)),
);
Expand Down

0 comments on commit e90df18

Please sign in to comment.