Skip to content

Commit 8bd86e8

Browse files
committed
Fix filters for multiselects
1 parent 662dae5 commit 8bd86e8

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/app/conf/2025/schedule/_components/filters.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface FilterCategoryConfig {
2121
property: keyof ScheduleSession
2222
label: string
2323
options: string[]
24-
enabledOptions?: Set<string>
24+
enabledOptions?: Set<string> | null
2525
}
2626

2727
export const FilterCategoryConfig = {
@@ -56,7 +56,7 @@ export const FilterStates = {
5656
type FiltersProps = {
5757
categories: FilterCategoryConfig[]
5858
filterState: Record<string, string[]>
59-
enabledOptions: Record<string, Set<string>>
59+
enabledOptions: Record<string, Set<string> | null> | null
6060
onFilterChange: (category: string, newSelectedOptions: string[]) => void
6161
}
6262

@@ -195,7 +195,7 @@ function FiltersCombobox({
195195
<ComboboxOption
196196
key={option}
197197
value={option}
198-
disabled={!enabledOptions.has(option)}
198+
disabled={enabledOptions && !enabledOptions.has(option)}
199199
>
200200
{({ active, selected }) => (
201201
<FilterComboboxOption

src/app/conf/2025/schedule/_components/schedule-list.tsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ function getSessionsByDay(
3232

3333
const states = Object.entries<FilterStates[keyof FilterStates]>(filterStates)
3434
const concurrentSessions: ConcurrentSessions = {}
35-
const flatFilteredSessions: ScheduleSession[] = []
3635

3736
filteredSortedSchedule.forEach(session => {
3837
for (const [property, filterState] of states) {
@@ -47,7 +46,6 @@ function getSessionsByDay(
4746
}
4847
}
4948

50-
flatFilteredSessions.push(session)
5149
;(concurrentSessions[session.event_start] ||= []).push(session)
5250
})
5351

@@ -68,14 +66,37 @@ function getSessionsByDay(
6866
return {
6967
sessionsByDay,
7068
enabledOptions: Object.fromEntries(
71-
Object.keys(filterStates).map(field => [
72-
field,
73-
new Set(
74-
flatFilteredSessions.map(session =>
75-
String(session[field as keyof ScheduleSession]),
76-
),
77-
),
78-
]),
69+
Object.keys(filterStates).map(currentField => {
70+
// Apply filters from ALL OTHER fields, not this one
71+
const otherFilters = Object.entries(filterStates).filter(
72+
([field]) => field !== currentField,
73+
)
74+
75+
const filteredData = scheduleData.filter(session => {
76+
// Check if session passes all OTHER filters
77+
for (const [property, filterState] of otherFilters) {
78+
const filters = filterState as string[]
79+
if (
80+
filters &&
81+
filters.length > 0 &&
82+
!filters.includes(
83+
session[property as keyof ScheduleSession] as string,
84+
)
85+
) {
86+
return false
87+
}
88+
}
89+
return true
90+
})
91+
92+
const enabledOptionsForField = new Set(
93+
filteredData
94+
.map(session => session[currentField as keyof ScheduleSession])
95+
.filter((x): x is string => !!x && typeof x === "string"),
96+
)
97+
98+
return [currentField, enabledOptionsForField]
99+
}),
79100
),
80101
}
81102
}

0 commit comments

Comments
 (0)