|
|
|
|
@@ -16,6 +16,7 @@ import { BasicBeliefReduce } from './BasicBeliefNode';
|
|
|
|
|
import type { GoalNode } from './GoalNode.tsx';
|
|
|
|
|
import { defaultPlan } from '../components/Plan.default.ts';
|
|
|
|
|
import { deleteGoalInPlanByID, insertGoalInPlan } from '../components/PlanEditingFunctions.tsx';
|
|
|
|
|
import { TextField } from '../../../../components/TextField.tsx';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The default data structure for a Trigger node
|
|
|
|
|
@@ -29,6 +30,7 @@ import { deleteGoalInPlanByID, insertGoalInPlan } from '../components/PlanEditin
|
|
|
|
|
*/
|
|
|
|
|
export type TriggerNodeData = {
|
|
|
|
|
label: string;
|
|
|
|
|
name: string;
|
|
|
|
|
droppable: boolean;
|
|
|
|
|
condition?: string; // id of the belief
|
|
|
|
|
plan?: Plan;
|
|
|
|
|
@@ -58,10 +60,20 @@ export function TriggerNodeCanConnect(connection: Connection | Edge): boolean {
|
|
|
|
|
export default function TriggerNode(props: NodeProps<TriggerNode>) {
|
|
|
|
|
const data = props.data;
|
|
|
|
|
const {updateNodeData} = useFlowStore();
|
|
|
|
|
|
|
|
|
|
const setName= (value: string) => {
|
|
|
|
|
updateNodeData(props.id, {...data, name: value})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
|
|
|
|
|
<Toolbar nodeId={props.id} allowDelete={true}/>
|
|
|
|
|
<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"}>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>
|
|
|
|
|
@@ -113,6 +125,7 @@ export function TriggerReduce(node: Node, nodes: Node[]) {
|
|
|
|
|
const conditionData = conditionNode ? BasicBeliefReduce(conditionNode, nodes) : ""
|
|
|
|
|
return {
|
|
|
|
|
id: node.id,
|
|
|
|
|
name: node.data.name,
|
|
|
|
|
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 ""
|
|
|
|
|
}
|
|
|
|
|
|