Skip to content

fix: redesign schedule bumper to handle multiple hours of change at once #4535

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 15 commits into from
Oct 14, 2022
Prev Previous commit
Next Next commit
Handle undefined deadline
  • Loading branch information
presleyp committed Oct 12, 2022
commit 666c8d8c3eb21e9fc8875bf155c7a883bf145e03
7 changes: 4 additions & 3 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useContext } from "react"
import { Helmet } from "react-helmet-async"
import { useTranslation } from "react-i18next"
import { getMaxDeadline, getMaxDeadlineChange, getMinDeadline } from "util/schedule"
//import { getMaxDeadlineDecrease, getMaxDeadlineIncrease } from "util/schedule"
import { selectFeatureVisibility } from "xServices/entitlements/entitlementsSelectors"
import { StateFrom } from "xstate"
import { DeleteDialog } from "../../components/Dialogs/DeleteDialog/DeleteDialog"
Expand Down Expand Up @@ -33,6 +32,7 @@ export const WorkspaceReadyPage = ({
const [bannerState, bannerSend] = useActor(
workspaceState.children["scheduleBannerMachine"],
)
const deadline = bannerState.context.workspace.deadline
const xServices = useContext(XServiceContext)
const featureVisibility = useSelector(
xServices.entitlementsXService,
Expand All @@ -41,6 +41,7 @@ export const WorkspaceReadyPage = ({
const [buildInfoState] = useActor(xServices.buildInfoXService)
const {
workspace,
template,
refreshWorkspaceWarning,
builds,
getBuildsError,
Expand Down Expand Up @@ -97,8 +98,8 @@ export const WorkspaceReadyPage = ({
},
deadlineMinusEnabled: () => !bannerState.matches("atMinDeadline"),
deadlinePlusEnabled: () => !bannerState.matches("atMaxDeadline"),
maxDeadlineDecrease: getMaxDeadlineChange(bannerState.context.workspace.deadline, getMinDeadline()),
maxDeadlineIncrease: getMaxDeadlineChange(bannerState.context.workspace.deadline, getMaxDeadline(workspace, bannerState.context.template))
maxDeadlineDecrease: deadline ? getMaxDeadlineChange(deadline, getMinDeadline()) : 0,
maxDeadlineIncrease: (deadline && template) ? getMaxDeadlineChange(getMaxDeadline(workspace, template), deadline) : 0
}}
isUpdating={workspaceState.hasTag("updating")}
workspace={workspace}
Expand Down
6 changes: 3 additions & 3 deletions site/src/util/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ export const getDeadline = (workspace: Workspace): dayjs.Dayjs =>
* @param template
* @returns number, in hours
*/
export const getMaxDeadlineChange = (deadline: dayjs.Dayjs, extremeDeadline: dayjs.Dayjs): number => {
return Math.abs(deadline.diff(extremeDeadline, "hours"))
}
export const getMaxDeadlineChange = (deadline: dayjs.Dayjs, extremeDeadline: dayjs.Dayjs): number => (
Math.abs(deadline.diff(extremeDeadline, "hours"))
)