Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: tracking updates for deleted nodes #4027

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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