Skip to content
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

ui: fix edit empy temp sched bug #4019

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 3 additions & 6 deletions web/src/app/schedules/ScheduleOverrideDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function ScheduleOverrideDialog(props) {
removeUserID: '',
start: DateTime.local().startOf('hour').toISO(),
end: DateTime.local().startOf('hour').plus({ hours: 8 }).toISO(),
...props.defaultValue,
...(props?.defaultValue ?? {}),
}

const [step, setStep] = useState(0)
Expand Down Expand Up @@ -146,15 +146,12 @@ export default function ScheduleOverrideDialog(props) {
if (!result.error) props.onClose()
})
}
onNext={step < 1 ? onNext : null}
disableSubmit={step === 0}
onNext={onNext}
/>
)
}

ScheduleOverrideDialog.defaultProps = {
defaultValue: {},
}

ScheduleOverrideDialog.propTypes = {
scheduleID: p.string.isRequired,
onClose: p.func,
Expand Down
10 changes: 8 additions & 2 deletions web/src/app/schedules/temp-sched/TempSchedDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ export default function TempSchedDialog({
let defaultShiftDur = {} as DurationValues

const getDurValues = (dur: Duration): DurationValues => {
if (!dur) return { ivl: 'days', dur: 1 }
if (dur.hours < 24 && dur.days < 1)
return { ivl: 'hours', dur: Math.ceil(dur.hours) }
if (dur.days < 7) return { ivl: 'days', dur: Math.ceil(dur.days) }

return { ivl: 'weeks', dur: Math.ceil(dur.weeks) }
}

if (edit) {
if (edit && _value.shifts.length > 0) {
// if editing infer shift duration
defaultShiftDur = getDurValues(inferDuration(_value.shifts))
} else {
Expand Down Expand Up @@ -199,6 +201,8 @@ export default function TempSchedDialog({

const hasCoverageGaps = (() => {
if (q.loading) return false
if (!value.shifts || value.shifts.length === 0) return true

const schedInterval = parseInterval(value, zone)
return (
getCoverageGapItems(
Expand Down Expand Up @@ -288,7 +292,9 @@ export default function TempSchedDialog({
title={edit ? 'Edit a Temporary Schedule' : 'Define a Temporary Schedule'}
onClose={onClose}
onSubmit={handleSubmit}
onNext={edit && !submitSuccess ? handleNext : null}
disableSubmit={edit && !submitSuccess}
onNext={edit ? handleNext : null}
disableNext={edit && submitSuccess}
onBack={edit && submitSuccess ? handleBack : null}
loading={fetching}
errors={errs}
Expand Down
14 changes: 7 additions & 7 deletions web/src/app/util/FilterContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const useStyles = makeStyles((theme) => {
export default function FilterContainer(props) {
const classes = useStyles()
const [anchorEl, setAnchorEl] = useState(null)
const {
icon = <FilterIcon />,
title = 'Filter',
iconButtonProps,
anchorRef,
} = props

function renderContent() {
return (
Expand Down Expand Up @@ -61,12 +67,11 @@ export default function FilterContainer(props) {
)
}

const { icon, iconButtonProps, anchorRef } = props
return (
<React.Fragment>
<IconButton
onClick={(e) => setAnchorEl(anchorRef ? anchorRef.current : e.target)}
title={props.title}
title={title}
aria-expanded={Boolean(anchorEl)}
{...iconButtonProps}
size='large'
Expand Down Expand Up @@ -120,8 +125,3 @@ FilterContainer.propTypes = {
anchorRef: p.object,
children: p.node,
}

FilterContainer.defaultProps = {
icon: <FilterIcon />,
title: 'Filter',
}
Loading