Skip to content

Commit 9d8578e

Browse files
refactor(site): apply minor naming improvements (#11080)
Minor naming and logic improvements to improve readability
1 parent 2c7394b commit 9d8578e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

site/src/pages/WorkspacePage/WorkspaceStats.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const WorkspaceStats: FC<WorkspaceStatsProps> = ({
110110
{shouldDisplayScheduleLabel(workspace) && (
111111
<StatsItem
112112
css={styles.statsItem}
113-
label={getScheduleLabel(workspace)}
113+
label={scheduleLabel(workspace)}
114114
value={
115115
<div css={styles.scheduleValue}>
116116
{isWorkspaceOn(workspace) ? (
@@ -335,21 +335,25 @@ const ScheduleSettingsLink = forwardRef<HTMLAnchorElement, LinkProps>(
335335
},
336336
);
337337

338+
const hasDeadline = (workspace: Workspace): boolean => {
339+
return Boolean(workspace.latest_build.deadline);
340+
};
341+
342+
const hasAutoStart = (workspace: Workspace): boolean => {
343+
return Boolean(workspace.autostart_schedule);
344+
};
345+
338346
export const canEditDeadline = (workspace: Workspace): boolean => {
339-
return isWorkspaceOn(workspace) && Boolean(workspace.latest_build.deadline);
347+
return isWorkspaceOn(workspace) && hasDeadline(workspace);
340348
};
341349

342350
export const shouldDisplayScheduleLabel = (workspace: Workspace): boolean => {
343-
if (canEditDeadline(workspace)) {
344-
return true;
345-
}
346-
if (isWorkspaceOn(workspace)) {
347-
return false;
348-
}
349-
return Boolean(workspace.autostart_schedule);
351+
const willAutoStop = isWorkspaceOn(workspace) && hasDeadline(workspace);
352+
const willAutoStart = !isWorkspaceOn(workspace) && hasAutoStart(workspace);
353+
return willAutoStop || willAutoStart;
350354
};
351355

352-
const getScheduleLabel = (workspace: Workspace) => {
356+
const scheduleLabel = (workspace: Workspace) => {
353357
return isWorkspaceOn(workspace) ? "Stops" : "Starts at";
354358
};
355359

0 commit comments

Comments
 (0)