chore: add name field to trigger nodes

This commit is contained in:
Björn Otgaar
2026-01-08 14:09:44 +01:00
parent c7ed3c8ef2
commit 96afba2a1d
3 changed files with 17 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import type { TriggerNodeData } from "./TriggerNode";
*/ */
export const TriggerNodeDefaults: TriggerNodeData = { export const TriggerNodeDefaults: TriggerNodeData = {
label: "Trigger Node", label: "Trigger Node",
name: "",
droppable: true, droppable: true,
hasReduce: true, hasReduce: true,
}; };

View File

@@ -16,6 +16,7 @@ import { BasicBeliefReduce } from './BasicBeliefNode';
import type { GoalNode } from './GoalNode.tsx'; import type { GoalNode } from './GoalNode.tsx';
import { defaultPlan } from '../components/Plan.default.ts'; import { defaultPlan } from '../components/Plan.default.ts';
import { deleteGoalInPlanByID, insertGoalInPlan } from '../components/PlanEditingFunctions.tsx'; import { deleteGoalInPlanByID, insertGoalInPlan } from '../components/PlanEditingFunctions.tsx';
import { TextField } from '../../../../components/TextField.tsx';
/** /**
* The default data structure for a Trigger node * The default data structure for a Trigger node
@@ -29,6 +30,7 @@ import { deleteGoalInPlanByID, insertGoalInPlan } from '../components/PlanEditin
*/ */
export type TriggerNodeData = { export type TriggerNodeData = {
label: string; label: string;
name: string;
droppable: boolean; droppable: boolean;
condition?: string; // id of the belief condition?: string; // id of the belief
plan?: Plan; plan?: Plan;
@@ -59,9 +61,19 @@ export default function TriggerNode(props: NodeProps<TriggerNode>) {
const data = props.data; const data = props.data;
const {updateNodeData} = useFlowStore(); const {updateNodeData} = useFlowStore();
const setName= (value: string) => {
updateNodeData(props.id, {...data, name: value})
}
return <> return <>
<Toolbar nodeId={props.id} allowDelete={true}/> <Toolbar nodeId={props.id} allowDelete={true}/>
<div className={`${styles.defaultNode} ${styles.nodeTrigger} flex-col gap-sm`}> <div className={`${styles.defaultNode} ${styles.nodeTrigger} flex-col gap-sm`}>
<TextField
value={props.data.name}
setValue={(val) => setName(val)}
placeholder={"Name of this trigger..."}
/>
<div className={"flex-row gap-md"}>Triggers when the condition is met.</div> <div className={"flex-row gap-md"}>Triggers when the condition is met.</div>
<div className={"flex-row gap-md"}>Condition/ Belief is currently {data.condition ? "" : "not"} set. {data.condition ? "🟢" : "🔴"}</div> <div className={"flex-row gap-md"}>Condition/ Belief is currently {data.condition ? "" : "not"} set. {data.condition ? "🟢" : "🔴"}</div>
<div className={"flex-row gap-md"}>Plan{data.plan ? (": " + data.plan.name) : ""} is currently {data.plan ? "" : "not"} set. {data.plan ? "🟢" : "🔴"}</div> <div className={"flex-row gap-md"}>Plan{data.plan ? (": " + data.plan.name) : ""} is currently {data.plan ? "" : "not"} set. {data.plan ? "🟢" : "🔴"}</div>
@@ -113,6 +125,7 @@ export function TriggerReduce(node: Node, nodes: Node[]) {
const conditionData = conditionNode ? BasicBeliefReduce(conditionNode, nodes) : "" const conditionData = conditionNode ? BasicBeliefReduce(conditionNode, nodes) : ""
return { return {
id: node.id, id: node.id,
name: node.data.name,
condition: conditionData, // Make sure we have a condition before reducing, or default to "" condition: conditionData, // Make sure we have a condition before reducing, or default to ""
plan: !data.plan ? "" : PlanReduce(nodes, data.plan), // Make sure we have a plan when reducing, or default to "" plan: !data.plan ? "" : PlanReduce(nodes, data.plan), // Make sure we have a plan when reducing, or default to ""
} }

View File

@@ -73,7 +73,8 @@ describe('TriggerNode', () => {
data: { data: {
...JSON.parse(JSON.stringify(TriggerNodeDefaults)), ...JSON.parse(JSON.stringify(TriggerNodeDefaults)),
condition: "belief-1", condition: "belief-1",
plan: defaultPlan plan: defaultPlan,
name: "trigger-1"
}, },
}; };
@@ -93,6 +94,7 @@ describe('TriggerNode', () => {
expect(result).toEqual({ expect(result).toEqual({
id: 'trigger-1', id: 'trigger-1',
name: "trigger-1",
condition: { condition: {
id: "belief-1", id: "belief-1",
keyword: "", keyword: "",