Skip to content

feat: implement feature-filtered sidebar navigation#1403

Merged
bjcoombs merged 3 commits intodevelopfrom
034-frontend-alignment--18--feature-sidebar
Mar 4, 2026
Merged

feat: implement feature-filtered sidebar navigation#1403
bjcoombs merged 3 commits intodevelopfrom
034-frontend-alignment--18--feature-sidebar

Conversation

@bjcoombs
Copy link
Copy Markdown
Collaborator

@bjcoombs bjcoombs commented Mar 4, 2026

Summary

  • Adds feature?: string field to NavItem interface in sidebar component
  • Imports useTenantFeatures hook and useTenantContext to filter navigation items
  • Platform admins (isPlatformAdmin) bypass feature filtering and always see all items
  • Items without a feature field (Transactions) are always visible
  • Maps all TENANT_NAV_ITEMS to their corresponding feature IDs from ALL_FEATURES

Changes Made

frontend/src/components/layout/sidebar.tsx

  • Added feature?: string to NavItem interface
  • Added feature annotations to all TENANT_NAV_ITEMS (Transactions has no feature — always shown)
  • Imported useTenantFeatures and useTenantContext
  • Added visibleTenantItems computed list that filters by enabled features with admin bypass

frontend/src/components/layout/sidebar.test.tsx

  • Added vi.mock for @/contexts/tenant-context and @/hooks/use-tenant-features
  • Added makeContext and makeFeatures test helpers
  • Updated beforeEach to set up default mocks (all features enabled, non-admin)
  • Added feature filtering describe block with 4 new test cases:
    • Hides items when feature is disabled
    • Always shows items without a feature field (Transactions)
    • Platform admin sees all items regardless of enabled features
    • Tenant user only sees enabled feature items

Technical Details

Feature-to-nav-item mapping follows ALL_FEATURES from tenant-ui-config.ts:

  • sagas → Starlark Config
  • mappings → Gateway Mappings
  • audit → Audit Log
  • All others map directly by name

Feature visibility is UX-only; backend RBAC enforces authorization.

Test plan

  • All 17 sidebar tests pass
  • TypeScript typecheck clean
  • Existing test cases preserved (no regressions)
  • New feature filtering tests cover: disable by feature, always-visible items, admin bypass, tenant filtering

Add `feature` field to NavItem interface and filter TENANT_NAV_ITEMS
based on enabled features from useTenantFeatures hook. Platform admins
bypass the filter and always see all items. Items without a feature
field (Transactions) are always visible.

Update sidebar tests with mocked tenant context and feature hook,
adding coverage for feature filtering, admin bypass, and always-visible
items.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e9fb27d3-1a71-49f5-9496-d1953945d264

📥 Commits

Reviewing files that changed from the base of the PR and between 496d4c0 and 600bf81.

📒 Files selected for processing (1)
  • frontend/src/test/navigation.a11y.test.tsx

📝 Walkthrough

Walkthrough

Feature-based visibility filtering is added to the Sidebar component: NavItem gained an optional feature property and tenant nav items are filtered based on tenant feature flags and user role. Tests were expanded to mock tenant context/features and validate filtering across roles; test helpers updated to use renderWithProviders.

Changes

Cohort / File(s) Summary
Feature-gated Navigation
frontend/src/components/layout/sidebar.tsx
Adds optional feature?: string to NavItem. Sidebar computes visibleTenantItems by filtering TENANT_NAV_ITEMS: items without feature always show; items with feature show if user is platform admin or if isFeatureEnabled(feature) is true. Rendering iterates visibleTenantItems.
Sidebar Test Coverage
frontend/src/components/layout/sidebar.test.tsx
Introduces mocks for useTenantContext and useTenantFeatures, with factory helpers (makeContext, makeFeatures) and beforeEach reset. Wraps render in MemoryRouter. Adds "feature filtering" test group covering hidden items when features disabled, items without feature always visible, platform admin visibility, and tenant-user visibility; expands expectations for platform/tenant lens links.
Test helper update & manifest
frontend/src/test/navigation.a11y.test.tsx, package.json
Tests switched from render to renderWithProviders import/use in accessibility test. Small manifest change recorded in package.json (test helper import adjustments).

Sequence Diagram

