From 3f52e6402464ee688aa39490a70bb1a4e629c0d8 Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 24 May 2022 06:01:55 +0000 Subject: [PATCH] refactor: resource strings in WorkspaceSchedule --- .../WorkspaceSchedule/WorkspaceSchedule.tsx | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index 8e3b33af0f52d..f15a731f89089 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -15,42 +15,44 @@ import { Stack } from "../Stack/Stack" dayjs.extend(duration) dayjs.extend(relativeTime) -const autoStartLabel = (schedule: string): string => { - const prefix = "Start" - - if (schedule) { - return `${prefix} (${extractTimezone(schedule)})` - } else { - return prefix - } -} - -const autoStartDisplay = (schedule: string): string => { - if (schedule) { - return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false }) - } - return "Manual" -} +const Language = { + autoStartDisplay: (schedule: string): string => { + if (schedule) { + return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false }) + } + return "Manual" + }, + autoStartLabel: (schedule: string): string => { + const prefix = "Start" -const autoStopDisplay = (workspace: Workspace): string => { - const latest = workspace.latest_build + if (schedule) { + return `${prefix} (${extractTimezone(schedule)})` + } else { + return prefix + } + }, + autoStopDisplay: (workspace: Workspace): string => { + const latest = workspace.latest_build - if (!workspace.ttl || workspace.ttl < 1) { - return "Manual" - } + if (!workspace.ttl || workspace.ttl < 1) { + return "Manual" + } - if (latest.transition === "start") { - const now = dayjs() - const updatedAt = dayjs(latest.updated_at) - const deadline = updatedAt.add(workspace.ttl / 1_000_000, "ms") - if (now.isAfter(deadline)) { - return "Workspace is shutting down now" + if (latest.transition === "start") { + const now = dayjs() + const updatedAt = dayjs(latest.updated_at) + const deadline = updatedAt.add(workspace.ttl / 1_000_000, "ms") + if (now.isAfter(deadline)) { + return "Workspace is shutting down now" + } + return now.to(deadline) } - return now.to(deadline) - } - const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds") - return `${duration.humanize()} after start` + const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds") + return `${duration.humanize()} after start` + }, + editScheduleLink: "Edit schedule", + schedule: "Schedule", } export interface WorkspaceScheduleProps { @@ -65,18 +67,18 @@ export const WorkspaceSchedule: React.FC = ({ workspace - Schedule + {Language.schedule}
- {autoStartLabel(workspace.autostart_schedule)} - {autoStartDisplay(workspace.autostart_schedule)} + {Language.autoStartLabel(workspace.autostart_schedule)} + {Language.autoStartDisplay(workspace.autostart_schedule)}
Shutdown - {autoStopDisplay(workspace)} + {Language.autoStopDisplay(workspace)}
- Edit schedule + {Language.editScheduleLink}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy