Skip to content

Commit 69a9e3f

Browse files
committed
temp: feat zIndex Management for Task Nodes
1 parent c6d3736 commit 69a9e3f

8 files changed

Lines changed: 96 additions & 7 deletions

File tree

react-compiler.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const REACT_COMPILER_ENABLED_DIRS = [
4848
"src/components/shared/TaskDetails/DisplayNameEditor.tsx",
4949
"src/components/shared/TaskDetails/Actions/UnpackSubgraphButton.tsx",
5050
"src/components/shared/ReactFlow/FlowControls/StackingControls.tsx",
51+
"src/components/shared/ReactFlow/FlowCanvas/TaskNode/TaskOverview/ZIndexEditor.tsx",
5152

5253
// 11-20 useCallback/useMemo
5354
// "src/components/ui", // 12

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import IOSection from "./IOSection/IOSection";
2626
import Logs, { OpenLogsInNewWindowLink } from "./logs";
2727
import OutputsList from "./OutputsList";
2828
import RenameTask from "./RenameTask";
29+
import { ZIndexEditor } from "./ZIndexEditor";
2930

3031
interface TaskOverviewProps {
3132
taskNode: TaskNodeContextType;
@@ -165,6 +166,8 @@ const TaskOverview = ({ taskNode }: TaskOverviewProps) => {
165166
)}
166167
</Tabs>
167168
</div>
169+
170+
<ZIndexEditor taskNode={taskNode} />
168171
</BlockStack>
169172
);
170173
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ContentBlock } from "@/components/shared/ContextPanel/Blocks/ContentBlock";
2+
import type { TaskNodeContextType } from "@/providers/TaskNodeProvider";
3+
import { ZINDEX_ANNOTATION } from "@/utils/annotations";
4+
5+
import { StackingControls } from "../../../FlowControls/StackingControls";
6+
7+
interface ZIndexEditorProps {
8+
taskNode: TaskNodeContextType;
9+
}
10+
11+
export const ZIndexEditor = ({ taskNode }: ZIndexEditorProps) => {
12+
const handleStackingControlChange = (newZIndex: number) => {
13+
const updatedAnnotations = {
14+
...taskNode.taskSpec?.annotations,
15+
[ZINDEX_ANNOTATION]: `${newZIndex}`,
16+
};
17+
18+
taskNode.callbacks.setAnnotations(updatedAnnotations);
19+
};
20+
21+
return (
22+
<ContentBlock className="border rounded-lg p-2 bg-background w-fit mx-auto">
23+
<StackingControls
24+
nodeId={taskNode.nodeId}
25+
onChange={handleStackingControlChange}
26+
/>
27+
</ContentBlock>
28+
);
29+
};

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { XYPosition } from "@xyflow/react";
22

