refactor: defaults should be in their own file, respecting eslint/ react standards. all tests fail, obviously.
ref: N25B-294
This commit is contained in:
@@ -2,51 +2,20 @@ import {
|
||||
Handle,
|
||||
type NodeProps,
|
||||
Position,
|
||||
type Connection,
|
||||
type Edge,
|
||||
useReactFlow,
|
||||
type Node,
|
||||
} from '@xyflow/react';
|
||||
import { Toolbar } from './NodeDefinitions';
|
||||
import { Toolbar } from '../components/NodeComponents';
|
||||
import styles from '../../VisProg.module.css';
|
||||
|
||||
export type EndNodeData = {
|
||||
label: string;
|
||||
droppable: Boolean;
|
||||
hasReduce: Boolean;
|
||||
};
|
||||
|
||||
|
||||
export const EndNodeDefaults: EndNodeData = {
|
||||
label: "End Node",
|
||||
droppable: false,
|
||||
hasReduce: true
|
||||
droppable: boolean;
|
||||
hasReduce: boolean;
|
||||
};
|
||||
|
||||
export type EndNode = Node<EndNodeData>
|
||||
|
||||
export function EndNodeCanConnect(connection: Connection | Edge): boolean {
|
||||
// connection has: { source, sourceHandle, target, targetHandle }
|
||||
|
||||
// Example rules:
|
||||
if (connection.source === connection.target) return false;
|
||||
|
||||
|
||||
if (connection.targetHandle && !["a", "b"].includes(connection.targetHandle)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (connection.sourceHandle && connection.sourceHandle !== "result") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If all rules pass
|
||||
return true;
|
||||
}
|
||||
|
||||
export default function EndNode(props: NodeProps<Node>) {
|
||||
const reactFlow = useReactFlow();
|
||||
const label_input_id = `phase_${props.id}_label_input`;
|
||||
return (
|
||||
<>
|
||||
<Toolbar nodeId={props.id} allowDelete={true}/>
|
||||
@@ -54,7 +23,6 @@ export default function EndNode(props: NodeProps<Node>) {
|
||||
<div className={"flex-row gap-sm"}>
|
||||
End
|
||||
</div>
|
||||
<Handle type="target" position={Position.Left} id="target"/>
|
||||
<Handle type="target" position={Position.Bottom} id="norms"/>
|
||||
<Handle type="source" position={Position.Right} id="source"/>
|
||||
</div>
|
||||
@@ -63,11 +31,18 @@ export default function EndNode(props: NodeProps<Node>) {
|
||||
}
|
||||
|
||||
export function EndReduce(node: Node, nodes: Node[]) {
|
||||
return {
|
||||
// Replace this for nodes functionality
|
||||
if (nodes.length <= -1) {
|
||||
console.warn("Impossible nodes length in EndReduce")
|
||||
}
|
||||
return {
|
||||
id: node.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function EndConnects(thisNode: Node, otherNode: Node, isThisSource: boolean) {
|
||||
|
||||
// Replace this for connection logic
|
||||
if (thisNode == undefined && otherNode == undefined && isThisSource == false) {
|
||||
console.warn("Impossible node connection called in EndConnects")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user