Merge remote-tracking branch 'origin/dev' into feat/send-program

# Conflicts:
#	src/pages/VisProgPage/visualProgrammingUI/nodes/TriggerNode.tsx
This commit is contained in:
Twirre Meulenbelt
2025-12-02 10:52:48 +01:00
18 changed files with 624 additions and 97 deletions

View File

@@ -14,10 +14,16 @@ import { RealtimeTextField, TextField } from '../../../../components/TextField';
import duplicateIndices from '../../../../utils/duplicateIndices';
/**
* The default data dot a Trigger node
* @param label: the label of this Trigger
* @param droppable: whether this node is droppable from the drop bar (initialized as true)
* @param children: ID's of children of this node
* The default data structure for a Trigger node
*
* Represents configuration for a node that activates when a specific condition is met,
* such as keywords being spoken or emotions detected.
*
* @property label: the display label of this Trigger node.
* @property droppable: Whether this node can be dropped from the toolbar (default: true).
* @property triggerType - The type of trigger ("keywords" or a custom string).
* @property triggers - The list of keyword triggers (if applicable).
* @property hasReduce - Whether this node supports reduction logic.
*/
export type TriggerNodeData = {
label: string;
@@ -31,14 +37,20 @@ export type TriggerNodeData = {
export type TriggerNode = Node<TriggerNodeData>
/**
* Determines whether a Trigger node can connect to another node or edge.
*
* @param connection - The connection or edge being attempted to connect towards.
* @returns `true` if the connection is defined; otherwise, `false`.
*/
export function TriggerNodeCanConnect(connection: Connection | Edge): boolean {
return (connection != undefined);
}
/**
* Defines how a Trigger node should be rendered
* @param props NodeProps, like id, label, children
* @returns React.JSX.Element
* @param props - Node properties provided by React Flow, including `id` and `data`.
* @returns The rendered TriggerNode React element (React.JSX.Element).
*/
export default function TriggerNode(props: NodeProps<TriggerNode>) {
const data = props.data;
@@ -66,9 +78,10 @@ export default function TriggerNode(props: NodeProps<TriggerNode>) {
}
/**
* Reduces each Trigger, including its children down into its relevant data.
* @param node The Node Properties of this node.
* @param nodes all the nodes in the graph.
* Reduces each Trigger, including its children down into its core data.
* @param node - The Trigger node to reduce.
* @param nodes - The list of all nodes in the current flow graph.
* @returns A simplified object containing the node label and its list of triggers.
*/
export function TriggerReduce(node: Node, nodes: Node[]) {
// Replace this for nodes functionality
@@ -93,10 +106,11 @@ export function TriggerReduce(node: Node, nodes: Node[]) {
}
/**
* This function is called whenever a connection is made with this node type (trigger)
* @param thisNode the node of this node type which function is called
* @param otherNode the other node which was part of the connection
* @param isThisSource whether this instance of the node was the source in the connection, true = yes.
* Handles logic that occurs when a connection is made involving a Trigger node.
*
* @param thisNode - The current Trigger node being connected.
* @param otherNode - The other node involved in the connection.
* @param isThisSource - Whether this node was the source of the connection.
*/
export function TriggerConnects(thisNode: Node, otherNode: Node, isThisSource: boolean) {
// Replace this for connection logic
@@ -106,23 +120,32 @@ export function TriggerConnects(thisNode: Node, otherNode: Node, isThisSource: b
}
// Definitions for the possible triggers, being keywords and emotions
/** Represents a single keyword trigger entry. */
type Keyword = { id: string, keyword: string };
/** Properties for an emotion-type trigger node. */
export type EmotionTriggerNodeProps = {
type: "emotion";
value: string;
}
/** Props for a keyword-type trigger node. */
export type KeywordTriggerNodeProps = {
type: "keywords";
value: Keyword[];
}
/** Union type for all possible Trigger node configurations. */
export type TriggerNodeProps = EmotionTriggerNodeProps | KeywordTriggerNodeProps;
/**
* The JSX element that is responsible for updating the field and showing the text
* @param param0 the function that updates the field
* @returns React.JSX.Element that handles adding keywords
* Renders an input element that allows users to add new keyword triggers.
*
* When the input is committed, the `addKeyword` callback is called with the new keyword.
*
* @param param0 - An object containing the `addKeyword` function.
* @returns A React element(React.JSX.Element) providing an input for adding keywords.
*/
function KeywordAdder({ addKeyword }: { addKeyword: (keyword: string) => void }) {
const [input, setInput] = useState("");
@@ -146,6 +169,14 @@ function KeywordAdder({ addKeyword }: { addKeyword: (keyword: string) => void })
</div>;
}
/**
* Displays and manages a list of keyword triggers for a Trigger node.
* Handles adding, editing, and removing keywords, as well as detecting duplicate entries.
*
* @param keywords - The current list of keyword triggers.
* @param setKeywords - A callback to update the keyword list in the parent node.
* @returns A React element(React.JSX.Element) for editing keyword triggers.
*/
function Keywords({
keywords,
setKeywords,