Skip to content

Commit 3f73a6c

Browse files
committed
fixup! feat: edit workspace schedule page
1 parent 58ecefa commit 3f73a6c

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

site/src/AppRouter.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { CreateUserPage } from "./pages/UsersPage/CreateUserPage/CreateUserPage"
1717
import { UsersPage } from "./pages/UsersPage/UsersPage"
1818
import { WorkspaceBuildPage } from "./pages/WorkspaceBuildPage/WorkspaceBuildPage"
1919
import { WorkspacePage } from "./pages/WorkspacePage/WorkspacePage"
20+
import { WorkspaceSchedulePage } from "./pages/WorkspaceSchedulePage/WorkspaceSchedulePage"
2021
import { WorkspaceSettingsPage } from "./pages/WorkspaceSettingsPage/WorkspaceSettingsPage"
2122

2223
const TerminalPage = React.lazy(() => import("./pages/TerminalPage/TerminalPage"))
@@ -73,6 +74,14 @@ export const AppRouter: React.FC = () => (
7374
</AuthAndFrame>
7475
}
7576
/>
77+
<Route
78+
path="schedule"
79+
element={
80+
<AuthAndFrame>
81+
<WorkspaceSchedulePage />
82+
</AuthAndFrame>
83+
}
84+
/>
7685
</Route>
7786
</Route>
7887

site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx

Lines changed: 40 additions & 36 deletions
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,20 @@ 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} href={`/workspace/${workspace.id}/schedule`}>
82+
{Language.editScheduleLink}
83+
</Link>
8084
</div>
8185
</Stack>
8286
</div>

0 commit comments

Comments
 (0)