openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

feat(notifications): filter alerts by category

Open obchain opened this issue 5 months ago • 1 comments

Summary

  • Adds a category filter to the Notifications system-events list — a chip row above the feed lets you narrow alerts to one category.
  • An All chip (default) plus one chip per category actually present in the feed; selecting one filters the list live, All clears it.
  • Only categories present in the feed get a chip — no dead chips for empty categories.
  • Chip labels reuse the existing notifications.category.* keys; one new key (notifications.filterAll) added across all 14 locales.

Problem

Every notification already carries a category (messages, agents, skills, system, meetings, reminders, important) and renders it as a badge, but there was no way to filter by it. A long mixed feed is hard to triage.

Solution

  • New selectedCategory state in Notifications.tsx, mirroring the Skills page's existing filter pattern.
  • presentCategories derives the chip set from the current items so absent categories never get a chip; if the active category drains out of the feed the filter falls back to All.
  • The filter row hides entirely when there are no notifications.
  • Chips expose aria-pressed for accessibility.
  • Scope notes: the filter applies to the system-events list (not the integration notification center); Mark-all-read / Clear continue to act on the whole feed, not the filtered view.

Submission Checklist

  • [x] Tests added or updated (happy path + at least one failure / edge case) — 5 new tests in Notifications.test.tsx cover chip render, present-only chips, filter-to-category, restore-to-All, and the empty-feed (no filter row) case.
  • [x] Diff coverage ≥ 80% — the changed Notifications.tsx logic (chip render + filter) is exercised by the new tests.
  • [x] Coverage matrix updated — N/A: frontend UI affordance on an existing page; no new tracked feature ID.
  • [x] All affected feature IDs from the matrix are listed under ## Related — N/A: no matrix feature IDs touched.
  • [x] No new external network dependencies introduced — N/A: frontend-only, no network calls added.
  • [x] Manual smoke checklist updated if this touches release-cut surfaces — N/A: not a release-cut surface.
  • [x] Linked issue closed via Closes #NNN in the ## Related section.

Impact

  • Desktop UI only. No backend/RPC, schema, or migration changes. No performance or security impact.

Related

  • Closes: #3715
  • Follow-up PR(s)/TODOs: none

AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: feat/notifications-category-filter

Summary by CodeRabbit

  • New Features
    • Notifications can now be filtered by category with an "All" filter option
    • Category filter controls displayed as interactive chips when notifications are available
    • Multi-language support added for the notifications filter feature across 14 languages

obchain avatar Jun 16 '26 12:06 obchain

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9d3a969f-64d8-4e30-922a-9c8bb6d57bc9

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8f3636623fbb20ac885ee382bd2eab74857cbe and bcb214eb2678f245f5aab0e4a696090f4b5c5837.

📒 Files selected for processing (2)
  • app/src/pages/Notifications.tsx
  • app/src/pages/__tests__/Notifications.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src/pages/Notifications.tsx

📝 Walkthrough

Walkthrough

The Notifications page gains category-based chip filtering. A CategoryFilter type and CATEGORY_ORDER array are introduced, along with selectedCategory state, derived presentCategories, an activeCategory fallback, and memoized filteredItems. The chip row renders conditionally with "all" and per-present-category chips. The notifications.filterAll i18n key is added across 13 locale files, and comprehensive tests cover chip rendering, filtering behavior, aria-pressed state, and empty-feed handling.

Changes

Notifications Category Filter

