Skip to content

Commit

Permalink
Disable 'Select All' and 'Recent' options when there are no semesters…
Browse files Browse the repository at this point in the history
… that fit each criteria
  • Loading branch information
AbhiramTadepalli committed Nov 5, 2024
1 parent cb96ad3 commit 3b60832
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/components/common/Filters/filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,12 @@ const Filters = ({
MenuProps={{ autoFocus: false }}
>
{/* select all sessions */}
<MenuItem className="h-10" value="select-all">
<MenuItem className="h-10 items-center" value="select-all">
<Checkbox
checked={chosenSessions.length === academicSessions.length}
checked={
academicSessions.length > 0 &&
chosenSessions.length === academicSessions.length
}
indeterminate={
chosenSessions.length !== academicSessions.length &&
chosenSessions.length !== 0 &&
Expand All @@ -258,24 +261,37 @@ const Filters = ({
chosenSessions.every((el) => recentSemesters.includes(el))
) // select-all is not indeterminate when recent is checked
}
disabled={academicSessions.length == 0}
/>
<ListItemText
className={academicSessions.length > 0 ? '' : 'text-gray-400'}
primary="Select All"
/>
<ListItemText primary="Select All" />
</MenuItem>

{/* recent sessions -- last <recentSemesters.length> long-semesters from current semester*/}
<MenuItem className="h-10" value="recent">
<MenuItem className="h-10 items-center" value="recent">
<Checkbox
checked={
recentSemesters.length > 0 &&
chosenSessions.length === recentSemesters.length &&
chosenSessions.every((el) => recentSemesters.includes(el))
}
disabled={recentSemesters.length == 0}
/>
<ListItemText
className={recentSemesters.length > 0 ? '' : 'text-gray-400'}
primary="Recent"
/>
<ListItemText primary="Recent" />
</MenuItem>

{/* indiv options */}
{academicSessions.map((session) => (
<MenuItem className="h-10" key={session} value={session}>
<MenuItem
className="h-10 items-center"
key={session}
value={session}
>
<Checkbox checked={chosenSessions.includes(session)} />
<ListItemText primary={displayAcademicSessionName(session)} />
</MenuItem>
Expand Down

0 comments on commit 3b60832

Please sign in to comment.