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

Skip to content

Commit 411d7da

Browse files
authored
fix: ws schedule as 12-hour format (#2209)
This does not finish all tasks in #2175 but is one of the asks.
1 parent 377f17c commit 411d7da

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx

+11-19
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { FC } from "react"
1313
import { Link as RouterLink } from "react-router-dom"
1414
import { Workspace } from "../../api/typesGenerated"
1515
import { MONOSPACE_FONT_FAMILY } from "../../theme/constants"
16-
import { extractTimezone, stripTimezone } from "../../util/schedule"
16+
import { stripTimezone } from "../../util/schedule"
1717
import { isWorkspaceOn } from "../../util/workspace"
1818
import { Stack } from "../Stack/Stack"
1919

@@ -31,20 +31,11 @@ export const Language = {
3131
return "Manual"
3232
}
3333
},
34-
autoStartLabel: (schedule: string | undefined): string => {
35-
const prefix = "Start"
36-
const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess()
37-
38-
if (schedule) {
39-
return `${prefix} (${dayjs().tz(timezone).format("z")})`
40-
} else {
41-
return prefix
42-
}
43-
},
34+
autoStartLabel: "START",
35+
autoStopLabel: "SHUTDOWN",
4436
autoStopDisplay: (workspace: Workspace): string => {
45-
const schedule = workspace.autostart_schedule
4637
const deadline = dayjs(workspace.latest_build.deadline).utc()
47-
// a mannual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
38+
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
4839
// SEE: #1834
4940
const hasDeadline = deadline.year() > 1
5041
const ttl = workspace.ttl_ms
@@ -59,8 +50,7 @@ export const Language = {
5950
if (now.isAfter(deadline)) {
6051
return "Workspace is shutting down"
6152
} else {
62-
const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess()
63-
return deadline.tz(timezone).format("HH:mm A")
53+
return deadline.tz(dayjs.tz.guess()).format("hh:mm A")
6454
}
6555
} else if (!ttl || ttl < 1) {
6656
// If the workspace is not on, and the ttl is 0 or undefined, then the
@@ -74,7 +64,7 @@ export const Language = {
7464
}
7565
},
7666
editScheduleLink: "Edit schedule",
77-
schedule: "Schedule",
67+
schedule: `Schedule (${dayjs.tz.guess()})`,
7868
}
7969

8070
export interface WorkspaceScheduleProps {
@@ -92,11 +82,13 @@ export const WorkspaceSchedule: FC<WorkspaceScheduleProps> = ({ workspace }) =>
9282
{Language.schedule}
9383
</Typography>
9484
<div>
95-
<span className={styles.scheduleLabel}>{Language.autoStartLabel(workspace.autostart_schedule)}</span>
96-
<span className={styles.scheduleValue}>{Language.autoStartDisplay(workspace.autostart_schedule)}</span>
85+
<span className={styles.scheduleLabel}>{Language.autoStartLabel}</span>
86+
<span className={styles.scheduleValue} data-chromatic="ignore">
87+
{Language.autoStartDisplay(workspace.autostart_schedule)}
88+
</span>
9789
</div>
9890
<div>
99-
<span className={styles.scheduleLabel}>Shutdown</span>
91+
<span className={styles.scheduleLabel}>{Language.autoStopLabel}</span>
10092
<span className={styles.scheduleValue} data-chromatic="ignore">
10193
{Language.autoStopDisplay(workspace)}
10294
</span>

site/src/pages/WorkspacePage/WorkspacePage.test.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ const renderWorkspacePage = async () => {
4343

4444
const testButton = async (label: string, actionMock: jest.SpyInstance) => {
4545
await renderWorkspacePage()
46-
const button = await screen.findByText(label)
46+
// REMARK: exact here because the "Start" button and "START" label for
47+
// workspace schedule could otherwise conflict.
48+
const button = await screen.findByText(label, { exact: true })
4749
await waitFor(() => fireEvent.click(button))
4850
expect(actionMock).toBeCalled()
4951
}

0 commit comments

Comments
 (0)