fix(tabsContext.tsx): add checkOldEdgesHandles function to ensure that only old edges with invalid handles are updated

fix(reactflowUtils.ts): rename checkEdgesHandles function to checkOldEdgesHandles for clarity
This commit is contained in:
anovazzi1 2023-08-04 16:04:52 -03:00
commit b656efba7d
2 changed files with 6 additions and 3 deletions

View file

@ -27,6 +27,7 @@ import {
import { TabsContextType, TabsState } from "../types/tabs"; import { TabsContextType, TabsState } from "../types/tabs";
import { import {
addVersionToDuplicates, addVersionToDuplicates,
checkOldEdgesHandles,
scapeJSONParse, scapeJSONParse,
scapedJSONStringfy, scapedJSONStringfy,
updateEdgesHandleIds, updateEdgesHandleIds,
@ -154,8 +155,10 @@ export function TabsProvider({ children }: { children: ReactNode }) {
function processFlowEdges(flow: FlowType) { function processFlowEdges(flow: FlowType) {
if (!flow.data || !flow.data.edges) return; if (!flow.data || !flow.data.edges) return;
const newEdges = updateEdgesHandleIds(flow.data); if (checkOldEdgesHandles(flow.data.edges)) {
flow.data.edges = newEdges; const newEdges = updateEdgesHandleIds(flow.data);
flow.data.edges = newEdges;
}
flow.data.edges.forEach((edge) => { flow.data.edges.forEach((edge) => {
edge.className = ""; edge.className = "";
edge.style = { stroke: "#555" }; edge.style = { stroke: "#555" };

View file

@ -297,7 +297,7 @@ export function scapeJSONParse(json: string): any {
} }
// this function receives an array of edges and return true if any of the handles are not a json string // 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 { export function checkOldEdgesHandles(edges: Edge[]): boolean {
return edges.some( return edges.some(
(edge) => (edge) =>
!edge.sourceHandle || !edge.sourceHandle ||