Skip to content

Commit d29e21f

Browse files
committed
fixup! feat(site): correctly display values of type clibase.Duration
1 parent 8166f57 commit d29e21f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

site/src/components/DeploySettingsLayout/optionValue.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ describe("optionValue", () => {
2121
...defaultOption,
2222
name: "Max Token Lifetime",
2323
value: 3600 * 1e9,
24+
annotations: { format_duration_ns: "false" },
2425
},
25-
expected: "1 hour",
26+
expected: 3600000000000,
2627
},
2728
{
2829
option: {
2930
...defaultOption,
3031
name: "Max Token Lifetime",
3132
value: 24 * 3600 * 1e9,
33+
annotations: { format_duration_ns: "true" },
3234
},
3335
expected: "1 day",
3436
},
@@ -37,14 +39,16 @@ describe("optionValue", () => {
3739
...defaultOption,
3840
name: "Session Duration",
3941
value: 3600 * 1e9,
42+
annotations: { format_duration_ns: "falsae" },
4043
},
41-
expected: "1 hour",
44+
expected: 3600000000000,
4245
},
4346
{
4447
option: {
4548
...defaultOption,
4649
name: "Session Duration",
4750
value: 24 * 3600 * 1e9,
51+
annotations: { format_duration_ns: "true" },
4852
},
4953
expected: "1 day",
5054
},
@@ -109,18 +113,18 @@ describe("optionValue", () => {
109113
...defaultOption,
110114
name: "Some Go Duration We Want To Show As A String",
111115
value: 30 * 1e9,
112-
annotations: { "format_duration_ns": "true" },
116+
annotations: { format_duration_ns: "true" },
113117
},
114-
expected: "30s",
118+
expected: "30 seconds",
115119
},
116120
{
117121
option: {
118122
...defaultOption,
119123
name: "Some Other Go Duration We Want To Just Display As A Number",
120124
value: 30 * 1e9,
121-
annotations: { "format_duration_ns": "false" },
125+
annotations: { format_duration_ns: "false" },
122126
},
123-
expected: "30000000000"
127+
expected: 30000000000,
124128
},
125129
])(
126130
`[$option.name]optionValue($option.value)`,

site/src/components/DeploySettingsLayout/optionValue.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ export function optionValue(
1616
case "format_duration_ns":
1717
return formatDuration(
1818
// intervalToDuration takes ms, so convert nanoseconds to ms
19-
intervalToDuration({ start: 0, end: option.value as number / 1e6 }),
20-
)
19+
intervalToDuration({
20+
start: 0,
21+
end: (option.value as number) / 1e6,
22+
}),
23+
);
2124
// Add additional cases here as needed.
2225
}
23-
};
26+
}
2427
}
2528

2629
// If no format annotations are present, use the option name to format the value.

0 commit comments

Comments
 (0)