33
import type { TaskType } from "@/types/taskNode";
4-
import { EDITOR_POSITION_ANNOTATION } from "@/utils/annotations";
4+
import {
5+
EDITOR_POSITION_ANNOTATION,
6+
ZINDEX_ANNOTATION,
7+
} from "@/utils/annotations";
58
import {
69
type ComponentSpec,
710
type GraphSpec,
@@ -17,6 +20,8 @@ import {
1720
getUniqueTaskName,
1821
} from "@/utils/unique";
1922

23+
import { getNodeTypeZIndexDefault } from "./zIndex";
24+
2025
interface AddTaskResult {
2126
spec: ComponentSpec;
2227
taskId: string | undefined;
@@ -75,8 +80,9 @@ const addTask = (
7580
const graphSpec = newComponentSpec.implementation.graph;
7681

7782
const nodePosition = { x: position.x, y: position.y };
78-
const positionAnnotations = {
83+
const annotations = {
7984
[EDITOR_POSITION_ANNOTATION]: JSON.stringify(nodePosition),
85+
[ZINDEX_ANNOTATION]: getNodeTypeZIndexDefault(taskType),
8086
};
8187

8288
if (taskType === "task") {
@@ -103,7 +109,7 @@ const addTask = (
103109

104110
const mergedAnnotations = {
105111
...taskSpec.annotations,
106-
...positionAnnotations,
112+
...annotations,
107113
};
108114

109115
const updatedTaskSpec: TaskSpec = {
@@ -133,7 +139,7 @@ const addTask = (
133139
const inputSpec: InputSpec = {
134140
...options,
135141
name: inputId,
136-
annotations: positionAnnotations,
142+
annotations,
137143
};
138144

139145
const inputs = (newComponentSpec.inputs ?? []).concat([inputSpec]);
@@ -146,7 +152,7 @@ const addTask = (
146152
const outputSpec: OutputSpec = {
147153
...options,
148154
name: outputId,
149-
annotations: positionAnnotations,
155+
annotations,
150156
};
151157

152158
const outputs = (newComponentSpec.outputs ?? []).concat([outputSpec]);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export const Z_INDEX_RANGES: Record<NodeType, zIndexDefinition> = {
3131
},
3232
};
3333

34+
export const getNodeTypeZIndexDefault = (nodeType: NodeType): number => {
35+
return Z_INDEX_RANGES[nodeType].default;
36+
};
37+
3438
const getNodeZIndexDefault = (node: Node): number => {
3539
if (!isDefinedNode(node)) {
3640
return 0;

src/config/launcherTaskAnnotationSchema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
"title": "Display Name",
1818
"x-type": "string",
1919
"exclusiveMaximum": 100
20+
},
21+
"zIndex": {
22+
"type": "integer",
23+
"title": "Z-Index",
24+
"x-type": "string",
25+
"exclusiveMinimum": -100,
26+
"exclusiveMaximum": 100
2027
}
2128
}
2229
}

src/utils/annotations.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { XYPosition } from "@xyflow/react";
22

3+
import { getNodeTypeZIndexDefault } from "@/components/shared/ReactFlow/FlowCanvas/utils/zIndex";
34
import type { AnnotationConfig } from "@/types/annotations";
45

56
import type { ComponentSpec } from "./componentSpec";
@@ -11,6 +12,7 @@ export const PIPELINE_RUN_NOTES_ANNOTATION = "notes";
1112
export const PIPELINE_CANONICAL_NAME_ANNOTATION = "canonical-pipeline-name";
1213
export const RUN_NAME_TEMPLATE_ANNOTATION = "run-name-template";
1314
export const EDITOR_POSITION_ANNOTATION = "editor.position";
15+
export const ZINDEX_ANNOTATION = "zIndex";
1416

1517
export const DEFAULT_COMMON_ANNOTATIONS: AnnotationConfig[] = [
1618
{
@@ -185,3 +187,32 @@ export const extractPositionFromAnnotations = (
185187
return defaultPosition;
186188
}
187189
};
190+
191+
/**
192+
* Gets the z-index from annotations.
193+
* @param annotations - The annotations object
194+
* @returns z-index number
195+
*/
196+
export const extractZIndexFromAnnotations = (
197+
annotations: Annotations,
198+
nodeType: string,
199+
): number => {
200+
const defaultZIndex = getNodeTypeZIndexDefault(nodeType);
201+
202+
if (!annotations) return defaultZIndex;
203+
204+
const zIndex = annotations[ZINDEX_ANNOTATION];
205+
206+
if (typeof zIndex === "number") {
207+
return Math.round(zIndex);
208+
}
209+
210+
if (typeof zIndex === "string") {
211+
const parsedZIndex = parseInt(zIndex, 10);
212+
if (!isNaN(parsedZIndex)) {
213+
return Math.round(parsedZIndex);
214+
}
215+
}
216+
217+
return defaultZIndex;
218+
};

src/utils/nodes/createTaskNode.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { type Node } from "@xyflow/react";
22

33
import type { TaskNodeData } from "@/types/taskNode";
44

5-
import { extractPositionFromAnnotations } from "../annotations";
5+
import {
6+
extractPositionFromAnnotations,
7+
extractZIndexFromAnnotations,
8+
} from "../annotations";
69
import type { TaskSpec } from "../componentSpec";
710
import { generateDynamicNodeCallbacks } from "./generateDynamicNodeCallbacks";
811
import { taskIdToNodeId } from "./nodeIdUtils";
@@ -12,9 +15,13 @@ export const createTaskNode = (
1215
nodeData: TaskNodeData,
1316
readOnly: boolean = false,
1417
) => {
18+
const nodeType = "task";
19+
1520
const [taskId, taskSpec] = task;
1621

1722
const position = extractPositionFromAnnotations(taskSpec.annotations);
23+
const zIndex = extractZIndexFromAnnotations(taskSpec.annotations, nodeType);
24+
1825
const nodeId = taskIdToNodeId(taskId);
1926

2027
// Inject the taskId and nodeId into the callbacks
@@ -32,6 +39,7 @@ export const createTaskNode = (
3239
readOnly,
3340
},
3441
position: position,
35-
type: "task",
42+
type: nodeType,
43+
zIndex,
3644
} as Node;
3745
};

0 commit comments

Comments
 (0)