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

Skip to content

Commit 4f63555

Browse files
authored
fix: Remove "Starts at Manual" label (#4179)
Fixes #2798.
1 parent df2649e commit 4f63555

File tree

2 files changed

+71
-34
lines changed

2 files changed

+71
-34
lines changed

site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ WorkspaceOffLong.args = {
7272
},
7373
}
7474

75+
export const WorkspaceOn = Template.bind({})
76+
WorkspaceOn.args = {
77+
deadlineMinusEnabled: () => true,
78+
deadlinePlusEnabled: () => true,
79+
workspace: {
80+
...Mocks.MockWorkspace,
81+
82+
latest_build: {
83+
...Mocks.MockWorkspaceBuild,
84+
transition: "start",
85+
deadline: "2022-05-17T23:59:00.00Z",
86+
},
87+
ttl_ms: 2 * 365 * 24 * 60 * 60 * 1000, // 2 years
88+
},
89+
}
90+
7591
export const CannotEdit = Template.bind({})
7692
CannotEdit.args = {
7793
workspace: {

site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.tsx

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export const shouldDisplayPlusMinus = (workspace: Workspace): boolean => {
3131
return isWorkspaceOn(workspace) && Boolean(workspace.latest_build.deadline)
3232
}
3333

34+
export const shouldDisplayScheduleLabel = (workspace: Workspace): boolean => {
35+
if (shouldDisplayPlusMinus(workspace)) {
36+
return true
37+
}
38+
if (isWorkspaceOn(workspace)) {
39+
return false
40+
}
41+
return Boolean(workspace.autostart_schedule)
42+
}
43+
3444
export interface WorkspaceScheduleButtonProps {
3545
workspace: Workspace
3646
onDeadlinePlus: () => void
@@ -60,41 +70,45 @@ export const WorkspaceScheduleButton: React.FC<WorkspaceScheduleButtonProps> = (
6070

6171
return (
6272
<span className={styles.wrapper}>
63-
<span className={styles.label}>
64-
<WorkspaceScheduleLabel workspace={workspace} />
65-
{canUpdateWorkspace && shouldDisplayPlusMinus(workspace) && (
66-
<span className={styles.actions}>
67-
<IconButton
68-
className={styles.iconButton}
69-
size="small"
70-
disabled={!deadlineMinusEnabled()}
71-
onClick={onDeadlineMinus}
72-
>
73-
<Tooltip title={t("workspaceScheduleButton.editDeadlineMinus")}>
74-
<RemoveIcon />
75-
</Tooltip>
76-
</IconButton>
77-
<IconButton
78-
className={styles.iconButton}
79-
size="small"
80-
disabled={!deadlinePlusEnabled()}
81-
onClick={onDeadlinePlus}
82-
>
83-
<Tooltip title={t("workspaceScheduleButton.editDeadlinePlus")}>
84-
<AddIcon />
85-
</Tooltip>
86-
</IconButton>
87-
</span>
88-
)}
89-
</span>
73+
{shouldDisplayScheduleLabel(workspace) && (
74+
<span className={styles.label}>
75+
<WorkspaceScheduleLabel workspace={workspace} />
76+
{canUpdateWorkspace && shouldDisplayPlusMinus(workspace) && (
77+
<span className={styles.actions}>
78+
<IconButton
79+
className={styles.iconButton}
80+
size="small"
81+
disabled={!deadlineMinusEnabled()}
82+
onClick={onDeadlineMinus}
83+
>
84+
<Tooltip title={t("workspaceScheduleButton.editDeadlineMinus")}>
85+
<RemoveIcon />
86+
</Tooltip>
87+
</IconButton>
88+
<IconButton
89+
className={styles.iconButton}
90+
size="small"
91+
disabled={!deadlinePlusEnabled()}
92+
onClick={onDeadlinePlus}
93+
>
94+
<Tooltip title={t("workspaceScheduleButton.editDeadlinePlus")}>
95+
<AddIcon />
96+
</Tooltip>
97+
</IconButton>
98+
</span>
99+
)}
100+
</span>
101+
)}
90102
<>
91103
<Button
92104
ref={anchorRef}
93105
startIcon={<ScheduleIcon />}
94106
onClick={() => {
95107
setIsOpen(true)
96108
}}
97-
className={styles.scheduleButton}
109+
className={`${styles.scheduleButton} ${
110+
shouldDisplayScheduleLabel(workspace) ? "label" : ""
111+
}`}
98112
>
99113
{t("workspaceScheduleButton.schedule")}
100114
</Button>
@@ -124,8 +138,8 @@ const useStyles = makeStyles((theme) => ({
124138
wrapper: {
125139
display: "inline-flex",
126140
alignItems: "center",
127-
border: `1px solid ${theme.palette.divider}`,
128141
borderRadius: `${theme.shape.borderRadius}px`,
142+
border: `1px solid ${theme.palette.divider}`,
129143

130144
[theme.breakpoints.down("sm")]: {
131145
flexDirection: "column",
@@ -153,15 +167,22 @@ const useStyles = makeStyles((theme) => ({
153167
},
154168
scheduleButton: {
155169
border: "none",
156-
borderLeft: `1px solid ${theme.palette.divider}`,
157-
borderRadius: `0px ${theme.shape.borderRadius}px ${theme.shape.borderRadius}px 0px`,
170+
borderRadius: `${theme.shape.borderRadius}px`,
158171
flexShrink: 0,
159172

173+
"&.label": {
174+
borderLeft: `1px solid ${theme.palette.divider}`,
175+
borderRadius: `0px ${theme.shape.borderRadius}px ${theme.shape.borderRadius}px 0px`,
176+
},
177+
160178
[theme.breakpoints.down("sm")]: {
161179
width: "100%",
162-
borderLeft: 0,
163-
borderTop: `1px solid ${theme.palette.divider}`,
164-
borderRadius: `0 0 ${theme.shape.borderRadius}px ${theme.shape.borderRadius}px`,
180+
181+
"&.label": {
182+
borderRadius: `0 0 ${theme.shape.borderRadius}px ${theme.shape.borderRadius}px`,
183+
borderLeft: 0,
184+
borderTop: `1px solid ${theme.palette.divider}`,
185+
},
165186
},
166187
},
167188
iconButton: {

0 commit comments

Comments
 (0)