Skip to content

Commit 935d4a0

Browse files
(feature/PRD-383-dates-during-running): Handle end date and duration (#597)
* (feature/PRD-383-dates-during-running): Handle end date and duration * (feature/PRD-361-artifact-pannel-fixes): docker image and contains code fixed * (feature/PRD-361-artifact-pannel-fixes): docker image and contains code fixed * fix: deepscan * (feature/PRD-383-dates-during-running): Docker image key * (feature/PRD-383-dates-during-running): Fixed tests --------- Co-authored-by: Cahllagerfeld <[email protected]>
1 parent 1814487 commit 935d4a0

File tree

5 files changed

+113
-6
lines changed

5 files changed

+113
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { CopyButton } from "@/components/CopyButton";
1313
import { Codesnippet } from "@/components/CodeSnippet";
1414
import { KeyValue } from "@/components/KeyValue";
1515
import { BuildItem } from "@/types/pipeline-builds";
16+
import { extractDockerImageKey } from "@/lib/strings";
1617

1718
type Props = {
1819
data: BuildItem;
@@ -41,7 +42,7 @@ export function DockerImageCollapsible({ data }: Props) {
4142
<div className="flex justify-between">
4243
<Tag className="inline-flex items-center gap-0.5" rounded={false} emphasis="subtle">
4344
<Docker className="mr-1 h-4 w-4 fill-theme-text-brand" />
44-
{"zenml/my_pipeline:data"}
45+
{extractDockerImageKey(data.image)}
4546
</Tag>
4647
<div className="align-center mr-1 flex">
4748
<a

src/app/runs/[id]/_Tabs/Overview/Details.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,19 @@ export function Details() {
7474
</Value>
7575
<Key>Start Time</Key>
7676
<Value>
77-
<DisplayDate dateString={data.metadata?.start_time || ""} />
77+
{data.metadata?.start_time ? (
78+
<DisplayDate dateString={data.metadata?.start_time} />
79+
) : (
80+
"Not available"
81+
)}
7882
</Value>
7983
<Key>End Time</Key>
8084
<Value>
81-
<DisplayDate dateString={data.metadata?.end_time || ""} />
85+
{data.metadata?.end_time ? (
86+
<DisplayDate dateString={data.metadata?.end_time} />
87+
) : (
88+
"Not available"
89+
)}
8290
</Value>
8391
</dl>
8492
</CollapsibleContent>

src/components/steps/step-sheet/DetailsTab.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,23 @@ export function StepDetailsTab({ stepId, runId }: Props) {
160160
<KeyValue label="Cache key" value={data.metadata?.cache_key || ""} />
161161
<KeyValue
162162
label="Start Time"
163-
value={<DisplayDate dateString={data.metadata?.start_time || ""} />}
163+
value={
164+
data.metadata?.start_time ? (
165+
<DisplayDate dateString={data.metadata?.start_time} />
166+
) : (
167+
"Not available"
168+
)
169+
}
164170
/>
165171
<KeyValue
166172
label="End Time"
167-
value={<DisplayDate dateString={data.metadata?.end_time || ""} />}
173+
value={
174+
data.metadata?.end_time ? (
175+
<DisplayDate dateString={data.metadata?.end_time} />
176+
) : (
177+
"Not available"
178+
)
179+
}
168180
/>
169181
<KeyValue
170182
label="Duration"

src/lib/strings.spec.ts

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { describe, expect, test } from "vitest";
2-
import { snakeCaseToTitleCase } from "./strings";
2+
import {
3+
extractDockerImageKey,
4+
renderAnyToString,
5+
snakeCaseToTitleCase,
6+
transformToEllipsis
7+
} from "./strings";
38

49
describe("snakeCaseToTitleCase converts snake_case to Title Case", () => {
510
const testCases = [
@@ -16,3 +21,70 @@ describe("snakeCaseToTitleCase converts snake_case to Title Case", () => {
1621
});
1722
});
1823
});
24+
25+
describe("renderAnyToString converts any value to string", () => {
26+
const testCases = [
27+
{ value: true, expected: "true", description: "Boolean conversion" },
28+
{ value: false, expected: "false", description: "Boolean conversion" },
29+
{ value: { key: "value" }, expected: '{"key":"value"}', description: "Object conversion" },
30+
{ value: "text", expected: "text", description: "Original value" },
31+
{ value: 123, expected: 123, description: "Original value" }
32+
];
33+
34+
testCases.forEach(({ value, expected, description }) => {
35+
test(description, () => {
36+
expect(renderAnyToString(value)).toBe(expected);
37+
});
38+
});
39+
});
40+
41+
describe("transformToEllipsis truncates text to maxLength and adds '...'", () => {
42+
const testCases = [
43+
{
44+
text: "Short text",
45+
maxLength: 20,
46+
expected: "Short text",
47+
description: "Text shorter than maxLength"
48+
},
49+
{
50+
text: "This is a long text",
51+
maxLength: 12,
52+
expected: "This is a...",
53+
description: "Text longer than maxLength"
54+
},
55+
{
56+
text: "Equal length",
57+
maxLength: 12,
58+
expected: "Equal length",
59+
description: "Text equal to maxLength"
60+
}
61+
];
62+
63+
testCases.forEach(({ text, maxLength, expected, description }) => {
64+
test(description, () => {
65+
expect(transformToEllipsis(text, maxLength)).toBe(expected);
66+
});
67+
});
68+
});
69+
70+
describe("extractDockerImageKey extracts Docker image key from string", () => {
71+
const testCases = [
72+
{
73+
string: "1.amazonaws.com/zenml:0.57.0",
74+
expected: "zenml:0.57.0",
75+
description: "String with tag"
76+
},
77+
{
78+
string:
79+
"339712793861.dkr.ecr.eu-central-1.amazonaws.com/zenml@sha256:8913beaf69e74a4b5b6cf2ee7c99f34dc6eac26fa967a743e9894a890c46a4e1",
80+
expected: "zenml",
81+
description: "String without tag"
82+
}
83+
];
84+
85+
testCases.forEach(({ string, expected, description }) => {
86+
test(description, () => {
87+
expect(extractDockerImageKey(string)).toBe(expected);
88+
});
89+
});
90+
});

src/lib/strings.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,17 @@ export const transformToEllipsis = (text: string, maxLength: number) => {
2222
return text.slice(0, maxLength - 3) + "...";
2323
}
2424
};
25+
26+
export const extractDockerImageKey = (string: string) => {
27+
const regex = /\/([^@/:]+)(?:@[^@]*$|:([^@]*$|$))/;
28+
const match = regex.exec(string);
29+
if (match && match[1]) {
30+
if (match[2]) {
31+
return `${match[1]}:${match[2]}`;
32+
} else {
33+
return match[1];
34+
}
35+
} else {
36+
return null;
37+
}
38+
};

0 commit comments

Comments
 (0)