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

@@ -69,7 +69,7 @@ export default function GoalNode({id, data}: NodeProps<GoalNode>) {
updateNodeData(id, {...data, can_fail: value});
}
//undefined plan warning
useEffect(() => {
const noPlanWarning : EditorWarning = {
scope: {
@@ -81,12 +81,31 @@ export default function GoalNode({id, data}: NodeProps<GoalNode>) {
description: "This goalNode is missing a plan, please make sure to create a plan by using the create plan button"
};
if (!data.plan){
if (!data.plan || data.plan.steps?.length === 0){
registerWarning(noPlanWarning);
return;
}
unregisterWarning(id, noPlanWarning.type);
},[data.plan, id, registerWarning, unregisterWarning])
//starts with number warning
useEffect(() => {
const name = data.name || "";
const startsWithNumberWarning: EditorWarning = {
scope: { id: id },
type: 'ELEMENT_STARTS_WITH_NUMBER',
severity: 'ERROR',
description: "Norms are not allowed to start with a number."
};
if (/^\d/.test(name)) {
registerWarning(startsWithNumberWarning);
} else {
unregisterWarning(id, 'ELEMENT_STARTS_WITH_NUMBER');
}
}, [data.name, id, registerWarning, unregisterWarning]);
return <>
<Toolbar nodeId={id} allowDelete={true}/>
<div className={`${styles.defaultNode} ${styles.nodeGoal} flex-col gap-sm`}>