mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
refactor: resource strings in WorkspaceSchedule (#1702)
This commit is contained in:
@ -15,7 +15,14 @@ import { Stack } from "../Stack/Stack"
|
|||||||
dayjs.extend(duration)
|
dayjs.extend(duration)
|
||||||
dayjs.extend(relativeTime)
|
dayjs.extend(relativeTime)
|
||||||
|
|
||||||
const autoStartLabel = (schedule: string): string => {
|
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 prefix = "Start"
|
||||||
|
|
||||||
if (schedule) {
|
if (schedule) {
|
||||||
@ -23,16 +30,8 @@ const autoStartLabel = (schedule: string): string => {
|
|||||||
} else {
|
} else {
|
||||||
return prefix
|
return prefix
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
autoStopDisplay: (workspace: Workspace): string => {
|
||||||
const autoStartDisplay = (schedule: string): string => {
|
|
||||||
if (schedule) {
|
|
||||||
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false })
|
|
||||||
}
|
|
||||||
return "Manual"
|
|
||||||
}
|
|
||||||
|
|
||||||
const autoStopDisplay = (workspace: Workspace): string => {
|
|
||||||
const latest = workspace.latest_build
|
const latest = workspace.latest_build
|
||||||
|
|
||||||
if (!workspace.ttl || workspace.ttl < 1) {
|
if (!workspace.ttl || workspace.ttl < 1) {
|
||||||
@ -51,6 +50,9 @@ const autoStopDisplay = (workspace: Workspace): string => {
|
|||||||
|
|
||||||
const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds")
|
const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds")
|
||||||
return `${duration.humanize()} after start`
|
return `${duration.humanize()} after start`
|
||||||
|
},
|
||||||
|
editScheduleLink: "Edit schedule",
|
||||||
|
schedule: "Schedule",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WorkspaceScheduleProps {
|
export interface WorkspaceScheduleProps {
|
||||||
@ -65,18 +67,18 @@ export const WorkspaceSchedule: React.FC<WorkspaceScheduleProps> = ({ workspace
|
|||||||
<Stack spacing={2}>
|
<Stack spacing={2}>
|
||||||
<Typography variant="body1" className={styles.title}>
|
<Typography variant="body1" className={styles.title}>
|
||||||
<ScheduleIcon className={styles.scheduleIcon} />
|
<ScheduleIcon className={styles.scheduleIcon} />
|
||||||
Schedule
|
{Language.schedule}
|
||||||
</Typography>
|
</Typography>
|
||||||
<div>
|
<div>
|
||||||
<span className={styles.scheduleLabel}>{autoStartLabel(workspace.autostart_schedule)}</span>
|
<span className={styles.scheduleLabel}>{Language.autoStartLabel(workspace.autostart_schedule)}</span>
|
||||||
<span className={styles.scheduleValue}>{autoStartDisplay(workspace.autostart_schedule)}</span>
|
<span className={styles.scheduleValue}>{Language.autoStartDisplay(workspace.autostart_schedule)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span className={styles.scheduleLabel}>Shutdown</span>
|
<span className={styles.scheduleLabel}>Shutdown</span>
|
||||||
<span className={styles.scheduleValue}>{autoStopDisplay(workspace)}</span>
|
<span className={styles.scheduleValue}>{Language.autoStopDisplay(workspace)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Link className={styles.scheduleAction}>Edit schedule</Link>
|
<Link className={styles.scheduleAction}>{Language.editScheduleLink}</Link>
|
||||||
</div>
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user