refactor(tabsContext.tsx): rename processFlowEdges and processFlowNodes functions to processDataFromFlow to improve clarity and consistency

refactor(tabsContext.tsx): remove console.log statement for old edges
refactor(tabsContext.tsx): add comments to indicate updating edges colors and baseclasses in edges
refactor(tabsContext.tsx): add comments to indicate updating baseclasses in edges
refactor(tabsContext.tsx): add comments to indicate adding animation to text type edges
refactor(tabsContext.tsx): update updateIds function to handle GroupNode type nodes
refactor(reactflowUtils.ts): update updateIds function to handle GroupNode type nodes
refactor(reactflowUtils.ts): update updateIds function to handle sourceHandle and targetHandle ids in edges
This commit is contained in:
anovazzi1 2023-09-21 10:56:50 -03:00
commit d9073aba39
2 changed files with 14 additions and 7 deletions

View file

@ -168,8 +168,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
if (!flow.data) { if (!flow.data) {
return; return;
} }
processFlowEdges(flow); processDataFromFlow(flow, false);
processFlowNodes(flow);
} catch (e) {} } catch (e) {}
}); });
} }
@ -177,10 +176,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;
if (checkOldEdgesHandles(flow.data.edges)) { if (checkOldEdgesHandles(flow.data.edges)) {
console.log("old edges");
const newEdges = updateEdgesHandleIds(flow.data); const newEdges = updateEdgesHandleIds(flow.data);
flow.data.edges = newEdges; flow.data.edges = newEdges;
} }
//update edges colors
flow.data.edges.forEach((edge) => { flow.data.edges.forEach((edge) => {
edge.className = ""; edge.className = "";
edge.style = { stroke: "#555" }; edge.style = { stroke: "#555" };
@ -208,6 +207,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
if (Object.keys(template["template"]).length > 0) { if (Object.keys(template["template"]).length > 0) {
updateDisplay_name(node, template); updateDisplay_name(node, template);
updateNodeBaseClasses(node, template); updateNodeBaseClasses(node, template);
//update baseclasses in edges
updateNodeEdges(flow, node, template); updateNodeEdges(flow, node, template);
updateNodeDescription(node, template); updateNodeDescription(node, template);
updateNodeTemplate(node, template); updateNodeTemplate(node, template);
@ -523,14 +523,15 @@ export function TabsProvider({ children }: { children: ReactNode }) {
} }
}; };
const processDataFromFlow = (flow: FlowType) => { const processDataFromFlow = (flow: FlowType, refreshIds = true) => {
let data = flow?.data ? flow.data : null; let data = flow?.data ? flow.data : null;
if (data) { if (data) {
processFlowEdges(flow); processFlowEdges(flow);
processFlowNodes(flow); processFlowNodes(flow);
//add animation to text type edges
updateEdges(data.edges); updateEdges(data.edges);
updateNodes(data.nodes, data.edges); // updateNodes(data.nodes, data.edges);
updateIds(data, getNodeId); // Assuming updateIds is defined elsewhere if (refreshIds) updateIds(data, getNodeId); // Assuming updateIds is defined elsewhere
} }
return data; return data;

View file

@ -163,7 +163,7 @@ export function updateIds(
newFlow.nodes.forEach((node: NodeType) => { newFlow.nodes.forEach((node: NodeType) => {
// Generate a unique node ID // Generate a unique node ID
let newId = getNodeId(node.data.type); let newId = getNodeId(node.data.node?.flow ? "GroupNode" : node.data.type);
idsMap[node.id] = newId; idsMap[node.id] = newId;
node.id = newId; node.id = newId;
node.data.id = newId; node.data.id = newId;
@ -180,6 +180,9 @@ export function updateIds(
...sourceHandleObject, ...sourceHandleObject,
id: edge.source, id: edge.source,
}); });
if (edge.data?.sourceHandle?.id) {
edge.data.sourceHandle.id = edge.source;
}
const targetHandleObject: targetHandleType = scapeJSONParse( const targetHandleObject: targetHandleType = scapeJSONParse(
edge.targetHandle! edge.targetHandle!
); );
@ -187,6 +190,9 @@ export function updateIds(
...targetHandleObject, ...targetHandleObject,
id: edge.target, id: edge.target,
}); });
if (edge.data?.targetHandle?.id) {
edge.data.targetHandle.id = edge.target;
}
edge.id = edge.id =
"reactflow__edge-" + "reactflow__edge-" +
edge.source + edge.source +