test: test for the actual better clone- and make sure we use the JSON stringify and parse for this since tests are weird
ref: N25B-371
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { useDraggable } from '@neodrag/react';
|
||||
import { useReactFlow, type XYPosition } from '@xyflow/react';
|
||||
import { type ReactNode, useCallback, useRef, useState } from 'react';
|
||||
import useFlowStore from '../VisProgStores';
|
||||
import styles from '../../VisProg.module.css';
|
||||
import { NodeDefaults, type NodeTypes } from '../NodeRegistry'
|
||||
import addNode from '../utils/AddNode';
|
||||
|
||||
/**
|
||||
* DraggableNodeProps dictates the type properties of a DraggableNode
|
||||
@@ -47,41 +47,6 @@ function DraggableNode({ className, children, nodeType, onDrop }: DraggableNodeP
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* addNode — adds a new node to the flow using the unified class-based system.
|
||||
* Keeps numbering logic for phase/norm nodes.
|
||||
*/
|
||||
function addNode(nodeType: keyof typeof NodeTypes, position: XYPosition) {
|
||||
const { nodes, setNodes } = useFlowStore.getState();
|
||||
|
||||
// Find out if there's any default data about our ndoe
|
||||
const defaultData = NodeDefaults[nodeType] ?? {}
|
||||
|
||||
// Currently, we find out what the Id is by checking the last node and adding one
|
||||
const sameTypeNodes = nodes.filter((node) => node.type === nodeType);
|
||||
const nextNumber =
|
||||
sameTypeNodes.length > 0
|
||||
? (() => {
|
||||
const lastNode = sameTypeNodes[sameTypeNodes.length - 1];
|
||||
const parts = lastNode.id.split('-');
|
||||
const lastNum = Number(parts[1]);
|
||||
return Number.isNaN(lastNum) ? sameTypeNodes.length + 1 : lastNum + 1;
|
||||
})()
|
||||
: 1;
|
||||
const id = `${nodeType}-${nextNumber}`;
|
||||
|
||||
// Create new node
|
||||
const newNode = {
|
||||
id: id,
|
||||
type: nodeType,
|
||||
position,
|
||||
// Deep copy using JSON because thats how things work:
|
||||
// Ref: https://developer.mozilla.org/en-US/docs/Glossary/Deep_copy
|
||||
data: structuredClone(defaultData)
|
||||
}
|
||||
setNodes([...nodes, newNode]);
|
||||
}
|
||||
|
||||
/**
|
||||
* DndToolbar defines how the drag and drop toolbar component works
|
||||
* and includes the default onDrop behavior.
|
||||
|
||||
Reference in New Issue
Block a user