From d6168cabde82c25ceb4fa863228dda7f89b486b5 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 4 Aug 2023 15:39:14 -0300 Subject: [PATCH] feat(reactflowUtils.ts): add checkEdgesHandles function to validate if any of the handles in an array of edges are not a JSON string The checkEdgesHandles function is added to the reactflowUtils.ts file. This function takes an array of edges as input and returns true if any of the handles in the edges are not a JSON string. It checks each edge in the array and verifies if the sourceHandle and targetHandle properties exist and contain a JSON string. If any of the handles are not a JSON string, the function returns true. This function is useful for validating the integrity of the handles in the edges before further processing. --- src/frontend/src/utils/reactflowUtils.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 4e6e17f71..3e1484752 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -295,3 +295,14 @@ export function scapedJSONStringfy(json: object): string { export function scapeJSONParse(json: string): any { return JSON.parse(json.replace(/\\"/g, '"')); } + +// this function receives an array of edges and return true if any of the handles are not a json string +export function checkEdgesHandles(edges: Edge[]): boolean { + return edges.some( + (edge) => + !edge.sourceHandle || + !edge.targetHandle || + !edge.sourceHandle.includes("{") || + !edge.targetHandle.includes("{") + ); +}