Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e407020

Browse files
greyscaledkylecarbs
authored andcommitted
refactor: resource strings in WorkspaceSchedule (#1702)
1 parent 55680ca commit e407020

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx

+38-36
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,44 @@ import { Stack } from "../Stack/Stack"
1515
dayjs.extend(duration)
1616
dayjs.extend(relativeTime)
1717

18-
const autoStartLabel = (schedule: string): string => {
19-
const prefix = "Start"
20-
21-
if (schedule) {
22-
return `${prefix} (${extractTimezone(schedule)})`
23-
} else {
24-
return prefix
25-
}
26-
}
27-
28-
const autoStartDisplay = (schedule: string): string => {
29-
if (schedule) {
30-
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false })
31-
}
32-
return "Manual"
33-
}
18+
const Language = {
19+
autoStartDisplay: (schedule: string): string => {
20+
if (schedule) {
21+
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false })
22+
}
23+
return "Manual"
24+
},
25+
autoStartLabel: (schedule: string): string => {
26+
const prefix = "Start"
3427

35-
const autoStopDisplay = (workspace: Workspace): string => {
36-
const latest = workspace.latest_build
28+
if (schedule) {
29+
return `${prefix} (${extractTimezone(schedule)})`
30+
} else {
31+
return prefix
32+
}
33+
},
34+
autoStopDisplay: (workspace: Workspace): string => {
35+
const latest = workspace.latest_build
3736

38-
if (!workspace.ttl || workspace.ttl < 1) {
39-
return "Manual"
40-
}
37+
if (!workspace.ttl || workspace.ttl < 1) {
38+
return "Manual"
39+
}
4140

42-
if (latest.transition === "start") {
43-
const now = dayjs()
44-
const updatedAt = dayjs(latest.updated_at)
45-
const deadline = updatedAt.add(workspace.ttl / 1_000_000, "ms")
46-
if (now.isAfter(deadline)) {
47-
return "Workspace is shutting down now"
41+
if (latest.transition === "start") {
42+
const now = dayjs()
43+
const updatedAt = dayjs(latest.updated_at)
44+
const deadline = updatedAt.add(workspace.ttl / 1_000_000, "ms")
45+
if (now.isAfter(deadline)) {
46+
return "Workspace is shutting down now"
47+
}
48+
return now.to(deadline)
4849
}
49-
return now.to(deadline)
50-
}
5150

52-
const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds")
53-
return `${duration.humanize()} after start`
51+
const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds")
52+
return `${duration.humanize()} after start`
53+
},
54+
editScheduleLink: "Edit schedule",
55+
schedule: "Schedule",
5456
}
5557

5658
export interface WorkspaceScheduleProps {
@@ -65,18 +67,18 @@ export const WorkspaceSchedule: React.FC<WorkspaceScheduleProps> = ({ workspace
6567
<Stack spacing={2}>
6668
<Typography variant="body1" className={styles.title}>
6769
<ScheduleIcon className={styles.scheduleIcon} />
68-
Schedule
70+
{Language.schedule}
6971
</Typography>
7072
<div>
71-
<span className={styles.scheduleLabel}>{autoStartLabel(workspace.autostart_schedule)}</span>
72-
<span className={styles.scheduleValue}>{autoStartDisplay(workspace.autostart_schedule)}</span>
73+
<span className={styles.scheduleLabel}>{Language.autoStartLabel(workspace.autostart_schedule)}</span>
74+
<span className={styles.scheduleValue}>{Language.autoStartDisplay(workspace.autostart_schedule)}</span>
7375
</div>
7476
<div>
7577
<span className={styles.scheduleLabel}>Shutdown</span>
76-
<span className={styles.scheduleValue}>{autoStopDisplay(workspace)}</span>
78+
<span className={styles.scheduleValue}>{Language.autoStopDisplay(workspace)}</span>
7779
</div>
7880
<div>
79-
<Link className={styles.scheduleAction}>Edit schedule</Link>
81+
<Link className={styles.scheduleAction}>{Language.editScheduleLink}</Link>
8082
</div>
8183
</Stack>
8284
</div>

0 commit comments

Comments
 (0)