Skip to content

Commit c59d689

Browse files
committed
chore: Node Definition Cleanup
1 parent f18fb64 commit c59d689

16 files changed

Lines changed: 137 additions & 91 deletions

File tree

src/components/PipelineRun/RunToolbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "@/utils/executionStatus";
1313

1414
import { ViewYamlButton } from "../shared/Buttons/ViewYamlButton";
15-
import { buildTakSpecShape } from "../shared/PipelineRunNameTemplate/types";
15+
import { buildTaskSpecShape } from "../shared/PipelineRunNameTemplate/types";
1616
import { CancelPipelineRunButton } from "./components/CancelPipelineRunButton";
1717
import { ClonePipelineButton } from "./components/ClonePipelineButton";
1818
import { InspectPipelineButton } from "./components/InspectPipelineButton";
@@ -55,7 +55,7 @@ export const RunToolbar = () => {
5555

5656
const pipelineName =
5757
extractCanonicalName(
58-
buildTakSpecShape(details?.task_spec, componentSpec),
58+
buildTaskSpecShape(details?.task_spec, componentSpec),
5959
) ?? componentSpec.name;
6060

6161
return (

src/components/PipelineRun/components/ClonePipelineButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useNavigate } from "@tanstack/react-router";
33
import { useCallback } from "react";
44

55
import TooltipButton from "@/components/shared/Buttons/TooltipButton";
6-
import { buildTakSpecShape } from "@/components/shared/PipelineRunNameTemplate/types";
6+
import { buildTaskSpecShape } from "@/components/shared/PipelineRunNameTemplate/types";
77
import { Icon } from "@/components/ui/icon";
88
import useToastNotification from "@/hooks/useToastNotification";
99
import { useExecutionDataOptional } from "@/providers/ExecutionDataProvider";
@@ -35,7 +35,7 @@ export const ClonePipelineButton = ({
3535
taskArguments?: Record<string, string>;
3636
}) => {
3737
const canonicalName = extractCanonicalName(
38-
buildTakSpecShape(runDetails?.rootDetails?.task_spec, componentSpec),
38+
buildTaskSpecShape(runDetails?.rootDetails?.task_spec, componentSpec),
3939
);
4040

4141
const name = getInitialName(componentSpec, canonicalName);

src/components/PipelineRun/components/RerunPipelineButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { isAuthorizationRequired } from "@/components/shared/Authentication/help
66
import { useAuthLocalStorage } from "@/components/shared/Authentication/useAuthLocalStorage";
77
import { useAwaitAuthorization } from "@/components/shared/Authentication/useAwaitAuthorization";
88
import TooltipButton from "@/components/shared/Buttons/TooltipButton";
9-
import { buildTakSpecShape } from "@/components/shared/PipelineRunNameTemplate/types";
9+
import { buildTaskSpecShape } from "@/components/shared/PipelineRunNameTemplate/types";
1010
import { useFlagValue } from "@/components/shared/Settings/useFlags";
1111
import { Icon } from "@/components/ui/icon";
1212
import useToastNotification from "@/hooks/useToastNotification";
@@ -68,7 +68,7 @@ export const RerunPipelineButton = ({
6868
return new Promise<PipelineRun>((resolve, reject) => {
6969
submitPipelineRun(componentSpec, backendUrl, {
7070
canonicalName: extractCanonicalName(
71-
buildTakSpecShape(
71+
buildTaskSpecShape(
7272
executionData?.rootDetails?.task_spec,
7373
componentSpec,
7474
),

src/components/shared/PipelineRunNameTemplate/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface TaskSpecShape {
1010
annotations?: Record<string, unknown> | null;
1111
}
1212

13-
export function buildTakSpecShape(
13+
export function buildTaskSpecShape(
1414
taskSpecOutput: TaskSpecOutput | undefined,
1515
componentSpec: ComponentSpec,
1616
): TaskSpecShape | undefined {

src/components/shared/ReactFlow/FlowCanvas/FlowCanvas.tsx

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
useStoreApi,
1818
type XYPosition,
1919
} from "@xyflow/react";
20-
import type { ComponentType, DragEvent } from "react";
20+
import type { DragEvent } from "react";
2121
import { useEffect, useRef, useState } from "react";
2222

2323
import { ConfirmationDialog } from "@/components/shared/Dialogs";
@@ -55,47 +55,38 @@ import { getBulkUpdateConfirmationDetails } from "./ConfirmationDialogs/BulkUpda
5555
import { getDeleteConfirmationDetails } from "./ConfirmationDialogs/DeleteConfirmation";
5656
import { getReplaceConfirmationDetails } from "./ConfirmationDialogs/ReplaceConfirmation";
5757
import { ConnectionLine } from "./Edges/ConnectionLine";
58-
import SmoothEdge from "./Edges/SmoothEdge";
59-
import GhostNode from "./GhostNode/GhostNode";
6058
import type { GhostNodeData } from "./GhostNode/types";
6159
import {
6260
computeDropPositionFromRefs,
6361
createGhostEdge,
6462
} from "./GhostNode/utils";
65-
import IONode from "./IONode/IONode";
6663
import SelectionToolbar from "./SelectionToolbar";
6764
import { handleGroupNodes } from "./Subgraphs/create/handleGroupNodes";
6865
import { NewSubgraphDialog } from "./Subgraphs/create/NewSubgraphDialog";
6966
import { canGroupNodes } from "./Subgraphs/create/utils";
7067
import { SubgraphBreadcrumbs } from "./Subgraphs/view/SubgraphBreadcrumbs";
71-
import TaskNode from "./TaskNode/TaskNode";
72-
import type { NodesAndEdges } from "./types";
68+
import {
69+
edgeTypes,
70+
isTaskNodeType,
71+
type NodesAndEdges,
72+
nodeTypes,
73+
} from "./types";
7374
import addTask from "./utils/addTask";
7475
import { createConnectedIONode } from "./utils/createConnectedIONode";
7576
import { duplicateNodes } from "./utils/duplicateNodes";
7677
import { isPositionInNode } from "./utils/geometry";
78+
import { getNodeFromEvent } from "./utils/getNodeFromEvent";
7779
import { getPositionFromEvent } from "./utils/getPositionFromEvent";
78-
import { getTaskFromEvent } from "./utils/getTaskFromEvent";
7980
import { handleConnection } from "./utils/handleConnection";
8081
import { removeEdge } from "./utils/removeEdge";
8182
import { removeNode } from "./utils/removeNode";
8283
import { replaceTaskNode } from "./utils/replaceTaskNode";
8384
import { updateNodePositions } from "./utils/updateNodePosition";
8485

85-
const nodeTypes: Record<string, ComponentType<any>> = {
86-
task: TaskNode,
87-
input: IONode,
88-
output: IONode,
89-
ghost: GhostNode,
90-
};
91-
9286
const SELECTABLE_NODES = new Set(["task", "input", "output"]);
9387
const UPGRADEABLE_NODES = new Set(["task"]);
9488
const REPLACEABLE_NODES = new Set(["task"]);
95-
96-
const edgeTypes: Record<string, ComponentType<any>> = {
97-
customEdge: SmoothEdge,
98-
};
89+
const FAST_PLACE_NODE_TYPES = new Set<Node["type"]>(["task"]);
9990

10091
const useScheduleExecutionOnceWhenConditionMet = (
10192
condition: boolean,
@@ -110,8 +101,6 @@ const useScheduleExecutionOnceWhenConditionMet = (
110101
}, [condition, callback]);
111102
};
112103

113-
const FAST_PLACE_NODE_TYPES = new Set<Node["type"]>(["task"]);
114-
115104
const FlowCanvas = ({
116105
readOnly,
117106
nodesConnectable,
@@ -362,7 +351,11 @@ const FlowCanvas = ({
362351
currentSubgraphPath,
363352
notify,
364353
);
365-
const newNodes = createNodesFromComponentSpec(subgraphSpec, nodeData);
354+
const newNodes = createNodesFromComponentSpec(
355+
subgraphSpec,
356+
nodeData,
357+
readOnly,
358+
);
366359

367360
const updatedNewNodes = newNodes.map((node) => ({
368361
...node,
@@ -561,14 +554,19 @@ const FlowCanvas = ({
561554
return;
562555
}
563556

564-
const { taskSpec: droppedTask, taskType } = getTaskFromEvent(event);
557+
const { spec: droppedTask, nodeType } = getNodeFromEvent(event);
558+
559+
if (!nodeType) {
560+
console.error("Dropped node type not identified.");
561+
return;
562+
}
565563

566-
if (!taskType) {
567-
console.error("Dropped task type not identified.");
564+
if (!isTaskNodeType(nodeType)) {
565+
console.error("Dropped node type is not supported:", nodeType);
568566
return;
569567
}
570568

571-
if (!droppedTask && taskType === "task") {
569+
if (!droppedTask && nodeType === "task") {
572570
console.error("Unable to find dropped task.");
573571
return;
574572
}
@@ -626,7 +624,7 @@ const FlowCanvas = ({
626624
const position = getPositionFromEvent(event, reactFlowInstance);
627625

628626
const { spec: newSubgraphSpec } = addTask(
629-
taskType,
627+
nodeType,
630628
droppedTask,
631629
position,
632630
currentSubgraphSpec,

src/components/shared/ReactFlow/FlowCanvas/TaskNode/AnnotationsEditor/AnnotationsEditor.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,14 @@ import { Button } from "@/components/ui/button";
44
import { BlockStack, InlineStack } from "@/components/ui/layout";
55
import { Heading, Paragraph } from "@/components/ui/typography";
66
import type { AnnotationConfig, Annotations } from "@/types/annotations";
7-
import {
8-
DISPLAY_NAME_MAX_LENGTH,
9-
EDITOR_POSITION_ANNOTATION,
10-
TASK_DISPLAY_NAME_ANNOTATION,
11-
} from "@/utils/annotations";
7+
import { DEFAULT_COMMON_ANNOTATIONS } from "@/utils/annotations";
128

139
import { AnnotationsInput } from "./AnnotationsInput";
1410
import {
1511
NewAnnotationRow,
1612
type NewAnnotationRowData,
1713
} from "./NewAnnotationRow";
1814

19-
const DEFAULT_COMMON_ANNOTATIONS: AnnotationConfig[] = [
20-
{
21-
annotation: EDITOR_POSITION_ANNOTATION,
22-
label: "Node position",
23-
type: "json",
24-
},
25-
{
26-
annotation: TASK_DISPLAY_NAME_ANNOTATION,
27-
label: "Display Name",
28-
type: "string",
29-
max: DISPLAY_NAME_MAX_LENGTH,
30-
},
31-
];
32-
3315
interface AnnotationsEditorProps {
3416
annotations: Annotations;
3517
pinnedAnnotations?: AnnotationConfig[];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
import type { Edge, Node } from "@xyflow/react";
2+
import type { ComponentType } from "react";
3+
4+
import type { TaskType } from "@/types/taskNode";
5+
6+
import SmoothEdge from "./Edges/SmoothEdge";
7+
import GhostNode from "./GhostNode/GhostNode";
8+
import IONode from "./IONode/IONode";
9+
import TaskNode from "./TaskNode/TaskNode";
210

311
export type NodesAndEdges = {
412
nodes: Node[];
513
edges: Edge[];
614
};
15+
16+
export const nodeTypes: Record<string, ComponentType<any>> = {
17+
task: TaskNode,
18+
input: IONode,
19+
output: IONode,
20+
ghost: GhostNode,
21+
};
22+
23+
export type NodeType = keyof typeof nodeTypes;
24+
25+
export const edgeTypes: Record<string, ComponentType<any>> = {
26+
customEdge: SmoothEdge,
27+
};
28+
29+
export function isTaskNodeType(type: string): type is TaskType {
30+
return type === "task" || type === "input" || type === "output";
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { DragEvent } from "react";
2+
3+
import type { TaskSpec } from "@/utils/componentSpec";
4+
5+
import type { NodeType } from "../types";
6+
7+
export const getNodeFromEvent = (event: DragEvent) => {
8+
const droppedData = event.dataTransfer.getData("application/reactflow");
9+
10+
if (droppedData === "") {
11+
return { spec: null, nodeType: null };
12+
}
13+
14+
const droppedDataObject = JSON.parse(droppedData);
15+
const nodeType = Object.keys(droppedDataObject)[0] as NodeType;
16+
const spec = droppedDataObject[nodeType] as TaskSpec | null;
17+
18+
return { spec, nodeType };
19+
};

src/components/shared/ReactFlow/FlowCanvas/utils/getTaskFromEvent.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/components/shared/ReactFlow/FlowCanvas/utils/removeNode.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { type Node } from "@xyflow/react";
33
import {
44
type ComponentSpec,
55
isGraphImplementation,
6+
isGraphInputArgument,
7+
isTaskOutputArgument,
68
} from "@/utils/componentSpec";
79
import {
810
nodeIdToInputName,
@@ -42,7 +44,7 @@ export const removeGraphInput = (
4244
for (const [inputName, argument] of Object.entries(
4345
taskSpec.arguments ?? {},
4446
)) {
45-
if (typeof argument !== "string" && "graphInput" in argument) {
47+
if (isGraphInputArgument(argument)) {
4648
if (argument.graphInput.inputName === inputNameToRemove) {
4749
const newGraphSpec = setTaskArgument(
4850
componentSpec.implementation.graph,
@@ -97,8 +99,7 @@ export const removeTask = (
9799
for (const [inputName, argument] of Object.entries(taskSpec.arguments)) {
98100
// Check if this argument references the task we're removing
99101
const isReferencingRemovedTask =
100-
typeof argument !== "string" &&
101-
"taskOutput" in argument &&
102+
isTaskOutputArgument(argument) &&
102103
argument.taskOutput.taskId === taskIdToRemove;
103104

104105
if (isReferencingRemovedTask) {

0 commit comments

Comments
 (0)