Skip to content

Commit c868b7f

Browse files
fix: artifacts with dynamic names (#706)
1 parent 33bc5d7 commit c868b7f

File tree

19 files changed

+544
-332
lines changed

19 files changed

+544
-332
lines changed

src/app/runs/[id]/_Tabs/Configuration/CodeCollapsible.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import ChevronDown from "@/assets/icons/chevron-down.svg?react";
2+
import { Codesnippet } from "@/components/CodeSnippet";
3+
import { getRunSnippet } from "@/lib/code-snippets";
4+
import { PipelineRun } from "@/types/pipeline-runs";
25
import {
36
CollapsibleContent,
47
CollapsibleHeader,
58
CollapsiblePanel,
69
CollapsibleTrigger
710
} from "@zenml-io/react-component-library";
8-
import { PipelineRun } from "@/types/pipeline-runs";
911
import { useState } from "react";
10-
import { Codesnippet } from "@/components/CodeSnippet";
1112

1213
type Props = {
1314
runId: PipelineRun["id"];
1415
};
1516

1617
export function CodeCollapsible({ runId }: Props) {
1718
const [open, setOpen] = useState(true);
18-
const runCode = `from zenml.client import Client
19-
run = Client().get_pipeline_run('${runId}')
20-
config = run.config`;
19+
const runCode = getRunSnippet(runId);
2120

2221
return (
2322
<CollapsiblePanel open={open} onOpenChange={setOpen}>

src/app/runs/[id]/_Tabs/Configuration/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export function ConfigurationTab() {
4444
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4545
data={(data.metadata?.config.settings as { [key: string]: any })?.resources || {}}
4646
/>
47+
<NestedCollapsible
48+
isInitialOpen
49+
title="Substitutions"
50+
data={data.metadata?.config.substitutions}
51+
/>
4752
<NestedCollapsible isInitialOpen title="Extra" data={data.metadata?.config.extra} />
4853
</div>
4954
);

src/app/runs/[id]/useDag.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export function useDag() {
3737
}, [pipelineDeployment.data?.metadata?.step_configurations]);
3838

3939
const realNodes = useMemo(() => {
40-
return extractExistingNodes((pipelineRun.data?.metadata?.steps as StepDict) ?? {});
40+
return extractExistingNodes(
41+
(pipelineRun.data?.metadata?.steps as StepDict) ?? {},
42+
(pipelineRun.data?.metadata?.step_substitutions as Record<string, Record<string, string>>) ||
43+
{}
44+
);
4145
}, [pipelineRun.data?.metadata?.steps]);
4246

4347
const onDagreLayout = useCallback(() => {

src/app/settings/secrets/columns.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import LockIcon from "@/assets/icons/Lock.svg?react";
22
import { CopyButton } from "@/components/CopyButton";
33
import { DisplayDate } from "@/components/DisplayDate";
44
import { InlineAvatar } from "@/components/InlineAvatar";
5+
import { getSecretSnippet } from "@/lib/code-snippets";
56
import { getUsername } from "@/lib/user";
67
import { routes } from "@/router/routes";
78
import { SecretNamespace } from "@/types/secret";
@@ -17,9 +18,7 @@ export const secretsColumns: ColumnDef<SecretNamespace>[] = [
1718
header: "Secret",
1819
accessorFn: (row) => row.name,
1920
cell: ({ getValue, row }) => {
20-
const code = `from zenml.client import Client
21-
secret = Client().get_secret("${row.original.name}")
22-
`;
21+
const code = getSecretSnippet(row.original.name);
2322

2423
return (
2524
<div className="flex items-center space-x-2">

src/app/stacks/StackList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ import { routes } from "@/router/routes";
77
import { useQuery } from "@tanstack/react-query";
88
import { Button, DataTable, Skeleton } from "@zenml-io/react-component-library";
99
import { Link } from "react-router-dom";
10-
import { getStackColumns } from "./columns";
1110
import { useStacklistQueryParams } from "./service";
1211
import { StackListQueryParams } from "../../types/stack";
12+
import { useStackColumns } from "./columns";
1313

1414
type Props = {
1515
fixedQueryParams?: StackListQueryParams;
1616
};
1717

1818
export function StackList({ fixedQueryParams = {} }: Props) {
1919
const queryParams = useStacklistQueryParams();
20+
const columns = useStackColumns();
2021
const { refetch, data } = useQuery({
2122
...stackQueries.stackList({ ...queryParams, sort_by: "desc:updated", ...fixedQueryParams }),
2223
throwOnError: true
@@ -43,7 +44,7 @@ export function StackList({ fixedQueryParams = {} }: Props) {
4344
<div className="flex flex-col items-center gap-5">
4445
<div className="w-full">
4546
{data ? (
46-
<DataTable columns={getStackColumns()} data={data.items} />
47+
<DataTable columns={columns} data={data.items} />
4748
) : (
4849
<Skeleton className="h-[500px] w-full" />
4950
)}

src/app/stacks/columns.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { Stack } from "@/types/stack";
77
import { User } from "@/types/user";
88
import { ColumnDef } from "@tanstack/react-table";
99
import { Avatar, AvatarFallback } from "@zenml-io/react-component-library";
10+
import { useMemo } from "react";
1011
import { StackActionsMenu } from "./ActionsDropdown";
1112

12-
export function getStackColumns(): ColumnDef<Stack>[] {
13-
return [
13+
export function useStackColumns(): ColumnDef<Stack>[] {
14+
const cols: ColumnDef<Stack>[] = [
1415
{
1516
id: "name",
1617
header: "Stack",
@@ -67,4 +68,6 @@ export function getStackColumns(): ColumnDef<Stack>[] {
6768
}
6869
}
6970
];
71+
72+
return useMemo(() => cols, []);
7073
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { isString } from "@/lib/type-guards";
2+
import { Codesnippet } from "../CodeSnippet";
3+
import { Props } from "./Visualization";
4+
5+
export function JSONVisualization({ content }: Props) {
6+
const json = parseJSON(content);
7+
return (
8+
<Codesnippet
9+
fullWidth
10+
highlightCode
11+
code={isString(json) ? json : JSON.stringify(json, null, 2)}
12+
/>
13+
);
14+
}
15+
16+
function parseJSON(content: string): unknown {
17+
try {
18+
const parsedJSON = JSON.parse(content);
19+
return parsedJSON;
20+
} catch (e) {
21+
return content;
22+
}
23+
}

src/components/artifacts/Visualization.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { HTMLVisualization } from "./HtmlVisualization";
1212
import { ImageVisualization } from "./ImageVisualization";
1313
import { InfoBox } from "../Infobox";
1414
import { useArtifactLoadConfirmationContext } from "@/context/VisualizationConfirmationContext";
15+
import { JSONVisualization } from "./JsonVisualization";
1516

1617
const CSVVisualization = lazy(() => import("./CsvVizualization"));
1718
const MarkdownVisualization = lazy(() => import("./MarkdownVisualization"));
@@ -126,6 +127,7 @@ export function Visualization({ artifactVersionId, artifactName }: Visualization
126127
{data.type === "html" && <HTMLVisualization content={data.value} />}
127128
{data.type === "markdown" && <MarkdownVisualization content={data.value} />}
128129
{data.type === "csv" && <CSVVisualization content={data.value} />}
130+
{data.type === "json" && <JSONVisualization content={data.value} />}
129131
</div>
130132
</div>
131133
);
@@ -165,14 +167,16 @@ function DownloadButton({
165167
image: "png",
166168
html: "html",
167169
markdown: "md",
168-
csv: "csv"
170+
csv: "csv",
171+
json: "json"
169172
} as const;
170173

171174
const typeMap = {
172175
image: "image/png",
173176
html: "text/html",
174177
markdown: "text/markdown",
175-
csv: "text/csv"
178+
csv: "text/csv",
179+
json: "application/json"
176180
} as const;
177181

178182
function prepareImagedownload() {

src/components/artifacts/artifact-node-sheet/DetailCards.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import { ExecutionStatusIcon, getExecutionStatusTagColor } from "@/components/Ex
77
import { InlineAvatar } from "@/components/InlineAvatar";
88
import { Key, KeyValue, Value } from "@/components/KeyValue";
99
import { useArtifactVersion } from "@/data/artifact-versions/artifact-version-detail-query";
10+
import { componentQueries } from "@/data/components";
1011
import { usePipelineRun } from "@/data/pipeline-runs/pipeline-run-detail-query";
1112
import { useStepDetail } from "@/data/steps/step-detail-query";
13+
import { getArtifactVersionSnippet } from "@/lib/code-snippets";
1214
import { routes } from "@/router/routes";
15+
import { useQuery } from "@tanstack/react-query";
1316
import {
1417
Skeleton,
1518
Tag,
@@ -21,8 +24,6 @@ import {
2124
import { Link } from "react-router-dom";
2225
import { Codesnippet } from "../../CodeSnippet";
2326
import { CollapsibleCard } from "../../CollapsibleCard";
24-
import { useQuery } from "@tanstack/react-query";
25-
import { componentQueries } from "../../../data/components";
2627

2728
type Props = {
2829
artifactVersionId: string;
@@ -251,16 +252,14 @@ export function DataCard({ artifactVersionId }: Props) {
251252
}
252253

253254
export function CodeCard({ artifactVersionId }: Props) {
254-
function returnConfigSchema(id: string) {
255-
return `from zenml.client import Client
256-
257-
step = Client().get_run_step(${id})
258-
config = step.config`;
259-
}
260-
261255
return (
262256
<CollapsibleCard initialOpen title="Code">
263-
<Codesnippet fullWidth highlightCode wrap code={returnConfigSchema(artifactVersionId)} />
257+
<Codesnippet
258+
fullWidth
259+
highlightCode
260+
wrap
261+
code={getArtifactVersionSnippet(artifactVersionId)}
262+
/>
264263
</CollapsibleCard>
265264
);
266265
}

src/components/dag-visualizer/ArtifactNode.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Copy from "@/assets/icons/copy.svg?react";
2+
import { getArtifactVersionSnippet } from "@/lib/code-snippets";
23
import { ArtifactVersion } from "@/types/artifact-versions";
34
import { NodeProps, useStore } from "reactflow";
45
import { ArtifactIcon } from "../ArtifactIcon";
@@ -51,10 +52,7 @@ export function ArtifactNode({ data, selected }: NodeProps<ArtifactVersion & { n
5152
</div>
5253
<CopyNodeButton
5354
className="h-4 w-4 shrink-0 rounded-sm hover:bg-primary-100 active:bg-primary-200"
54-
code={`from zenml.client import Client
55-
56-
artifact = Client().get_artifact_version("${data.id}")
57-
loaded_artifact = artifact.load()`}
55+
code={getArtifactVersionSnippet(data.id)}
5856
type="artifact"
5957
>
6058
<Copy className="h-3 w-3 fill-primary-400" />

0 commit comments

Comments
 (0)