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,15 +2,11 @@ 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';
|
||||
import { NodeDefaults, NodeReduces } from '../NodeRegistry';
|
||||
import type { FlowState } from '../VisProgTypes';
|
||||
|
||||
/**
|
||||
* The default data dot a phase node
|
||||
@@ -25,26 +21,9 @@ export type PhaseNodeData = {
|
||||
hasReduce: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Default data for this node
|
||||
*/
|
||||
export const PhaseNodeDefaults: PhaseNodeData = {
|
||||
label: "Phase Node",
|
||||
droppable: true,
|
||||
children: [],
|
||||
hasReduce: true,
|
||||
};
|
||||
|
||||
export type PhaseNode = Node<PhaseNodeData>
|
||||
|
||||
/**
|
||||
*
|
||||
* @param connection
|
||||
* @returns
|
||||
*/
|
||||
export function PhaseNodeCanConnect(connection: Connection | Edge): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines how a phase node should be rendered
|
||||
@@ -52,7 +31,6 @@ export function PhaseNodeCanConnect(connection: Connection | Edge): boolean {
|
||||
* @returns React.JSX.Element
|
||||
*/
|
||||
export default function PhaseNode(props: NodeProps<Node>) {
|
||||
const reactFlow = useReactFlow();
|
||||
const label_input_id = `phase_${props.id}_label_input`;
|
||||
return (
|
||||
<>
|
||||
@@ -65,6 +43,7 @@ export default function PhaseNode(props: NodeProps<Node>) {
|
||||
<Handle type="target" position={Position.Left} id="target"/>
|
||||
<Handle type="source" position={Position.Right} id="source"/>
|
||||
<Handle type="source" position={Position.Bottom} id="norms"/>
|
||||
<Handle type="source" position={Position.Top} id="norms"/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
@@ -78,16 +57,16 @@ export function PhaseReduce(node: Node, nodes: Node[]) {
|
||||
const thisnode = node as PhaseNode;
|
||||
const data = thisnode.data as PhaseNodeData;
|
||||
const reducableChildren = Object.entries(NodeDefaults)
|
||||
.filter(([_, data]) => data.hasReduce)
|
||||
.map(([type, _]) => (
|
||||
.filter(([, data]) => data.hasReduce)
|
||||
.map(([type]) => (
|
||||
type
|
||||
));
|
||||
|
||||
let childrenData: any = ""
|
||||
let childrenData: unknown = ""
|
||||
if (data.children != undefined) {
|
||||
childrenData = data.children.map((childId) => {
|
||||
// Reduce each of this phases' children.
|
||||
let child = nodes.find((node) => node.id == childId);
|
||||
const child = nodes.find((node) => node.id == childId);
|
||||
|
||||
// Make sure that we reduce only valid children nodes.
|
||||
if (child == undefined || child.type == undefined || !reducableChildren.includes(child.type)) return ''
|
||||
@@ -109,8 +88,8 @@ export function PhaseReduce(node: Node, nodes: Node[]) {
|
||||
|
||||
export function PhaseConnects(thisNode: Node, otherNode: Node, isThisSource: boolean) {
|
||||
console.log("Connect functionality called.")
|
||||
let node = thisNode as PhaseNode
|
||||
let data = node.data as PhaseNodeData
|
||||
const node = thisNode as PhaseNode
|
||||
const data = node.data as PhaseNodeData
|
||||
if (isThisSource)
|
||||
data.children.push(otherNode.id)
|
||||
}
|
||||
Reference in New Issue
Block a user