forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPipelineDetails.tsx
More file actions
281 lines (260 loc) · 8.85 KB
/
PipelineDetails.tsx
File metadata and controls
281 lines (260 loc) · 8.85 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import { Frown } from "lucide-react";
import { useEffect, useState } from "react";
import { PipelineValidationList } from "@/components/Editor/components/PipelineValidationList/PipelineValidationList";
import { useValidationIssueNavigation } from "@/components/Editor/hooks/useValidationIssueNavigation";
import { ArtifactsList } from "@/components/shared/ArtifactsList/ArtifactsList";
import { CopyText } from "@/components/shared/CopyText/CopyText";
import { Button } from "@/components/ui/button";
import { Icon } from "@/components/ui/icon";
import { BlockStack, InlineStack } from "@/components/ui/layout";
import { Text } from "@/components/ui/typography";
import useToastNotification from "@/hooks/useToastNotification";
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
import { useContextPanel } from "@/providers/ContextPanelProvider";
import {
type InputSpec,
type OutputSpec,
type TypeSpecType,
} from "@/utils/componentSpec";
import { getComponentFileFromList } from "@/utils/componentStore";
import { USER_PIPELINES_LIST_NAME } from "@/utils/constants";
import { TaskImplementation } from "../shared/TaskDetails";
import { InputValueEditor } from "./IOEditor/InputValueEditor";
import { OutputNameEditor } from "./IOEditor/OutputNameEditor";
import RenamePipeline from "./RenamePipeline";
import { getOutputConnectedDetails } from "./utils/getOutputConnectedDetails";
const PipelineDetails = () => {
const { setContent } = useContextPanel();
const {
componentSpec,
graphSpec,
digest,
isComponentTreeValid,
globalValidationIssues,
} = useComponentSpec();
const notify = useToastNotification();
const { handleIssueClick, groupedIssues } = useValidationIssueNavigation(
globalValidationIssues,
);
// Utility function to convert TypeSpecType to string
const typeSpecToString = (typeSpec?: TypeSpecType): string => {
if (typeSpec === undefined) {
return "Any";
}
if (typeof typeSpec === "string") {
return typeSpec;
}
return JSON.stringify(typeSpec);
};
// State for file metadata
const [fileMeta, setFileMeta] = useState<{
creationTime?: Date;
modificationTime?: Date;
createdBy?: string;
}>({});
// Fetch file metadata on mount or when componentSpec.name changes
useEffect(() => {
const fetchMeta = async () => {
if (!componentSpec?.name) return;
const file = await getComponentFileFromList(
USER_PIPELINES_LIST_NAME,
componentSpec.name,
);
if (file) {
setFileMeta({
creationTime: file.creationTime,
modificationTime: file.modificationTime,
createdBy: file.componentRef.spec.metadata?.annotations?.author as
| string
| undefined,
});
}
};
fetchMeta();
}, [componentSpec?.name]);
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 handleDigestCopy = () => {
navigator.clipboard.writeText(digest);
notify("Digest copied to clipboard", "success");
};
if (!componentSpec) {
return (
<div className="flex flex-col gap-8 items-center justify-center h-full">
<Frown className="w-12 h-12 text-secondary-foreground" />
<div className="text-secondary-foreground">
Error loading pipeline details.
</div>
</div>
);
}
const annotations = componentSpec.metadata?.annotations || {};
return (
<BlockStack
gap="6"
className="p-2 h-full"
data-context-panel="pipeline-details"
>
<CopyText className="text-lg font-semibold">
{componentSpec.name ?? "Unnamed Pipeline"}
</CopyText>
<InlineStack gap="2">
<RenamePipeline />
<TaskImplementation
displayName={componentSpec.name ?? "Pipeline"}
componentSpec={componentSpec}
showInlineContent={false}
/>
</InlineStack>
{(fileMeta.createdBy ||
fileMeta.creationTime ||
fileMeta.modificationTime) && (
<BlockStack>
<Text as="h3" size="md" weight="semibold" className="mb-1">
Pipeline Info
</Text>
<dl className="flex flex-col gap-1 text-xs text-secondary-foreground">
{fileMeta.createdBy && (
<InlineStack as="div" gap="1" blockAlign="center">
<Text as="dt" weight="semibold">
Created by:
</Text>
<dd>{fileMeta.createdBy}</dd>
</InlineStack>
)}
{fileMeta.creationTime && (
<InlineStack as="div" gap="1" blockAlign="center">
<Text as="dt" weight="semibold">
Created at:
</Text>
<dd>{new Date(fileMeta.creationTime).toLocaleString()}</dd>
</InlineStack>
)}
{fileMeta.modificationTime && (
<InlineStack as="div" gap="1" blockAlign="center">
<Text as="dt" weight="semibold">
Last updated:
</Text>
<dd>{new Date(fileMeta.modificationTime).toLocaleString()}</dd>
</InlineStack>
)}
</dl>
</BlockStack>
)}
{componentSpec.description && (
<BlockStack>
<Text as="h3" size="md" weight="semibold" className="mb-1">
Description
</Text>
<Text as="p" size="sm" className="whitespace-pre-line">
{componentSpec.description}
</Text>
</BlockStack>
)}
{/* Component Digest */}
{digest && (
<BlockStack>
<Text as="h3" size="md" weight="semibold" className="mb-1">
Digest
</Text>
<Button
className="bg-gray-100 border border-gray-300 rounded p-2 h-fit text-xs w-full text-left hover:bg-gray-200 active:bg-gray-300 transition cursor-pointer"
onClick={handleDigestCopy}
variant="ghost"
>
<Text as="span" font="mono" className="break-all w-full text-wrap">
{digest}
</Text>
</Button>
</BlockStack>
)}
{/* Annotations */}
{Object.keys(annotations).length > 0 && (
<BlockStack>
<Text as="h3" size="md" weight="semibold" className="mb-1">
Annotations
</Text>
<ul className="text-xs text-secondary-foreground">
{Object.entries(annotations).map(([key, value]) => (
<li key={key}>
<Text as="span" weight="semibold">
{key}:
</Text>{" "}
<Text as="span" className="break-all">
{String(value)}
</Text>
</li>
))}
</ul>
</BlockStack>
)}
<ArtifactsList
inputs={(componentSpec.inputs ?? []).map((input) => ({
name: input.name,
type: typeSpecToString(input?.type),
value: input.value || input.default,
actions: (
<Button
type="button"
variant="ghost"
size="min"
onClick={() => handleInputEdit(input)}
className="text-muted-foreground hover:text-foreground h-4 w-4"
>
<Icon name="Pencil" className="size-2.5" />
</Button>
),
}))}
outputs={(componentSpec.outputs ?? []).map((output) => {
const connectedDetails = getOutputConnectedDetails(
graphSpec,
output.name,
);
return {
name: output.name,
type: typeSpecToString(connectedDetails.outputType),
value: connectedDetails.outputName,
actions: (
<Button
type="button"
variant="ghost"
size="min"
onClick={() => handleOutputEdit(output)}
className="text-muted-foreground hover:text-foreground h-4 w-4"
>
<Icon name="Pencil" className="size-2.5" />
</Button>
),
};
})}
/>
{/* Validations */}
<BlockStack>
<Text as="h3" size="md" weight="semibold" className="mb-1">
Validations
</Text>
<PipelineValidationList
isComponentTreeValid={isComponentTreeValid}
groupedIssues={groupedIssues}
totalIssueCount={globalValidationIssues.length}
onIssueSelect={handleIssueClick}
/>
</BlockStack>
</BlockStack>
);
};
export default PipelineDetails;