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.
This commit is contained in:
anovazzi1 2023-08-04 15:39:14 -03:00
commit d6168cabde

View file

@ -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("{")
);
}