Skip to content

Commit

Permalink
refactor: tracking updates for deleted nodes (langflow-ai#4027)
Browse files Browse the repository at this point in the history
* tracking updates for deleted nodes

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and diogocabral committed Nov 26, 2024
1 parent 0da603b commit eebcd4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ export default function Page({ view }: { view?: boolean }): JSX.Element {
track("Component Connection Deleted");
}
if (lastSelection.nodes?.length) {
track("Component Deleted");
lastSelection.nodes.forEach((n) => {
track("Component Deleted", { componentType: n.data.type });
});
}
deleteNode(lastSelection.nodes.map((node) => node.id));
deleteEdge(lastSelection.edges.map((edge) => edge.id));
Expand Down
32 changes: 25 additions & 7 deletions src/frontend/src/stores/flowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,32 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
return get().nodes.find((node) => node.id === id);
},
deleteNode: (nodeId) => {
get().setNodes(
get().nodes.filter((node) =>
typeof nodeId === "string"
? node.id !== nodeId
: !nodeId.includes(node.id),
),
const { filteredNodes, deletedNode } = get().nodes.reduce<{
filteredNodes: Node[];
deletedNode: Node | null;
}>(
(acc, node) => {
const isMatch =
typeof nodeId === "string"
? node.id === nodeId
: nodeId.includes(node.id);

if (isMatch) {
acc.deletedNode = node;
} else {
acc.filteredNodes.push(node);
}

return acc;
},
{ filteredNodes: [], deletedNode: null },
);
track("Component Deleted", { nodeId });

get().setNodes(filteredNodes);

if (deletedNode) {
track("Component Deleted", { componentType: deletedNode.data.type });
}
},
deleteEdge: (edgeId) => {
get().setEdges(
Expand Down

0 comments on commit eebcd4b

Please sign in to comment.