Skip to content

feat(filter): add category filter in search panel#50

Closed
AmintaCCCP wants to merge 2 commits into
mainfrom
fix/issue-39-40-category-lock
Closed

feat(filter): add category filter in search panel#50
AmintaCCCP wants to merge 2 commits into
mainfrom
fix/issue-39-40-category-lock

Conversation

@AmintaCCCP

@AmintaCCCP AmintaCCCP commented Mar 7, 2026

Copy link
Copy Markdown
Owner

Summary

Resolve #28 by adding category filter support in the filter panel.

Changes

  • Add categories to SearchFilters
  • Add category options (from default + custom categories) in SearchBar filter section
  • Add category toggle handler and include category filter in active filter count
  • Apply category filtering logic (manual custom_category matching)
  • Clear category filters in the "Clear all" action

Notes

This keeps behavior intuitive for users who manually manage categories and want category-level filtering from the filter panel.

Fixes #28

Summary by CodeRabbit

  • New Features
    • Category-based filtering added to search: a new Categories section shows available category buttons to toggle and refine results. Selections update the active filters count, can be cleared with other filters, and recompute when category or language data changes.

@coderabbitai

coderabbitai Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds category-based filtering: extends SearchFilters with categories, initializes it in app store, and updates SearchBar to compute available categories from customCategories, expose UI toggles, and apply category filters to repository search logic.

Changes

Cohort / File(s) Summary
Type Definitions
src/types/index.ts
Added categories: string[] to SearchFilters.
Store State
src/store/useAppStore.ts
Initialized categories: [] in initialSearchFilters.
SearchBar Component
src/components/SearchBar.tsx
Imported getAllCategories, read customCategories from store, derived availableCategories, added category toggle UI and handlers, integrated searchFilters.categories into filter logic and reset/count calculations.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant UI as SearchBar (UI)
    participant Store as AppStore
    participant List as RepoList

    User->>UI: Toggle category button
    UI->>Store: update local searchFilters.categories
    Store-->>UI: updated customCategories / categories (derived)
    UI->>List: applyFilters(filters including categories)
    List-->>UI: filtered repo list returned
    UI->>User: render filtered results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
Categories hop into view with glee,
I nudge the toggles, set filters free.
Tiny buttons bloom, results align—
A rabbit’s nod: the search is fine! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding category filter functionality to the search panel, which is the primary focus of the changeset.
Linked Issues check ✅ Passed The PR successfully implements category filtering in the filter panel as requested in issue #28, enabling users to filter by categories with proper toggle functionality and filter state management.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing category filtering: type definitions, store state initialization, and UI implementation are all in scope for the stated objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-39-40-category-lock

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/components/SearchBar.tsx (1)

224-232: Consider the UX impact of excluding uncategorized repositories.

When a category filter is active, repositories without a custom_category are excluded from results. This is consistent with filtering by manually-assigned categories, but users may expect repositories to also match based on their auto-detected or default category.

If this is the intended behavior (filtering only manually-categorized repos), the current implementation is correct. However, you might want to:

  1. Add a UI hint indicating the filter applies to manually-assigned categories only, or
  2. Consider a fallback to match against default category keywords if custom_category is not set
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/SearchBar.tsx` around lines 224 - 232, The current filter
using searchFilters.categories only checks repo.custom_category and thus
excludes uncategorized repos; update the filtering in the block that references
searchFilters.categories and filtered so that when repo.custom_category is falsy
you fallback to matching against an automatic/default category or keyword set
(e.g., call a helper like matchDefaultCategory(repo, searchFilters.categories)
or check repo.auto_category/default_category) so repos without custom_category
can still match, and/or add a clear UI hint near the category filter indicating
it currently applies to manually-assigned categories only (adjust the
label/tooltip for the category UI control).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/SearchBar.tsx`:
- Around line 224-232: The current filter using searchFilters.categories only
checks repo.custom_category and thus excludes uncategorized repos; update the
filtering in the block that references searchFilters.categories and filtered so
that when repo.custom_category is falsy you fallback to matching against an
automatic/default category or keyword set (e.g., call a helper like
matchDefaultCategory(repo, searchFilters.categories) or check
repo.auto_category/default_category) so repos without custom_category can still
match, and/or add a clear UI hint near the category filter indicating it
currently applies to manually-assigned categories only (adjust the label/tooltip
for the category UI control).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e616864-fcab-4fb3-bd3c-48d83bc73e5c

