Skip to content

Commit dab8aab

Browse files
committed
Extract optionValue into a module
1 parent a8bb51c commit dab8aab

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

site/src/components/DeploySettingsLayout/OptionsTable.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
OptionValue,
1313
} from "components/DeploySettingsLayout/Option";
1414
import { FC } from "react";
15-
import { intervalToDuration, formatDuration } from "date-fns";
15+
import { optionValue } from "./optionValue";
1616

1717
const OptionsTable: FC<{
1818
options: DeploymentOption[];
@@ -60,29 +60,6 @@ const OptionsTable: FC<{
6060
);
6161
};
6262

63-
// optionValue is a helper function to format the value of a specific deployment options
64-
export function optionValue(option: DeploymentOption) {
65-
switch (option.name) {
66-
case "Max Token Lifetime":
67-
case "Session Duration":
68-
// intervalToDuration takes ms, so convert nanoseconds to ms
69-
return formatDuration(
70-
intervalToDuration({ start: 0, end: (option.value as number) / 1e6 }),
71-
);
72-
case "Strict-Transport-Security":
73-
if (option.value === 0) {
74-
return "Disabled";
75-
}
76-
return (option.value as number).toString() + "s";
77-
case "OIDC Group Mapping":
78-
return Object.entries(option.value as Record<string, string>).map(
79-
([key, value]) => `"${key}"->"${value}"`,
80-
);
81-
default:
82-
return option.value;
83-
}
84-
}
85-
8663
const useStyles = makeStyles((theme) => ({
8764
table: {
8865
"& td": {

site/src/components/DeploySettingsLayout/Options.test.tsx renamed to site/src/components/DeploySettingsLayout/optionValue.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { optionValue } from "./OptionsTable";
1+
import { optionValue } from "./optionValue";
22
import { DeploymentOption } from "api/types";
33

44
const defaultOption: DeploymentOption = {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { DeploymentOption } from "api/types";
2+
import { intervalToDuration, formatDuration } from "date-fns";
3+
4+
// optionValue is a helper function to format the value of a specific deployment options
5+
export function optionValue(option: DeploymentOption) {
6+
switch (option.name) {
7+
case "Max Token Lifetime":
8+
case "Session Duration":
9+
// intervalToDuration takes ms, so convert nanoseconds to ms
10+
return formatDuration(
11+
intervalToDuration({ start: 0, end: (option.value as number) / 1e6 }),
12+
);
13+
case "Strict-Transport-Security":
14+
if (option.value === 0) {
15+
return "Disabled";
16+
}
17+
return (option.value as number).toString() + "s";
18+
case "OIDC Group Mapping":
19+
return Object.entries(option.value as Record<string, string>).map(
20+
([key, value]) => `"${key}"->"${value}"`,
21+
);
22+
default:
23+
return option.value;
24+
}
25+
}

0 commit comments

Comments
 (0)