Skip to content

Restore category search filter using Gutenberg components#80

Merged
kraftbj merged 7 commits intotrunkfrom
fix-issue-73
Mar 6, 2026
Merged

Restore category search filter using Gutenberg components#80
kraftbj merged 7 commits intotrunkfrom
fix-issue-73

Conversation

@kraftbj
Copy link
Collaborator

@kraftbj kraftbj commented Feb 27, 2026

Summary

  • Restores the category search/filter that was lost during the Gutenberg modernization, using native @wordpress/components primitives (SearchControl, CheckboxControl, TreeSelect)
  • Extracts all category UI into a dedicated CategoryPanel component, reducing PressThisEditor.js by ~250 lines
  • Categories now render hierarchically (indented tree) with tree-aware filtering that preserves parent context when a child matches

Details

The old jQuery-based Press This had a .categories-search input above the category list (assets/press-this.js:842-863). During the Gutenberg modernization (354ccf3), this was not ported to the new React-based editor.

New files

  • src/utils/terms.jsbuildTermsTree() and getFilterMatcher() ported from @wordpress/editor (pure functions, no store dependencies)
  • src/components/CategoryPanel.js — self-contained category panel component
  • tests/utils/terms.test.js — 16 tests covering tree building and filtering

Changed files

  • src/components/PressThisEditor.js — inline category state/logic replaced with <CategoryPanel />
  • src/styles/main.scss — removed duplicate inline category styles
  • src/styles/partials/_categories-panel.scss — simplified for CheckboxControl markup and hierarchical indentation
  • package.json — added @wordpress/a11y and @wordpress/html-entities as direct dependencies

Behavior

  • Search input only appears when there are 8+ categories (matches Gutenberg's MIN_TERMS_COUNT_FOR_FILTER)
  • Filtering is case-insensitive and preserves parent path when a child matches
  • Screen reader announcements via speak() from @wordpress/a11y
  • Parent category dropdown in "Add New" form uses TreeSelect for native hierarchy display
  • Save flow and Add New Category AJAX are unchanged

Test plan

  • Build passes (npm run build)
  • Lint passes (npm run lint)
  • All 126 tests pass (npm run test:js) — 16 new tests for term utilities
  • Open Press This, expand Categories panel — categories display hierarchically
  • Type in search to filter; parent categories preserved when child matches
  • Clear search with X button; full list returns
  • Select/deselect categories, save post, verify correct categories saved
  • Add New Category: parent dropdown shows hierarchy via TreeSelect
  • Create a new category, verify it appears in the list and is auto-selected
  • With fewer than 8 categories, search input should not appear

Fixes #73

The Gutenberg modernization removed the category search/filter that
existed in the old jQuery-based Press This. This restores it using
native Gutenberg component primitives (SearchControl, CheckboxControl,
TreeSelect) with hierarchical tree rendering and tree-aware filtering.

Extracts category UI into a dedicated CategoryPanel component, reducing
PressThisEditor.js by ~250 lines. Adds buildTermsTree and
getFilterMatcher utilities ported from @wordpress/editor.

Fixes #73
Copy link
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

Restores the lost Press This category search/filter experience using Gutenberg component primitives by extracting category UI/logic into a dedicated React component and adding reusable term tree utilities + tests.

Changes:

  • Added CategoryPanel component implementing hierarchical category rendering, filtering, and “Add New Category” UI.
  • Added pure terms utilities for building/filtering a term tree (ported from Gutenberg), with accompanying unit tests.
  • Updated editor + styles and added direct dependencies for a11y announcements and HTML entity decoding.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/components/PressThisEditor.js Replaces inline categories UI/state with <CategoryPanel /> integration.
src/components/CategoryPanel.js New hierarchical categories panel with search/filter, a11y speak, and add-category flow.
src/utils/terms.js New pure utilities for term tree building, filtering, and HTML entity decoding.
tests/utils/terms.test.js New unit tests covering term tree building/filtering and entity decoding.
src/styles/main.scss Removes old inline category styles (intended to defer to CategoryPanel styling).
src/styles/partials/_categories-panel.scss Updates styles for Gutenberg controls + hierarchical indentation.
package.json Adds @wordpress/a11y and @wordpress/html-entities direct dependencies.
package-lock.json Locks new direct dependencies and related WordPress package versions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kraftbj kraftbj added this to the 2.0.2 milestone Feb 27, 2026
- Import _categories-panel.scss partial in main.scss so its styles
  are included in the built CSS.
- Add @use "variables" to the partial, matching all other partials.
- Derive filteredTermsTree via useMemo instead of state so filtered
  results stay in sync when categories change mid-filter.
Copy link
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

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

kraftbj added 2 commits March 6, 2026 18:02
- Replace setFilter callback with a useEffect that announces screen
  reader results from the already-derived filteredTermsTree, avoiding
  redundant filtering on every keystroke.
- Update JSDoc for onSelectionChange/onCategoriesChange to reflect
  that they are React setState dispatchers accepting updater functions.
Copy link
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

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Use the functional form of onSelectionChange so rapid toggles
under React state batching compose correctly instead of reading
a potentially stale selectedCategories from the closure.
Copy link
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

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The fallback list in get_script_dependencies() was missing several
handles (wp-a11y, wp-block-library, wp-dom-ready, wp-format-library,
wp-html-entities, wp-primitives, react-jsx-runtime) and included
wp-rich-text which is no longer a direct dependency. Synced with
the authoritative build/press-this-editor.asset.php output.

Also adds CLAUDE.md with a maintenance reminder to keep the
fallback list in sync when @wordpress/* imports change.
Copy link
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

Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kraftbj kraftbj merged commit e4f05a6 into trunk Mar 6, 2026
10 checks passed
@kraftbj kraftbj deleted the fix-issue-73 branch March 6, 2026 17:43
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.

Can no longer filter categories

2 participants