chore: add name field to trigger nodes
This commit is contained in:
@@ -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,
|
||||||
};
|
};
|
||||||
@@ -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;
|
||||||
@@ -58,10 +60,20 @@ export function TriggerNodeCanConnect(connection: Connection | Edge): boolean {
|
|||||||
export default function TriggerNode(props: NodeProps<TriggerNode>) {
|
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 ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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: "",
|
||||||
|
|||||||
Reference in New Issue
Block a user