forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPipelineIO.tsx
More file actions
177 lines (162 loc) · 5.1 KB
/
PipelineIO.tsx
File metadata and controls
177 lines (162 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { type ReactNode } from "react";
import type { TaskSpecOutput } from "@/api/types.gen";
import { Attribute } from "@/components/shared/ContextPanel/Blocks/Attribute";
import { ContentBlock } from "@/components/shared/ContextPanel/Blocks/ContentBlock";
import { typeSpecToString } from "@/components/shared/ReactFlow/FlowCanvas/TaskNode/ArgumentsEditor/utils";
import { Button } from "@/components/ui/button";
import { Icon } from "@/components/ui/icon";
import { BlockStack, InlineStack } from "@/components/ui/layout";
import { Paragraph } from "@/components/ui/typography";
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
import { useContextPanel } from "@/providers/ContextPanelProvider";
import { type InputSpec, type OutputSpec } from "@/utils/componentSpec";
import { getArgumentValue } from "@/utils/nodes/taskArguments";
import { InputValueEditor } from "../../Editor/IOEditor/InputValueEditor";
import { OutputNameEditor } from "../../Editor/IOEditor/OutputNameEditor";
import { getOutputConnectedDetails } from "../../Editor/utils/getOutputConnectedDetails";
const PipelineIO = ({
taskArguments,
}: {
taskArguments?: TaskSpecOutput["arguments"] | null;
}) => {
const { setContent } = useContextPanel();
const { componentSpec, graphSpec } = useComponentSpec();
const readOnly = !!taskArguments;
const handleInputEdit = (input: InputSpec) => {
setContent(<InputValueEditor key={input.name} input={input} />);
};
const handleOutputEdit = (output: OutputSpec) => {
const outputConnectedDetails = getOutputConnectedDetails(
graphSpec,
output.name,
);
setContent(
<OutputNameEditor
connectedDetails={outputConnectedDetails}
key={output.name}
output={output}
/>,
);
};
const inputActions: IORowAction[] = [
{
label: "Edit",
icon: <Icon name="Pencil" size="sm" />,
hidden: readOnly,
onClick: handleInputEdit,
},
];
const outputActions: IORowAction[] = [
{
label: "Edit",
icon: <Icon name="Pencil" size="sm" />,
hidden: readOnly,
onClick: handleOutputEdit,
},
];
return (
<BlockStack gap="4">
<ContentBlock title={taskArguments ? "Arguments" : "Inputs"}>
{componentSpec.inputs && componentSpec.inputs.length > 0 ? (
<BlockStack>
{componentSpec.inputs.map((input) => (
<IORow
key={input.name}
value={
getArgumentValue(taskArguments, input.name) ||
input.value ||
input.default ||
"—"
}
type={typeSpecToString(input?.type)}
spec={input}
actions={inputActions}
/>
))}
</BlockStack>
) : (
<Paragraph tone="subdued" size="xs">
No inputs
</Paragraph>
)}
</ContentBlock>
<ContentBlock title="Outputs">
{componentSpec.outputs && componentSpec.outputs.length > 0 ? (
<BlockStack>
{componentSpec.outputs.map((output) => {
const connectedOutput = getOutputConnectedDetails(
graphSpec,
output.name,
);
return (
<IORow
key={output.name}
value={connectedOutput.outputName ?? "No value"}
type={typeSpecToString(connectedOutput.outputType)}
spec={output}
actions={outputActions}
/>
);
})}
</BlockStack>
) : (
<Paragraph tone="subdued" size="xs">
No outputs
</Paragraph>
)}
</ContentBlock>
</BlockStack>
);
};
export default PipelineIO;
type IORowAction = {
label: string;
icon?: ReactNode;
hidden?: boolean;
onClick: (spec: InputSpec | OutputSpec) => void;
};
interface IORowProps {
spec: InputSpec | OutputSpec;
value: string;
type: string;
actions?: IORowAction[];
}
function IORow({ spec, value, type, actions }: IORowProps) {
return (
<InlineStack
gap="1"
align="space-between"
blockAlign="center"
className="even:bg-white odd:bg-secondary px-2 py-0 rounded-xs w-full"
wrap="nowrap"
>
<div className="flex-1 min-w-0">
<Attribute label={spec.name} value={value} copyable />
</div>
<InlineStack
className="min-w-16 shrink-0"
align="end"
blockAlign="center"
>
<Paragraph size="xs" tone="subdued">
({type})
</Paragraph>
{actions?.map(
(action) =>
!action.hidden && (
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => action.onClick(spec)}
className="text-xs text-muted-foreground hover:text-foreground hover:bg-transparent"
key={action.label}
>
{action.icon ?? action.label}
</Button>
),
)}
</InlineStack>
</InlineStack>
);
}