From bd7620a182cfc8cb61f55d62c06c85e6f028a0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Otgaar?= Date: Tue, 18 Nov 2025 18:49:11 +0100 Subject: [PATCH] chore: fix eslints and spelling --- .../visualProgrammingUI/NodeRegistry.ts | 4 +- .../visualProgrammingUI/nodes/PhaseNode.tsx | 51 +++---------------- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/src/pages/VisProgPage/visualProgrammingUI/NodeRegistry.ts b/src/pages/VisProgPage/visualProgrammingUI/NodeRegistry.ts index 0ef5455..14a993f 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/NodeRegistry.ts +++ b/src/pages/VisProgPage/visualProgrammingUI/NodeRegistry.ts @@ -1,6 +1,6 @@ import StartNode, { StartConnects, StartReduce } from "./nodes/StartNode"; import EndNode, { EndConnects, EndReduce } from "./nodes/EndNode"; -import PhaseNode, { PhaseConnects, PhaseReduce, PhaseReduce2 } from "./nodes/PhaseNode"; +import PhaseNode, { PhaseConnects, PhaseReduce } from "./nodes/PhaseNode"; import NormNode, { NormConnects, NormReduce } from "./nodes/NormNode"; import { EndNodeDefaults } from "./nodes/EndNode.default"; import { StartNodeDefaults } from "./nodes/StartNode.default"; @@ -42,7 +42,7 @@ export const NodeDefaults = { export const NodeReduces = { start: StartReduce, end: EndReduce, - phase: PhaseReduce2, + phase: PhaseReduce, norm: NormReduce, goal: GoalReduce, trigger: TriggerReduce, diff --git a/src/pages/VisProgPage/visualProgrammingUI/nodes/PhaseNode.tsx b/src/pages/VisProgPage/visualProgrammingUI/nodes/PhaseNode.tsx index 864278d..91d5486 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/nodes/PhaseNode.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/nodes/PhaseNode.tsx @@ -6,7 +6,7 @@ import { } from '@xyflow/react'; import { Toolbar } from '../components/NodeComponents'; import styles from '../../VisProg.module.css'; -import { NodeDefaults, NodeReduces, NodesInPhase, NodeTypes } from '../NodeRegistry'; +import { NodeReduces, NodesInPhase, NodeTypes } from '../NodeRegistry'; import useFlowStore from '../VisProgStores'; import { TextField } from '../../../../components/TextField'; @@ -62,6 +62,7 @@ export default function PhaseNode(props: NodeProps) { ); }; + /** * Reduces each phase, including its children down into its relevant data. * @param props: The Node Properties of this node. @@ -69,66 +70,28 @@ export default function PhaseNode(props: NodeProps) { 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]) => ( - type - )); - - let childrenData: unknown = "" - if (data.children != undefined) { - childrenData = data.children.map((childId) => { - // Reduce each of this phases' children. - 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 '' - const reducer = NodeReduces[child.type as keyof typeof NodeReduces] - - if (!reducer) { - console.warn(`No reducer found for node type ${child.type}`); - return null; - } - - return reducer(child, nodes); - })} - return { - id: thisnode.id, - name: data.label as string, - children: childrenData, - } -} - - -/** - * Reduces each phase, including its children down into its relevant data. - * @param props: The Node Properties of this node. - */ -export function PhaseReduce2(node: Node, nodes: Node[]) { - const thisnode = node as PhaseNode; - const data = thisnode.data as PhaseNodeData; // node typings that are not in phase - let nodesNotInPhase: string[] = Object.entries(NodesInPhase) + const nodesNotInPhase: string[] = Object.entries(NodesInPhase) .filter(([, f]) => !f()) .map(([t]) => t); // node typings that then are in phase - let nodesInPhase: string[] = Object.entries(NodeTypes) + const nodesInPhase: string[] = Object.entries(NodeTypes) .filter(([t]) => !nodesNotInPhase.includes(t)) .map(([t]) => t); // children nodes - let childrenNodes = nodes.filter((node) => data.children.includes(node.id)); + const childrenNodes = nodes.filter((node) => data.children.includes(node.id)); // Build the result object - let result: Record = { + const result: Record = { id: thisnode.id, label: data.label, }; nodesInPhase.forEach((type) => { - let typedChildren = childrenNodes.filter((child) => child.type == type); + const typedChildren = childrenNodes.filter((child) => child.type == type); const reducer = NodeReduces[type as keyof typeof NodeReduces]; if (!reducer) { console.warn(`No reducer found for node type ${type}`);