refactor: consolidate 7 filter props into single _filters object#42
Merged
mekarpeles merged 2 commits intomainfrom Apr 27, 2026
Merged
refactor: consolidate 7 filter props into single _filters object#42mekarpeles merged 2 commits intomainfrom
mekarpeles merged 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors ol-search-page to consolidate filter state from seven Lit reactive properties into a single _filters reactive object, simplifying update/watch logic and reducing repeated per-filter assignment code.
Changes:
- Replaces seven individual reactive filter props with one
_filtersstate object initialized fromDEFAULT_FILTERS - Removes
_filters/_chipsgetters and computes chips inline viabuildChips(this._filters) - Adds static-analysis contract tests to enforce the new filter-object patterns
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| frontend/src/components/ol-search-page.js | Consolidates filter state into _filters, updates mutation sites, and simplifies updated() broadcasting |
| frontend/src/components/ol-search-page.filter-object.test.js | Adds static-analysis tests asserting the consolidated filter-object contract |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mekarpeles
added a commit
that referenced
this pull request
Apr 26, 2026
- updated() now dispatches a defensive copy of _filters (with array
fields spread) so external ol-app-state listeners cannot mutate
internal Lit reactive state
- _onFilterChange and _rfApply now guard against unknown filter keys
via FILTER_KEYS (derived from DEFAULT_FILTERS) — silently ignores
any key not in the canonical set
- _onSearch uses { ...DEFAULT_FILTERS, ...f, <arrays spread> } to
avoid duplicating the schema and automatically handle future fields
- Test slice for updated() widened from 300→600 chars; FILTER_KEYS
guard tests added
…l-search-page
Replaces the seven individual reactive properties (_sort, _availability,
_fictionFilter, _languages, _genres, _authors, _subjects) with a single
_filters: { state: true } property initialised from DEFAULT_FILTERS.
Every mutation site now uses a single spread assignment instead of a
switch-with-7-cases, making filter changes O(1) lines to write and
impossible to partially update:
_onFilterChange: { ...this._filters, [filter]: value }
_rfApply: { ...this._filters, [filter]: value }
_onClearAllFilters: { ...DEFAULT_FILTERS }
_onChipRemove: { ...f, ...update } (derived from chip type)
The get _filters() and get _chips() computed getters are removed;
callers use this._filters directly and buildChips(this._filters) inline.
updated() now watches ['_lastQ', '_filters'] instead of 8 properties.
Closes #37. 13 static-analysis tests added.
- updated() now dispatches a defensive copy of _filters (with array
fields spread) so external ol-app-state listeners cannot mutate
internal Lit reactive state
- _onFilterChange and _rfApply now guard against unknown filter keys
via FILTER_KEYS (derived from DEFAULT_FILTERS) — silently ignores
any key not in the canonical set
- _onSearch uses { ...DEFAULT_FILTERS, ...f, <arrays spread> } to
avoid duplicating the schema and automatically handle future fields
- Test slice for updated() widened from 300→600 chars; FILTER_KEYS
guard tests added
c1cf264 to
3d70486
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #37
Summary
_sort,_availability,_fictionFilter,_languages,_genres,_authors,_subjects(7 individual Lit reactive properties) with a single_filters: { state: true }object initialised fromDEFAULT_FILTERSget _filters()andget _chips()computed getters —_filtersis now direct reactive state, chips are computed inline withbuildChips(this._filters)_onFilterChangeand_rfApplyuse{ ...this._filters, [filter]: value };_onClearAllFiltersuses{ ...DEFAULT_FILTERS }updated()now watches two properties (_lastQ,_filters) instead of eightTest plan
ol-search-page.filter-object.test.jscovering:_filtersdeclared as reactive state, 7 individual props not declared, constructor initialisation, no getter methods, spread mutation patterns,updated()watches_filters,buildChipscalled inline