Skip to content

Commit 365ff2f

Browse files
committed
[Frontend] Filters now reset to default state (not initial) and setOptions options is now native
1 parent 4b7e875 commit 365ff2f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

services/frontend/src/components/FilterView/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const defaultFilterContext: FilterContext = {
1515
students: [],
1616
precomputed: null,
1717
options: {},
18-
args: null,
18+
args: undefined,
1919
}
2020

2121
export type FilterViewContextState = {

services/frontend/src/components/FilterView/filters/courses/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { produce } from 'immer'
21
import { keyBy } from 'lodash'
32
import { FC } from 'react'
43
import { Dropdown, type DropdownProps } from 'semantic-ui-react'
@@ -32,10 +31,13 @@ const CourseFilterCard: FC<{
3231

3332
const setCourseFilter = (code, type) =>
3433
onOptionsChange(
35-
produce(options, draft => {
36-
draft.courseFilters[code] = type
37-
if (type === null) delete draft.courseFilters[code]
38-
})
34+
(() => {
35+
const newOpts = structuredClone(options)
36+
newOpts.courseFilters[code] = type
37+
if (type === null) delete newOpts.courseFilters[code]
38+
39+
return newOpts
40+
})()
3941
)
4042

4143
const onChange: NonNullable<DropdownProps['onChange']> = (_, { value }) => {

services/frontend/src/components/FilterView/filters/createFilter.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { produce } from 'immer'
2-
31
import { ReactNode } from 'react'
42
import { setFilterOptions } from '@/redux/filters'
53
import { mapValues } from '@oodikone/shared/util'
@@ -120,7 +118,7 @@ export const createFilter = (options: FilterOptions): FilterFactory => {
120118

121119
const opt_actions: NonNullable<FilterOptions['actions']> = Object.assign(options.actions ?? {}, {
122120
setOptions: (_, value) => value,
123-
reset: (..._) => null,
121+
reset: (..._) => options.defaultOptions,
124122
})
125123

126124
/**
@@ -140,7 +138,12 @@ export const createFilter = (options: FilterOptions): FilterFactory => {
140138
view,
141139
filter: options.key,
142140
action: `${options.key}/${key}`,
143-
options: produce(ctx.options, (draft: FilterContext['options']) => action(draft, payload)),
141+
options: (() => {
142+
const newOpts = structuredClone(ctx.options)
143+
action(newOpts, payload)
144+
145+
return newOpts
146+
})(),
144147
})
145148
},
146149
]

0 commit comments

Comments
 (0)