From 38ee6758329420d025ddd87ce20b35e8a9ac8b45 Mon Sep 17 00:00:00 2001 From: G r e y Date: Thu, 9 Jun 2022 16:33:09 +0000 Subject: [PATCH 1/6] fix: ws schedule as 12-hour format This does not finish all tasks in #2175 but is one of the asks. @johnstcn - you should do the same lowercasing of HH->hh in #2165 --- site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index 3861ae94d6e1c..f2405e671e3cb 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -60,7 +60,7 @@ export const Language = { return "Workspace is shutting down" } else { const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess() - return deadline.tz(timezone).format("HH:mm A") + return deadline.tz(timezone).format("hh:mm A") } } else if (!ttl || ttl < 1) { // If the workspace is not on, and the ttl is 0 or undefined, then the From 618f13da4d597eb104e8353fd9e02d3f663a0100 Mon Sep 17 00:00:00 2001 From: G r e y Date: Thu, 9 Jun 2022 17:40:12 +0000 Subject: [PATCH 2/6] fixup! fix: ws schedule as 12-hour format --- .../WorkspaceSchedule/WorkspaceSchedule.tsx | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index f2405e671e3cb..a7a70b191a2f3 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -13,7 +13,7 @@ import { FC } from "react" import { Link as RouterLink } from "react-router-dom" import { Workspace } from "../../api/typesGenerated" import { MONOSPACE_FONT_FAMILY } from "../../theme/constants" -import { extractTimezone, stripTimezone } from "../../util/schedule" +import { stripTimezone } from "../../util/schedule" import { isWorkspaceOn } from "../../util/workspace" import { Stack } from "../Stack/Stack" @@ -26,23 +26,16 @@ dayjs.extend(timezone) export const Language = { autoStartDisplay: (schedule: string | undefined): string => { if (schedule) { - return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false }) + return ( + cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false }) + ` (${dayjs.tz.guess()})` + ) } else { return "Manual" } }, - autoStartLabel: (schedule: string | undefined): string => { - const prefix = "Start" - const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess() - - if (schedule) { - return `${prefix} (${dayjs().tz(timezone).format("z")})` - } else { - return prefix - } - }, + autoStartLabel: "Start", + autoStopLabel: "Shutdown", autoStopDisplay: (workspace: Workspace): string => { - const schedule = workspace.autostart_schedule const deadline = dayjs(workspace.latest_build.deadline).utc() // a mannual shutdown has a deadline of '"0001-01-01T00:00:00Z"' // SEE: #1834 @@ -59,8 +52,8 @@ export const Language = { if (now.isAfter(deadline)) { return "Workspace is shutting down" } else { - const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess() - return deadline.tz(timezone).format("hh:mm A") + const browserTZ = dayjs.tz.guess() + return deadline.tz(browserTZ).format("hh:mm A") + ` (${browserTZ})` } } else if (!ttl || ttl < 1) { // If the workspace is not on, and the ttl is 0 or undefined, then the @@ -92,11 +85,13 @@ export const WorkspaceSchedule: FC = ({ workspace }) => {Language.schedule}
- {Language.autoStartLabel(workspace.autostart_schedule)} - {Language.autoStartDisplay(workspace.autostart_schedule)} + {Language.autoStartLabel} + + {Language.autoStartDisplay(workspace.autostart_schedule)} +
- Shutdown + {Language.autoStopLabel} {Language.autoStopDisplay(workspace)} From de183b7cd9d30d33901952df3923ae2361c55de0 Mon Sep 17 00:00:00 2001 From: G r e y Date: Thu, 9 Jun 2022 17:41:18 +0000 Subject: [PATCH 3/6] fixup! fix: ws schedule as 12-hour format --- site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index a7a70b191a2f3..b20905d2c1dd6 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -37,7 +37,7 @@ export const Language = { autoStopLabel: "Shutdown", autoStopDisplay: (workspace: Workspace): string => { const deadline = dayjs(workspace.latest_build.deadline).utc() - // a mannual shutdown has a deadline of '"0001-01-01T00:00:00Z"' + // a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"' // SEE: #1834 const hasDeadline = deadline.year() > 1 const ttl = workspace.ttl_ms From 51c92a657802371a53421597f80e691c1b3d2328 Mon Sep 17 00:00:00 2001 From: G r e y Date: Thu, 9 Jun 2022 17:46:17 +0000 Subject: [PATCH 4/6] fixup! fix: ws schedule as 12-hour format --- .../components/WorkspaceSchedule/WorkspaceSchedule.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index b20905d2c1dd6..99119b2b177ac 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -26,9 +26,7 @@ dayjs.extend(timezone) export const Language = { autoStartDisplay: (schedule: string | undefined): string => { if (schedule) { - return ( - cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false }) + ` (${dayjs.tz.guess()})` - ) + return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false }) } else { return "Manual" } @@ -53,7 +51,7 @@ export const Language = { return "Workspace is shutting down" } else { const browserTZ = dayjs.tz.guess() - return deadline.tz(browserTZ).format("hh:mm A") + ` (${browserTZ})` + return deadline.tz(browserTZ).format("hh:mm A") } } else if (!ttl || ttl < 1) { // If the workspace is not on, and the ttl is 0 or undefined, then the @@ -67,7 +65,7 @@ export const Language = { } }, editScheduleLink: "Edit schedule", - schedule: "Schedule", + schedule: `Schedule (${dayjs.tz.guess()})`, } export interface WorkspaceScheduleProps { From ccb543c6cd178214c9b64ccb496cb79fcb820e1b Mon Sep 17 00:00:00 2001 From: G r e y Date: Thu, 9 Jun 2022 17:47:35 +0000 Subject: [PATCH 5/6] fixup! fix: ws schedule as 12-hour format --- site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index 99119b2b177ac..2fccf79049146 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -50,8 +50,7 @@ export const Language = { if (now.isAfter(deadline)) { return "Workspace is shutting down" } else { - const browserTZ = dayjs.tz.guess() - return deadline.tz(browserTZ).format("hh:mm A") + return deadline.tz(dayjs.tz.guess()).format("hh:mm A") } } else if (!ttl || ttl < 1) { // If the workspace is not on, and the ttl is 0 or undefined, then the From 7bfc0b89e6a2456d64c33cdfcf2cfae6ac2bc2b2 Mon Sep 17 00:00:00 2001 From: G r e y Date: Thu, 9 Jun 2022 19:18:25 +0000 Subject: [PATCH 6/6] fixup! fix: ws schedule as 12-hour format --- site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx | 4 ++-- site/src/pages/WorkspacePage/WorkspacePage.test.tsx | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index 2fccf79049146..1a5d35a499f11 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -31,8 +31,8 @@ export const Language = { return "Manual" } }, - autoStartLabel: "Start", - autoStopLabel: "Shutdown", + autoStartLabel: "START", + autoStopLabel: "SHUTDOWN", autoStopDisplay: (workspace: Workspace): string => { const deadline = dayjs(workspace.latest_build.deadline).utc() // a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"' diff --git a/site/src/pages/WorkspacePage/WorkspacePage.test.tsx b/site/src/pages/WorkspacePage/WorkspacePage.test.tsx index fce7a50abafca..b7923c5530f78 100644 --- a/site/src/pages/WorkspacePage/WorkspacePage.test.tsx +++ b/site/src/pages/WorkspacePage/WorkspacePage.test.tsx @@ -43,7 +43,9 @@ const renderWorkspacePage = async () => { const testButton = async (label: string, actionMock: jest.SpyInstance) => { await renderWorkspacePage() - const button = await screen.findByText(label) + // REMARK: exact here because the "Start" button and "START" label for + // workspace schedule could otherwise conflict. + const button = await screen.findByText(label, { exact: true }) await waitFor(() => fireEvent.click(button)) expect(actionMock).toBeCalled() }