feat: added rule based connection validation and connection limits to the editor

This commit is contained in:
Gerla, J. (Justin)
2026-01-07 13:32:53 +00:00
committed by Björn Otgaar
parent 6d1c17e77b
commit 9e7c192804
20 changed files with 672 additions and 89 deletions

View File

@@ -1,5 +1,4 @@
import {
Handle,
type NodeProps,
Position,
type Node,
@@ -7,6 +6,8 @@ import {
import { Toolbar } from '../components/NodeComponents';
import styles from '../../VisProg.module.css';
import { TextField } from '../../../../components/TextField';
import {MultiConnectionHandle} from "../components/RuleBasedHandle.tsx";
import {allowOnlyConnectionsFromHandle, allowOnlyConnectionsFromType} from "../HandleRules.ts";
import useFlowStore from '../VisProgStores';
import { BasicBeliefReduce } from './BasicBeliefNode';
@@ -74,9 +75,13 @@ export default function NormNode(props: NodeProps<NormNode>) {
<label htmlFor={checkbox_id}>{data.conditions.length} condition{data.conditions.length > 1 ? "s" : ""}/ belief{data.conditions.length > 1 ? "s" : ""} attached.</label>
</div>)}
<Handle type="source" position={Position.Right} id="norms"/>
<Handle type="target" position={Position.Bottom} id="norms"/>
<MultiConnectionHandle type="source" position={Position.Right} id="norms" rules={[
allowOnlyConnectionsFromHandle([{nodeType:"phase",handleId:"data"}])
]}/>
<MultiConnectionHandle type="target" position={Position.Bottom} id="beliefs" rules={[
allowOnlyConnectionsFromType(["basic_belief"])
]}/>
</div>
</>;
};
@@ -85,14 +90,14 @@ export default function NormNode(props: NodeProps<NormNode>) {
/**
* Reduces each Norm, including its children down into its relevant data.
* @param node The Node Properties of this node.
* @param _nodes all the nodes in the graph
* @param nodes all the nodes in the graph
*/
export function NormReduce(node: Node, nodes: Node[]) {
const data = node.data as NormNodeData;
// conditions nodes - make sure to check for empty arrays
let conditionNodes: Node[] = [];
if (data.conditions)
if (data.conditions)
conditionNodes = nodes.filter((node) => data.conditions.includes(node.id));
// Build the result object