Layer / File(s) Summary
Category filter types and state foundation
app/src/pages/Notifications.tsx
Defines CATEGORY_ORDER array to establish canonical chip ordering and introduces CategoryFilter type alias (`NotificationCategory
Filter state, derivation, and list memoization
app/src/pages/Notifications.tsx
Introduces selectedCategory state, derives presentCategories from the current notification feed, computes activeCategory with fallback to 'all' when the selection becomes unavailable, triggers useEffect to reset the stored selection when fallback activates, and memoizes filteredItems based on active category selection.
Chip row rendering and filtered list display
app/src/pages/Notifications.tsx
Conditionally renders a category chip row (hidden when feed is empty) with "all" chip and per-present-category chips, each with data-testid and aria-pressed attributes; switches list iteration from items to filteredItems; updates empty-state rendering to key off filtered results length and active category instead of total items.
Category filter test coverage
app/src/pages/__tests__/Notifications.test.tsx
Extends test suite with imports for act, notificationReceived, and notification types; adds comprehensive tests for chip rendering rules (only present categories), default "All" filter state and aria-pressed, category selection filtering and state toggling, empty-feed filter row hiding, correct empty-state messaging, and state transition where stale category selection clears when that category drains from the feed.
notifications.filterAll i18n translations (13 locales)
app/src/lib/i18n/en.ts, app/src/lib/i18n/ar.ts, app/src/lib/i18n/bn.ts, app/src/lib/i18n/de.ts, app/src/lib/i18n/fr.ts, app/src/lib/i18n/hi.ts, app/src/lib/i18n/id.ts, app/src/lib/i18n/it.ts, app/src/lib/i18n/ko.ts, app/src/lib/i18n/pl.ts, app/src/lib/i18n/pt.ts, app/src/lib/i18n/ru.ts, app/src/lib/i18n/zh-CN.ts
Adds the notifications.filterAll translation entry to each locale's messages map (e.g., "All", "Alle", "Todas", "Tout", "Tutte", "全部", etc.); most locales also add notifications.filterEmpty for category-empty state messaging.

Sequence Diagram

sequenceDiagram
  participant User
  participant ChipRow as Chip Row UI
  participant NotificationsPage as Notifications Page
  participant NotificationsFeed as Notifications Feed

  NotificationsPage->>NotificationsFeed: read items
  NotificationsPage->>NotificationsPage: derive presentCategories from items
  NotificationsPage->>NotificationsPage: compute activeCategory (fallback to 'all')
  NotificationsPage->>NotificationsPage: memoize filteredItems from activeCategory
  
  alt Categories present in feed
    NotificationsPage->>ChipRow: render "all" chip + per-category chips
    User->>ChipRow: click category chip
    ChipRow->>NotificationsPage: setSelectedCategory
    NotificationsPage->>NotificationsPage: activeCategory updates, filteredItems recomputed
    NotificationsPage->>NotificationsPage: render filtered list with aria-pressed states
  else No notifications
    NotificationsPage-->>ChipRow: hide filter row entirely
    NotificationsPage->>NotificationsPage: show empty-state message
  end

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

feature

Poem

🐇 Hippity-hop, the chips appear in a row, Tap "messages" or "agents" — watch the list flow! "All" brings them back with a wiggle of ears, Thirteen tongues say the same word, it appears. No dead chips, no clutter, just what's in the feed — A tidy notifications page is all that we need! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(notifications): filter alerts by category' clearly and concisely summarizes the main feature addition: a category filter for the notifications list.
Linked Issues check ✅ Passed The PR fully implements all acceptance criteria from issue #3715: chip row renders with All chip plus present categories, filtering works correctly, only present categories get chips, i18n keys are added across 14 locales, and comprehensive unit tests cover chip rendering and filter behavior.
Out of Scope Changes check ✅ Passed All changes are directly in scope: localization files add the new notifications.filterAll and notifications.filterEmpty keys; Notifications.tsx implements the category filter UI and state management; tests provide comprehensive coverage of the new functionality.

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


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[bot] avatar Jun 16 '26 12:06 coderabbitai[bot]

I addressed the remaining stale-category review thread in a helper PR because direct push to the head fork returned 403: https://github.com/obchain/openhuman/pull/1

What changed:

  • reset the stored category filter back to All when the selected category leaves the feed
  • added a regression test proving Messages does not silently become active again if it later reappears

Local validation:

  • pnpm --filter openhuman-app exec eslint src/pages/Notifications.tsx src/pages/tests/Notifications.test.tsx
  • pnpm --filter openhuman-app exec prettier --check src/pages/Notifications.tsx src/pages/tests/Notifications.test.tsx
  • pnpm --filter openhuman-app exec vitest run --config test/vitest.config.ts src/pages/tests/Notifications.test.tsx --reporter=verbose

I also checked the current failing Rust Tauri Coverage (cargo-llvm-cov) job. The GitHub job metadata shows it failed while/after starting Run cargo llvm-cov for Tauri shell, but the downloadable log ends before that command emits an error, so there is no actionable Rust stack in the log I can fix from this branch.

Felyx-Fu avatar Jun 17 '26 10:06 Felyx-Fu

Added the category-fallback test in bcb214eb (falls back to All and forgets the selection when the active category drains, even if it reappears). Covers both the fallback render and the stored-selection reset. 11/11 in the suite pass.

obchain avatar Jun 18 '26 05:06 obchain

@coderabbitai can you please review and approve

oxoxDev avatar Jun 25 '26 09:06 oxoxDev

@oxoxDev Reviewed the latest updates — the stale category selection reset and the regression coverage for the drain/reappear case address my remaining concern. This looks good to approve.

✅ Action performed

Comments resolved and changes approved.


Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Jun 25 '26 09:06 coderabbitai[bot]