sequenceDiagram
    participant Sidebar as Sidebar Component
    participant TC as useTenantContext
    participant TF as useTenantFeatures
    participant Filter as Feature Filter Logic
    participant Render as Render Engine

    Sidebar->>TC: request user role / tenant lens
    TC-->>Sidebar: returns role (platform admin / tenant user)

    Sidebar->>TF: request enabled features
    TF-->>Sidebar: returns enabled feature list

    Sidebar->>Filter: apply filter to TENANT_NAV_ITEMS
    Note over Filter: For each nav item
    alt item has no `feature`
        Filter-->>Filter: include
    else item has `feature`
        alt user is platform admin
            Filter-->>Filter: include
        else user is tenant user
            alt feature in enabled list
                Filter-->>Filter: include
            else
                Filter-->>Filter: exclude
            end
        end
    end

    Filter-->>Sidebar: visibleTenantItems
    Sidebar->>Render: render visibleTenantItems + platform items
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: implement feature-filtered sidebar navigation' clearly and concisely summarizes the main change: adding feature-based filtering to the sidebar navigation component.
Description check ✅ Passed The description is well-structured and directly relates to the changeset, providing clear details about feature filtering implementation, changes to both component and test files, and technical rationale.

✏️ 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 034-frontend-alignment--18--feature-sidebar

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

@claude
Copy link
Copy Markdown

claude Bot commented Mar 4, 2026

Claude Code Review

Commit: 600bf81 | CI: running (lints pass, build/tests/frontend pending)

Summary

Clean, well-scoped implementation across 3 commits. Feature IDs in TENANT_NAV_ITEMS all match entries in ALL_FEATURES from tenant-ui-config.ts. The filtering logic is simple and correct: no-feature items pass through, platform admins bypass, everyone else checks isFeatureEnabled. Tests cover all four filtering scenarios with proper mocks. The third commit correctly wraps the a11y test in renderWithProviders to supply the TenantProvider that useTenantContext now requires.

The PR description correctly notes this is UX-only — backend RBAC is the authorization boundary. The sidebar just hides navigation; direct URL access would still be blocked server-side.

Risk Assessment

Area Level Detail
Blast radius Low Single component, UX-only filtering
Rollback Safe No data changes, revert restores old sidebar
Scale N/A Static filtering, no API calls added
Cross-system Low Reads from existing tenant context and features hook
Migration N/A No migrations

Findings

No issues found. Verified:

  • All 17 feature IDs in TENANT_NAV_ITEMS map to valid ALL_FEATURES entries (including the non-obvious mappings: sagas → Starlark Config, mappings → Gateway Mappings, audit → Audit Log)
  • Transactions is intentionally the only item without a feature field — always visible
  • useTenantFeatures falls back to DEFAULT_UI_CONFIG (all features enabled) when no tenant config exists, preventing blank sidebars on initial load
  • Hooks are called unconditionally (React rules of hooks compliance)
  • navigation.a11y.test.tsx correctly updated to use renderWithProviders since Sidebar now depends on TenantProvider via useTenantContext
  • Unit test mocks (vi.mock) in sidebar.test.tsx correctly bypass the provider requirement by mocking at the module level
  • tenantConfig property omitted from makeContext mock is safe — useTenantFeatures handles undefined config via DEFAULT_UI_CONFIG fallback

Bot Review Notes

No unresolved bot threads found at time of review. CodeRabbit review was still in progress.

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Clean implementation. Feature filtering logic is correct, feature IDs match ALL_FEATURES, admin bypass and always-visible items work as expected. Tests are thorough. See summary comment for details.

bjcoombs added 2 commits March 4, 2026 16:13
The Sidebar now uses useTenantFeatures which depends on TenantContext.
Update renderSidebar to use renderWithProviders from test-utils to
supply the required provider tree.
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Clean implementation. Feature filtering logic is correct, feature IDs all map to valid ALL_FEATURES entries, and test coverage is thorough. See summary comment for full details.

@bjcoombs bjcoombs merged commit 2aff3bd into develop Mar 4, 2026
45 of 46 checks passed
@bjcoombs bjcoombs deleted the 034-frontend-alignment--18--feature-sidebar branch March 4, 2026 17:11
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