8000 fix: redesign schedule bumper to handle multiple hours of change at once by presleyp · Pull Request #4535 · coder/coder · GitHub
[go: up one dir, main page]

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
Merged
Prev Previous commit
Next Next commit
Format
  • Loading branch information
presleyp committed Oct 13, 2022
commit 24a7f2d9491f28bc03236a50789fc941167d4fc0
43 changes: 23 additions & 20 deletions site/src/components/WorkspaceScheduleButton/EditHours.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,44 @@ interface EditHoursProps {
max: number
}

export const EditHours = ({ handleSubmit, max }: EditHoursProps): JSX.Element => {
export const EditHours = ({
handleSubmit,
max,
}: EditHoursProps): JSX.Element => {
const { t } = useTranslation("workspacePage")
const [hours, setHours] = useState(1)
const styles = useStyles()

return (
<form onSubmit={() => handleSubmit(hours)}>
<Stack direction="row" alignItems="baseline" spacing={1}>
<TextField
className={styles.inputField}
inputProps={{ min: 0, max, step: 1 }}
label={t("workspaceScheduleButton.hours")}
value={hours}
onChange={(e) => setHours(parseInt(e.target.value))}
type="number"
/>
<Button className={styles.button} type="submit" color="primary">
{t("workspaceScheduleButton.submitDeadline")}
</Button>
</Stack>
<TextField
className={styles.inputField}
inputProps={{ min: 0, max, step: 1 }}
label={t("workspaceScheduleButton.hours")}
value={hours}
onChange={(e) => setHours(parseInt(e.target.value))}
type="number"
/>
<Button className={styles.button} type="submit" color="primary">
{t("workspaceScheduleButton.submitDeadline")}
</Button>
</Stack>
</form>
)
}

const useStyles = makeStyles(() => ({
inputField: {
width: '70px',
width: "70px",
"& .MuiOutlinedInput-root": {
height: '30px'
}
height: "30px",
},
},
button: {
"&.MuiButton-root": {
minHeight: '30px',
height: '30px'
}
}
minHeight: "30px",
height: "30px",
},
},
}))
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export default {
defaultValue: true,
},
deadlineMinusEnabled: {
defaultValue: (): boolean => false
defaultValue: (): boolean => false,
},
deadlinePlusEnabled: {
defaultValue: (): boolean => false
}
defaultValue: (): boolean => false,
},
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ export const WorkspaceScheduleButton: React.FC<
return (
<span className={styles.wrapper}>
<Maybe condition={shouldDisplayScheduleLabel(workspace)}>
<Stack className={styles.label} spacing={1} direction="row" alignItems="center" >
<Stack
className={styles.label}
spacing={1}
direction="row"
alignItems="center"
>
<WorkspaceScheduleLabel workspace={workspace} />
<Maybe condition={canUpdateWorkspace && canEditDeadline(workspace)}>
<span className={styles.actions}>
10000 Expand Down Expand Up @@ -125,7 +130,12 @@ export const WorkspaceScheduleButton: React.FC<
</IconButton>
</span>
<Maybe condition={editMode !== "off"}>
<EditHours handleSubmit={handleSubmitHours} max={editMode === "add" ? maxDeadlineIncrease : maxDeadlineDecrease} />
<EditHours
handleSubmit={handleSubmitHours}
max={
editMode === "add" ? maxDeadlineIncrease : maxDeadlineDecrease
}
/>
</Maybe>
</Maybe>
</Stack>
Expand Down Expand Up @@ -226,12 +236,16 @@ const useStyles = makeStyles<Theme, StyleProps>((theme) => ({
addButton: {
borderRadius: theme.shape.borderRadius,
border: ({ editMode }) =>
editMode === "add" ? `2px solid ${theme.palette.primary.main}` : "2px solid transparent",
editMode === "add"
? `2px solid ${theme.palette.primary.main}`
: "2px solid transparent",
},
subtractButton: {
borderRadius: theme.shape.borderRadius,
border: ({ editMode }) =>
editMode === "subtract" ? `2px solid ${theme.palette.primary.main}` : "2px solid transparent"
editMode === "subtract"
? `2px solid ${theme.palette.primary.main}`
: "2px solid transparent",
},
popoverPaper: {
padding: `${theme.spacing(2)}px ${theme.spacing(3)}px ${theme.spacing(
Expand Down
18 changes: 15 additions & 3 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import dayjs from "dayjs"
import { useContext } from "react"
import { Helmet } from "react-helmet-async"
import { useTranslation } from "react-i18next"
import { getMaxDeadline, getMaxDeadlineChange, getMinDeadline } from "util/schedule"
import {
getMaxDeadline,
getMaxDeadlineChange,
getMinDeadline,
} from "util/schedule"
import { selectFeatureVisibility } from "xServices/entitlements/entitlementsSelectors"
import { StateFrom } from "xstate"
import { DeleteDialog } from "../../components/Dialogs/DeleteDialog/DeleteDialog"
Expand Down Expand Up @@ -98,8 +102,16 @@ export const WorkspaceReadyPage = ({
},
deadlineMinusEnabled: () => !bannerState.matches("atMinDeadline"),
deadlinePlusEnabled: () => !bannerState.matches("atMaxDeadline"),
maxDeadlineDecrease: deadline ? getMaxDeadlineChange(deadline, getMinDeadline()) : 0,
maxDeadlineIncrease: (deadline && template) ? getMaxDeadlineChange(getMaxDeadline(workspace, template), deadline) : 0
maxDeadlineDecrease: deadline
? getMaxDeadlineChange(deadline, getMinDeadline())
: 0,
maxDeadlineIncrease:
deadline && template
? getMaxDeadlineChange(
getMaxDeadline(workspace, template),
deadline,
)
: 0,
}}
629A isUpdating={workspaceState.hasTag("updating")}
workspace={workspace}
Expand Down
7 changes: 4 additions & 3 deletions site/src/util/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const getDeadline = (workspace: Workspace): dayjs.Dayjs =>
* @param template
* @returns number, in hours
*/
export const getMaxDeadlineChange = (deadline: dayjs.Dayjs, extremeDeadline: dayjs.Dayjs): number => (
Math.abs(deadline.diff(extremeDeadline, "hours"))
)
export const getMaxDeadlineChange = (
deadline: dayjs.Dayjs,
extremeDeadline: dayjs.Dayjs,
): number => Math.abs(deadline.diff(extremeDeadline, "hours"))
0