feat: updated the phase node creation to better assign ids to new phase and norm nodes.

ref: N25B-114
This commit is contained in:
JGerla
2025-10-25 18:12:57 +02:00
parent 8038674167
commit e1d131e642

View File

@@ -10,6 +10,7 @@ import {
useState useState
} from 'react'; } from 'react';
import styles from "../../VisProg.module.css" import styles from "../../VisProg.module.css"
import useFlowStore from "../VisProgStores.tsx";
// Is used to make sure each subsequent node gets a unique id, so the ReactFlow implementation // Is used to make sure each subsequent node gets a unique id, so the ReactFlow implementation
// can distinguish between different nodes. // can distinguish between different nodes.
@@ -73,7 +74,8 @@ function DraggableNode({className, children, nodeType, onDrop}: DraggableNodePro
* @constructor * @constructor
*/ */
export function DndToolbar() { export function DndToolbar() {
const {setNodes, screenToFlowPosition} = useReactFlow(); const {screenToFlowPosition} = useReactFlow();
const {setNodes} = useReactFlow();
/** /**
* handleNodeDrop implements the default onDrop behavior * handleNodeDrop implements the default onDrop behavior
@@ -96,12 +98,17 @@ export function DndToolbar() {
const newNode = () => { const newNode = () => {
switch (nodeType) { switch (nodeType) {
case "phase": case "phase":
{
const nds = useFlowStore.getState().nodes;
const phaseNumber = nds.filter((node) => node.type === 'phase').length;
return { return {
id: getId(), id: `phase-${phaseNumber}`,
type: nodeType, type: nodeType,
position, position,
data: {label: `"new"`, number: (-1)}, data: {label: `"new"`, number: phaseNumber},
}; };
}
case "start": case "start":
return { return {
id: getId(), id: getId(),
@@ -117,12 +124,16 @@ export function DndToolbar() {
data: {label: `new end node`}, data: {label: `new end node`},
}; };
case "norm": case "norm":
{
const nds = useFlowStore.getState().nodes;
const normNumber = nds.filter((node) => node.type === 'norm').length;
return { return {
id: getId(), id: `norm-${normNumber}`,
type: nodeType, type: nodeType,
position, position,
data: {label: `new norm node`}, data: {label: `new norm node`},
}; };
}
default: { default: {
return { return {
id: getId(), id: getId(),