📥 Commits

Reviewing files that changed from the base of the PR and between a85181b and 067811f.

📒 Files selected for processing (3)
  • src/components/SearchBar.tsx
  • src/store/useAppStore.ts
  • src/types/index.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/SearchBar.tsx (1)

72-83: ⚠️ Potential issue | 🟠 Major

Re-run filtering when category metadata changes.

Line 82 reruns performSearch() for filter value changes, but applyFilters() now also depends on customCategories and language. Renaming categories, editing keywords, or switching locale leaves the current result set stale until some unrelated filter changes. Add those dependencies here, or memoize applyFilters and depend on that.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/SearchBar.tsx` around lines 72 - 83, The effect that calls
performSearch (defined inside useEffect) is missing dependencies for
customCategories and language which applyFilters now relies on; update the
dependency array of the useEffect that references performSearch to include
customCategories and language (or alternatively memoize applyFilters with
useCallback/useMemo and depend on the memoized function in the useEffect).
Ensure references to
performSearch/useEffect/searchFilters/applyFilters/customCategories/language are
updated so renaming categories, editing keywords, or changing locale triggers
performSearch().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/SearchBar.tsx`:
- Around line 47-50: The code currently stores translated category names in
available/selected filters which breaks when language changes; change
persistence to use stable IDs: keep setAvailableCategories populated with
category ids (from getAllCategories(customCategories, language).filter(cat =>
cat.id !== 'all').map(cat => cat.id)) and ensure searchFilters.categories stores
cat.id values instead of names; update applyFilters and any
selection/serialization logic to resolve Category.name only at render time by
looking up the label from getAllCategories(...) or a categoriesById map. Apply
the same change to the other occurrences noted (lines referencing
available/selected category names and applyFilters).

---

Outside diff comments:
In `@src/components/SearchBar.tsx`:
- Around line 72-83: The effect that calls performSearch (defined inside
useEffect) is missing dependencies for customCategories and language which
applyFilters now relies on; update the dependency array of the useEffect that
references performSearch to include customCategories and language (or
alternatively memoize applyFilters with useCallback/useMemo and depend on the
memoized function in the useEffect). Ensure references to
performSearch/useEffect/searchFilters/applyFilters/customCategories/language are
updated so renaming categories, editing keywords, or changing locale triggers
performSearch().

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 84dd2675-98b2-4831-8ab0-bbfed4870bd0

📥 Commits

Reviewing files that changed from the base of the PR and between 067811f and e70f3c5.

📒 Files selected for processing (1)
  • src/components/SearchBar.tsx

Comment on lines +47 to +50
const allCategories = getAllCategories(customCategories, language)
.filter(cat => cat.id !== 'all')
.map(cat => cat.name);
setAvailableCategories(allCategories);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Use stable category IDs instead of translated names.

These paths treat the display label as the persisted filter value. Once language changes, default category names change too, so the selected chips lose their active state and applyFilters() can no longer resolve the inferred category objects for the existing selection. Store cat.id in searchFilters.categories and derive the current label from Category.name only at render time.

Also applies to: 491-495, 864-882

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/SearchBar.tsx` around lines 47 - 50, The code currently stores
translated category names in available/selected filters which breaks when
language changes; change persistence to use stable IDs: keep
setAvailableCategories populated with category ids (from
getAllCategories(customCategories, language).filter(cat => cat.id !==
'all').map(cat => cat.id)) and ensure searchFilters.categories stores cat.id
values instead of names; update applyFilters and any selection/serialization
logic to resolve Category.name only at render time by looking up the label from
getAllCategories(...) or a categoriesById map. Apply the same change to the
other occurrences noted (lines referencing available/selected category names and
applyFilters).

@AmintaCCCP

Copy link
Copy Markdown
Owner Author

Closing this PR per maintainer decision: category filtering will remain in the left sidebar only to avoid duplicated/conflicting controls.

@AmintaCCCP AmintaCCCP closed this Mar 7, 2026
@AmintaCCCP AmintaCCCP deleted the fix/issue-39-40-category-lock branch April 26, 2026 09:36
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.

希望可以增加分类筛选

1 participant