Skip to content

refactor(site): apply minor naming improvements #11080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor(site): minor naming improvements
  • Loading branch information
BrunoQuaresma committed Dec 7, 2023
commit aad46d5ea240a20aeaa859b103f05f2063f26c7a
24 changes: 14 additions & 10 deletions site/src/pages/WorkspacePage/WorkspaceStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const WorkspaceStats: FC<WorkspaceStatsProps> = ({
{shouldDisplayScheduleLabel(workspace) && (
<StatsItem
css={styles.statsItem}
label={getScheduleLabel(workspace)}
label={scheduleLabel(workspace)}
value={
<div css={styles.scheduleValue}>
{isWorkspaceOn(workspace) ? (
Expand Down Expand Up @@ -335,21 +335,25 @@ const ScheduleSettingsLink = forwardRef<HTMLAnchorElement, LinkProps>(
},
);

const hasDeadline = (workspace: Workspace): boolean => {
return Boolean(workspace.latest_build.deadline);
};

const hasAutoStart = (workspace: Workspace): boolean => {
return Boolean(workspace.autostart_schedule);
};

export const canEditDeadline = (workspace: Workspace): boolean => {
return isWorkspaceOn(workspace) && Boolean(workspace.latest_build.deadline);
return isWorkspaceOn(workspace) && hasDeadline(workspace);
};

export const shouldDisplayScheduleLabel = (workspace: Workspace): boolean => {
if (canEditDeadline(workspace)) {
return true;
}
if (isWorkspaceOn(workspace)) {
return false;
}
return Boolean(workspace.autostart_schedule);
const willAutoStop = isWorkspaceOn(workspace) && hasDeadline(workspace);
const willAutoStart = !isWorkspaceOn(workspace) && hasAutoStart(workspace);
return willAutoStop || willAutoStart;
};

const getScheduleLabel = (workspace: Workspace) => {
const scheduleLabel = (workspace: Workspace) => {
return isWorkspaceOn(workspace) ? "Stops" : "Starts at";
};

Expand Down