From ae47dda8611133702df1daf7bf64eacaa2b9fb66 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Fri, 23 Sep 2022 19:47:32 +0000 Subject: [PATCH] fix: Remove "Starts at Manual" label Fixes #2798. --- .../WorkspaceScheduleButton.stories.tsx | 16 +++++ .../WorkspaceScheduleButton.tsx | 66 +++++++++++-------- 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.stories.tsx b/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.stories.tsx index 4ba95a70dc3de..1e2bb06b33caa 100644 --- a/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.stories.tsx +++ b/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.stories.tsx @@ -72,6 +72,22 @@ WorkspaceOffLong.args = { }, } +export const WorkspaceOn = Template.bind({}) +WorkspaceOn.args = { + deadlineMinusEnabled: () => true, + deadlinePlusEnabled: () => true, + workspace: { + ...Mocks.MockWorkspace, + + latest_build: { + ...Mocks.MockWorkspaceBuild, + transition: "start", + deadline: "2022-05-17T23:59:00.00Z", + }, + ttl_ms: 2 * 365 * 24 * 60 * 60 * 1000, // 2 years + }, +} + export const CannotEdit = Template.bind({}) CannotEdit.args = { workspace: { diff --git a/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.tsx b/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.tsx index e264321d377a9..c5cf4974d93ba 100644 --- a/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.tsx +++ b/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.tsx @@ -31,6 +31,16 @@ export const shouldDisplayPlusMinus = (workspace: Workspace): boolean => { return isWorkspaceOn(workspace) && Boolean(workspace.latest_build.deadline) } +export const shouldDisplayScheduleLabel = (workspace: Workspace): boolean => { + if (shouldDisplayPlusMinus(workspace)) { + return true + } + if (isWorkspaceOn(workspace)) { + return false + } + return Boolean(workspace.autostart_schedule) +} + export interface WorkspaceScheduleButtonProps { workspace: Workspace onDeadlinePlus: () => void @@ -60,33 +70,35 @@ export const WorkspaceScheduleButton: React.FC = ( return ( - - - {canUpdateWorkspace && shouldDisplayPlusMinus(workspace) && ( - - - - - - - - - - - - - )} - + {shouldDisplayScheduleLabel(workspace) && ( + + + {canUpdateWorkspace && shouldDisplayPlusMinus(workspace) && ( + + + + + + + + + + + + + )} + + )} <>