Skip to content

refactor: consolidate 7 filter props into single _filters object#42

Merged
mekarpeles merged 2 commits intomainfrom
refactor/search-page-filter-object
Apr 27, 2026
Merged

refactor: consolidate 7 filter props into single _filters object#42
mekarpeles merged 2 commits intomainfrom
refactor/search-page-filter-object

Conversation

@mekarpeles
Copy link
Copy Markdown
Member

Closes #37

Summary

  • Replaces _sort, _availability, _fictionFilter, _languages, _genres, _authors, _subjects (7 individual Lit reactive properties) with a single _filters: { state: true } object initialised from DEFAULT_FILTERS
  • Removes the get _filters() and get _chips() computed getters — _filters is now direct reactive state, chips are computed inline with buildChips(this._filters)
  • All mutation sites collapse to a single spread: _onFilterChange and _rfApply use { ...this._filters, [filter]: value }; _onClearAllFilters uses { ...DEFAULT_FILTERS }
  • updated() now watches two properties (_lastQ, _filters) instead of eight

Test plan

  • 13 static-analysis tests added in ol-search-page.filter-object.test.js covering: _filters declared as reactive state, 7 individual props not declared, constructor initialisation, no getter methods, spread mutation patterns, updated() watches _filters, buildChips called inline
  • All 187 unit tests pass
  • Lint clean

Copilot AI review requested due to automatic review settings April 26, 2026 22:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _filters state object initialized from DEFAULT_FILTERS
  • Removes _filters / _chips getters and computes chips inline via buildChips(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.

Comment thread frontend/src/components/ol-search-page.js
Comment thread frontend/src/components/ol-search-page.js
Comment thread frontend/src/components/ol-search-page.js
Comment thread frontend/src/components/ol-search-page.js Outdated
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
@mekarpeles mekarpeles force-pushed the refactor/search-page-filter-object branch from c1cf264 to 3d70486 Compare April 27, 2026 00:10
@mekarpeles mekarpeles merged commit 81e1406 into main Apr 27, 2026
2 checks passed
@mekarpeles mekarpeles deleted the refactor/search-page-filter-object branch April 27, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: consolidate ol-search-page's 7 individual filter props into one _filters object

2 participants