From 65a43887c5d079753cec905cb26c5a1c797f65b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Mon, 21 Oct 2024 12:51:07 +0300 Subject: [PATCH] feat: added filtering for new coming nodes by node type --- src/stores/useDataStore/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stores/useDataStore/index.ts b/src/stores/useDataStore/index.ts index 705f63cc1..72dd1805e 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -323,13 +323,17 @@ export const useDataStore = create()( console.log(updatedNode) }, addNewNode: (data) => { - const { dataInitial: existingData } = get() + const { dataInitial: existingData, filters } = get() if (!data?.nodes) { return } - const uniqueIncomingNodes = deduplicateByRefId(data.nodes || []) + const nodesFilteredByFilters = filters.node_type.length + ? data.nodes.filter((node) => filters.node_type.some((t) => t === node.node_type)) + : data.nodes + + const uniqueIncomingNodes = deduplicateByRefId(nodesFilteredByFilters || []) const uniqueIncomingEdges = deduplicateByRefId(data.edges || []) // Step 2: Existing nodes and links from the current state