Skip to content

feature: allow editing workspace deadline in UI #2721

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 12 commits into from
Jun 30, 2022
Prev Previous commit
Next Next commit
disable edit deadline buttons if outside bounds
  • Loading branch information
johnstcn committed Jun 30, 2022
commit 7bae0facc6c1cf37ad02176da641c7114b57881c
26 changes: 24 additions & 2 deletions site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const Language = {
}

export interface WorkspaceScheduleProps {
now?: dayjs.Dayjs
workspace: Workspace
onDeadlinePlus: () => void
onDeadlineMinus: () => void
Expand All @@ -94,20 +95,41 @@ export const shouldDisplayPlusMins = (workspace: Workspace): boolean => {
return deadline.year() > 1
}

export const deadlineMinusDisabled = (workspace: Workspace, now: dayjs.Dayjs): boolean => {
const delta = dayjs(workspace.latest_build.deadline).diff(now)
return delta <= 30 * 60 * 1000
}

export const deadlinePlusDisabled = (workspace: Workspace, now: dayjs.Dayjs): boolean => {
const delta = dayjs(workspace.latest_build.deadline).diff(now)
return delta > 23 * 59 * 59 * 1000
}

export const WorkspaceSchedule: FC<WorkspaceScheduleProps> = ({
now,
workspace,
onDeadlineMinus,
onDeadlinePlus,
}) => {
const styles = useStyles()
const editDeadlineButtons = shouldDisplayPlusMins(workspace) ? (
<Stack direction="row" spacing={0}>
<IconButton size="small" className={styles.editDeadline} onClick={onDeadlineMinus}>
<IconButton
size="small"
disabled={deadlineMinusDisabled(workspace, now ? now : dayjs())}
className={styles.editDeadline}
onClick={onDeadlineMinus}
>
<Tooltip title={Language.editDeadlineMinus}>
<IndeterminateCheckBoxIcon />
</Tooltip>
</IconButton>
<IconButton size="small" className={styles.editDeadline} onClick={onDeadlinePlus}>
<IconButton
size="small"
disabled={deadlinePlusDisabled(workspace, now ? now : dayjs())}
className={styles.editDeadline}
onClick={onDeadlinePlus}
>
<Tooltip title={Language.editDeadlinePlus}>
<AddBoxIcon />
</Tooltip>
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/WorkspacePage/WorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const WorkspacePage: React.FC = () => {
bannerSend({
type: "UPDATE_DEADLINE",
workspaceId: workspace.id,
newDeadline: dayjs().utc().add(4, "hours"),
newDeadline: dayjs(workspace.latest_build.deadline).utc().add(4, "hours"),
})
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import * as API from "../../api/api"
import { displayError, displaySuccess } from "../../components/GlobalSnackbar/utils"

export const Language = {
errorExtension: "Failed to extend workspace deadline.",
successExtension: "Successfully extended workspace deadline.",
errorExtension: "Failed to update workspace shutdown time.",
successExtension: "Updated workspace shutdown time.",
}

export type WorkspaceScheduleBannerEvent = {
Expand Down