import { type NodeProps, Position, type Node, } from '@xyflow/react'; import { Toolbar } from '../components/NodeComponents'; import styles from '../../VisProg.module.css'; import { TextField } from '../../../../components/TextField'; import {MultiConnectionHandle} from "../components/RuleBasedHandle.tsx"; import {allowOnlyConnectionsFromHandle} from "../HandleRules.ts"; import useFlowStore from '../VisProgStores'; import { DoesPlanIterate, PlanReduce, type Plan } from '../components/Plan'; import PlanEditorDialog from '../components/PlanEditor'; import { MultilineTextField } from '../../../../components/MultilineTextField'; /** * The default data dot a phase node * @param label: the label of this phase * @param droppable: whether this node is droppable from the drop bar (initialized as true) * @param desciption: description of the goal - this will be checked for completion * @param hasReduce: whether this node has reducing functionality (true by default) * @param can_fail: whether this plan should be checked- this plan could possible fail * @param plan: The (possible) attached plan to this goal */ export type GoalNodeData = { label: string; name: string; description: string; droppable: boolean; achieved: boolean; hasReduce: boolean; can_fail: boolean; plan?: Plan; }; export type GoalNode = Node /** * Defines how a Goal node should be rendered * @param props NodeProps, like id, label, children * @returns React.JSX.Element */ export default function GoalNode({id, data}: NodeProps) { const {updateNodeData} = useFlowStore(); const text_input_id = `goal_${id}_text_input`; const checkbox_id = `goal_${id}_checkbox`; const planIterate = DoesPlanIterate(data.plan); const setDescription = (value: string) => { updateNodeData(id, {...data, description: value}); } const setName= (value: string) => { updateNodeData(id, {...data, name: value}) } const setFailable = (value: boolean) => { updateNodeData(id, {...data, can_fail: value}); } return <>
setName(val)} placeholder={"To ..."} />
{data.can_fail && (
)}
{data.plan && (
{planIterate ? "" : } planIterate ? setFailable(e.target.checked) : setFailable(false)} />
)}
{ updateNodeData(id, { ...data, plan, }); }} description={data.name} />
; } /** * Reduces each Goal, including its children down into its relevant data. * @param node The Node Properties of this node. * @param _nodes all the nodes in the graph */ export function GoalReduce(node: Node, _nodes: Node[]) { const data = node.data as GoalNodeData; return { id: node.id, name: data.name, description: data.description, can_fail: data.can_fail, plan: data.plan ? PlanReduce(data.plan) : "", } } export const GoalTooltip = ` The goal node allows you to set goals that Pepper has to achieve before moving to the next phase of your program`; /** * This function is called whenever a connection is made with this node type as the target * @param _thisNode the node of this node type which function is called * @param _sourceNodeId the source of the received connection */ export function GoalConnectionTarget(_thisNode: Node, _sourceNodeId: string) { // no additional connection logic exists yet } /** * This function is called whenever a connection is made with this node type as the source * @param _thisNode the node of this node type which function is called * @param _targetNodeId the target of the created connection */ export function GoalConnectionSource(_thisNode: Node, _targetNodeId: string) { // no additional connection logic exists yet } /** * This function is called whenever a connection is disconnected with this node type as the target * @param _thisNode the node of this node type which function is called * @param _sourceNodeId the source of the disconnected connection */ export function GoalDisconnectionTarget(_thisNode: Node, _sourceNodeId: string) { // no additional connection logic exists yet } /** * This function is called whenever a connection is disconnected with this node type as the source * @param _thisNode the node of this node type which function is called * @param _targetNodeId the target of the diconnected connection */ export function GoalDisconnectionSource(_thisNode: Node, _targetNodeId: string) { // no additional connection logic exists yet }