-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: do not re-render entire time slot page when slot changes
- Loading branch information
1 parent
b4fb2be
commit d3d1242
Showing
10 changed files
with
360 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ClearAll } from '@mui/icons-material'; | ||
import { Button } from '@mui/material'; | ||
|
||
type Props = { | ||
fields: { id: string }[]; | ||
remove: () => void; | ||
}; | ||
|
||
export const ClearSlotsButton = ({ fields, remove }: Props) => { | ||
return ( | ||
fields.length > 0 && ( | ||
<Button onClick={() => remove()} sx={{ mr: 1 }} startIcon={<ClearAll />}> | ||
Clear All | ||
</Button> | ||
) | ||
); | ||
}; |
65 changes: 65 additions & 0 deletions
65
web/src/components/slot_scheduler/MissingProgramsAlert.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { slotOptionIsScheduled } from '@/helpers/slotSchedulerUtil'; | ||
import { useSlotProgramOptions } from '@/hooks/programming_controls/useSlotProgramOptions'; | ||
import { TimeSlotForm } from '@/pages/channels/TimeSlotEditorPage'; | ||
import { ExpandLess, ExpandMore } from '@mui/icons-material'; | ||
import { Alert, Collapse, IconButton, ListItem } from '@mui/material'; | ||
import { isEmpty, map, reject } from 'lodash-es'; | ||
import pluralize from 'pluralize'; | ||
import { useMemo } from 'react'; | ||
import { Control, useWatch } from 'react-hook-form'; | ||
import { useToggle } from 'usehooks-ts'; | ||
|
||
type Props = { | ||
control: Control<TimeSlotForm>; | ||
}; | ||
|
||
export const MissingProgramsAlert = ({ control }: Props) => { | ||
const programOptions = useSlotProgramOptions(); | ||
const currentSlots = useWatch({ control, name: 'slots' }); | ||
const [unscheduledOpen, toggleUnscheduledOpen] = useToggle(false); | ||
|
||
const unscheduledOptions = useMemo( | ||
() => | ||
reject(programOptions, (item) => | ||
slotOptionIsScheduled(currentSlots, item), | ||
), | ||
[currentSlots, programOptions], | ||
); | ||
|
||
return ( | ||
!isEmpty(unscheduledOptions) && ( | ||
<Alert | ||
severity="warning" | ||
action={ | ||
<IconButton | ||
aria-label="close" | ||
color="inherit" | ||
size="small" | ||
onClick={() => { | ||
toggleUnscheduledOpen(); | ||
}} | ||
> | ||
{!unscheduledOpen ? ( | ||
<ExpandMore fontSize="inherit" /> | ||
) : ( | ||
<ExpandLess fontSize="inherit" /> | ||
)} | ||
</IconButton> | ||
} | ||
> | ||
There are {unscheduledOptions.length} unscheduled{' '} | ||
{pluralize('program', unscheduledOptions.length)}. Unscheduled items | ||
will be removed from the channel when saving. | ||
<Collapse in={unscheduledOpen}> | ||
<> | ||
{map(unscheduledOptions, (option) => ( | ||
<ListItem key={option.value}> | ||
{option.description} ({option.type}) | ||
</ListItem> | ||
))} | ||
</> | ||
</Collapse> | ||
</Alert> | ||
) | ||
); | ||
}; |
Oops, something went wrong.