chore: added warnings

Warning 1: if elements have the same name, show a warning.
Warning 2: if a goal/triggerNode has no/empty plan, show a warning.
Warning 3: if (non-phase) elements start with or are a number,
    show a warning.
This commit is contained in:
Pim Hutting
2026-01-30 12:31:09 +01:00
parent e3abf8c14a
commit d514c2ef50
8 changed files with 154 additions and 14 deletions

View File

@@ -240,10 +240,14 @@ const useFlowStore = create<FlowState>(UndoRedo((set, get) => ({
).then(() => {
get().unregisterNodeRules(nodeId);
get().unregisterWarningsForId(nodeId);
// Re-validate after deletion is finished
get().validateDuplicateNames(get().nodes);
});
} else {
const remainingNodes = get().nodes.filter((n) => n.id !== nodeId);
get().validateDuplicateNames(remainingNodes); // Re-validate survivors
set({
nodes: get().nodes.filter((n) => n.id !== nodeId),
nodes: remainingNodes,
edges: get().edges.filter((e) => e.source !== nodeId && e.target !== nodeId),
})
}
@@ -265,15 +269,49 @@ const useFlowStore = create<FlowState>(UndoRedo((set, get) => ({
*/
updateNodeData: (nodeId, data) => {
get().pushSnapshot();
set({
nodes: get().nodes.map((node) => {
if (node.id === nodeId) {
node = { ...node, data: { ...node.data, ...data }};
}
return node;
}),
const updatedNodes = get().nodes.map((node) => {
if (node.id === nodeId) {
return { ...node, data: { ...node.data, ...data } };
}
return node;
});
get().validateDuplicateNames(updatedNodes); // Re-validate after update
set({ nodes: updatedNodes });
},
//helper function to see if any of the nodes have duplicate names
validateDuplicateNames: (nodes: Node[]) => {
const nameMap = new Map<string, string[]>();
// 1. Group IDs by their identifier (name, norm, or label)
nodes.forEach((n) => {
const name = (n.data.name || n.data.norm )?.toString().trim();
if (name) {
if (!nameMap.has(name)) nameMap.set(name, []);
nameMap.get(name)!.push(n.id);
}
});
// 2. Scan nodes and toggle the warning
nodes.forEach((n) => {
const name = (n.data.name || n.data.norm )?.toString().trim();
const isDuplicate = name ? (nameMap.get(name)?.length || 0) > 1 : false;
if (isDuplicate) {
get().registerWarning({
scope: { id: n.id },
type: 'DUPLICATE_ELEMENT_NAME',
severity: 'ERROR',
description: `The name "${name}" is already used by another element.`
});
} else {
// This clears the warning if the "twin" was deleted or renamed
get().unregisterWarning(n.id, 'DUPLICATE_ELEMENT_NAME');
}
});
},
/**
* Adds a new node to the flow store.