Skip to content

feat: add active filter count badge to UniversalFilter#1753

Open
Uday9909 wants to merge 2 commits into
layer5io:masterfrom
Uday9909:feat/filter-count-badge
Open

feat: add active filter count badge to UniversalFilter#1753
Uday9909 wants to merge 2 commits into
layer5io:masterfrom
Uday9909:feat/filter-count-badge

Conversation

@Uday9909

@Uday9909 Uday9909 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Notes for Reviewers

This PR fixes #1728

Signed commits

  • Yes, I signed my commits.

Changes

File Change
src/custom/UniversalFilter.tsx +17 lines — import Badge, derive count, wrap TooltipIcon
src/__testing__/UniversalFilter.test.tsx +82 lines — Badge mock + 3 test cases

Verification

  • Tests: 463/463 passed (26 suites)
  • Lint: clean
  • Build: CJS + ESM succeed
  • Only 2 files changed
  • DCO sign-off on all commits

Summary by CodeRabbit

  • New Features

    • Added a badge to the filter control showing the number of active filters.
    • The badge remains hidden when no filters are selected.
  • Tests

    • Added coverage to verify the filter badge content and visibility state.

Wraps the filter TooltipIcon in a MUI Badge that displays the count
of active (non-'All') filter values. Badge is invisible when no
filters are active via MUI's native invisible prop.

Fixes layer5io#1728

Signed-off-by: Udaybir Singh <writetoudaybir@gmail.com>
Copilot AI review requested due to automatic review settings July 25, 2026 07:18

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f3f5c668-95f8-446a-954e-4a61a4e3522b

📥 Commits

Reviewing files that changed from the base of the PR and between 82f39f3 and c4c9724.

📒 Files selected for processing (2)
  • src/__testing__/UniversalFilter.test.tsx
  • src/custom/UniversalFilter.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/custom/UniversalFilter.tsx

📝 Walkthrough

Walkthrough

UniversalFilter now counts active selected filters and displays that count in a Badge around the filter trigger. The badge is hidden when no non-default filters are active, and tests mock Badge output for DOM assertions.

Changes

UniversalFilter active count badge

Layer / File(s) Summary
Badge count rendering
src/custom/UniversalFilter.tsx
Imports MUI Badge, counts truthy selected filter values other than 'All', and wraps the existing tooltip icon with a badge that hides when the count is zero.
Badge behavior test support
src/__testing__/UniversalFilter.test.tsx
Mocks Badge with DOM attributes exposing its content and invisible state for test assertions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: khushambansal

🚥 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 is concise and accurately describes the main UI change to UniversalFilter.
Linked Issues check ✅ Passed The badge count, hidden state, and UniversalFilter update align with issue #1728.
Out of Scope Changes check ✅ Passed The PR stays focused on UniversalFilter and its tests, with no unrelated changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/custom/UniversalFilter.tsx (1)

186-198: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a Sistent semantic token for the badge color.

color="primary" relies on MUI’s default color API rather than the project’s theme semantics. Style the badge with the appropriate Sistent semantic palette token so its applied-filter state remains theme-consistent.

As per coding guidelines, “Theme-aware UI must use Sistent theme exports and semantic palette tokens rather than raw MUI defaults.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/custom/UniversalFilter.tsx` around lines 186 - 198, Update the Badge in
the UniversalFilter component to replace the raw MUI color="primary" value with
the appropriate Sistent semantic palette token from the theme, preserving the
existing activeFilterCount visibility behavior.

Source: Coding guidelines

src/__testing__/UniversalFilter.test.tsx (1)

115-188: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test badge updates after filters are applied and cleared.

These cases mount independent initial states only. Add a controlled-parent or rerender test that changes selectedFilters from active to All (and vice versa) to verify the badge updates during the user flow required by the issue.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/__testing__/UniversalFilter.test.tsx` around lines 115 - 188, Extend the
badge tests around UniversalFilter with a rerender or controlled-parent flow
that changes selectedFilters between an active value and 'All'. Assert that
filter-badge data-content and data-invisible update correctly in both
directions, preserving the existing initial-state coverage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/__testing__/UniversalFilter.test.tsx`:
- Around line 58-65: Update the Badge mock component in UniversalFilter.test.tsx
to replace the any props annotation with an explicit React prop type covering
optional badgeContent, optional invisible, and children; preserve the mock’s
existing rendering and data attributes.

---

Nitpick comments:
In `@src/__testing__/UniversalFilter.test.tsx`:
- Around line 115-188: Extend the badge tests around UniversalFilter with a
rerender or controlled-parent flow that changes selectedFilters between an
active value and 'All'. Assert that filter-badge data-content and data-invisible
update correctly in both directions, preserving the existing initial-state
coverage.

In `@src/custom/UniversalFilter.tsx`:
- Around line 186-198: Update the Badge in the UniversalFilter component to
replace the raw MUI color="primary" value with the appropriate Sistent semantic
palette token from the theme, preserving the existing activeFilterCount
visibility behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0df0062b-85a5-4b55-95d8-89bc12b89cb2

📥 Commits

Reviewing files that changed from the base of the PR and between 846866a and 33880e5.

📒 Files selected for processing (2)
  • src/__testing__/UniversalFilter.test.tsx
  • src/custom/UniversalFilter.tsx

Comment on lines +58 to +65
jest.mock('../base/Badge', () => ({
Badge: ({ children, badgeContent, invisible }: any) => (
<div data-testid="filter-badge" data-content={badgeContent} data-invisible={String(invisible)}>
{children}
</div>
)
}));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

git ls-files src/__testing__/UniversalFilter.test.tsx
echo '---'
cat -n src/__testing__/UniversalFilter.test.tsx | sed -n '1,260p'

Repository: layer5io/sistent

Length of output: 7096


Type the Badge mock props explicitly. Replace the any here with a small prop type, such as React.PropsWithChildren<{ badgeContent?: React.ReactNode; invisible?: boolean }>.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/__testing__/UniversalFilter.test.tsx` around lines 58 - 65, Update the
Badge mock component in UniversalFilter.test.tsx to replace the any props
annotation with an explicit React prop type covering optional badgeContent,
optional invisible, and children; preserve the mock’s existing rendering and
data attributes.

Source: Coding guidelines

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

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

⚠️ Outside diff range comments (4)
src/custom/UniversalFilter.tsx (1)

244-251: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Associate the quick-range label with the Select.
InputLabel is detached from the Select, so screen readers may announce the control without its “Quick Ranges” name. Add labelId={${testId}-quick-range-label} to the Select.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/custom/UniversalFilter.tsx` around lines 244 - 251, Update the Select
associated with the quick-range InputLabel to include the matching labelId value
`${testId}-quick-range-label`, ensuring the control is programmatically named
“Quick Ranges.”
src/__testing__/publishedTypeSurfaceDependencies.test.ts (3)

95-97: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Detect side-effect imports in declaration bundles.

specifiersIn misses import 'side-effect-package';. A package referenced only this way is still required by consumers, but the current detector returns no reference and can let the dependency-contract test pass incorrectly.

Extend the matcher and add a detector fixture for side-effect imports.

Proposed fix
 const specifiersIn = (source: string): string[] => [
-  ...new Set([...source.matchAll(/(?:from|import\()\s*['"]([^'"]+)['"]/g)].map((match) => match[1]))
+  ...new Set(
+    [...source.matchAll(/\b(?:from|import(?:\s*\(\s*)?)\s*['"]([^'"]+)['"]/g)].map(
+      (match) => match[1]
+    )
+  )
 ];

Also applies to: 214-224

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/__testing__/publishedTypeSurfaceDependencies.test.ts` around lines 95 -
97, Update specifiersIn to recognize bare side-effect imports such as import
'package' in addition to from and dynamic import() forms, while preserving
extraction of the module specifier. Add a detector fixture covering a
declaration bundle containing only a side-effect import and assert that the
referenced package is detected by the dependency-contract test.

140-181: 📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Validate the published surface with a scoped tsc fixture.

This test only scans declaration text and package metadata; it never type-checks a real consumer. Add a scoped fixture, invoke tsc, verify the fixture appears in --listFiles, and filter diagnostics to that fixture so the test validates actual consumer resolution rather than only regex results.

As per coding guidelines, type-contract tests under src/__testing__/*.test.ts must use this scoped tsc verification approach.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/__testing__/publishedTypeSurfaceDependencies.test.ts` around lines 140 -
181, Extend the published type-surface test around the existing dist/index.d.ts
checks with a scoped consumer fixture that imports the package and is
type-checked via tsc. Verify the fixture is present in tsc’s --listFiles output,
filter diagnostics to the fixture, and fail on relevant resolution or type
errors while preserving the existing metadata and declaration-text assertions.

Source: Coding guidelines


66-77: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Restore the documented optional-peer exemption.

The comments state that @mui/x-date-pickers is intentionally exempted while DateTimePickerProps remains publicly re-exported, but OPTIONAL_PEERS_ON_THE_RECORD contains only react. Because optional peers are removed from the consumer-guaranteed set, this causes the suite to fail whenever the declaration bundle references @mui/x-date-pickers.

Either add the documented exemption until issue #1749 is fixed, or remove the public type reference before narrowing the list.

Proposed fix
-const OPTIONAL_PEERS_ON_THE_RECORD = ['react'];
+const OPTIONAL_PEERS_ON_THE_RECORD = ['`@mui/x-date-pickers`', 'react'];

Based on learnings, derive optional-peer enforcement from src/__testing__/optionalPeerDependencies.test.ts rather than narrowing the list independently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/__testing__/publishedTypeSurfaceDependencies.test.ts` around lines 66 -
77, Restore the documented `@mui/x-date-pickers` exemption in
OPTIONAL_PEERS_ON_THE_RECORD so the published type-surface test remains
consistent with the barrel’s DateTimePickerProps re-export, or remove that
public type reference before narrowing the exemption list. Prefer reusing the
optional-peer enforcement or exemption definition from
optionalPeerDependencies.test.ts instead of maintaining a separate independently
narrowed list.

Source: Learnings

🧹 Nitpick comments (1)
src/custom/UniversalFilter.tsx (1)

290-294: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a Sistent semantic badge color.

color="primary" relies on the raw MUI color API. Use the project’s semantic Sistent palette/token styling for the badge so it remains consistent across themes.

As per coding guidelines, “Theme-aware UI must use Sistent theme exports and semantic palette tokens rather than raw MUI defaults.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/custom/UniversalFilter.tsx` around lines 290 - 294, Update the Badge in
UniversalFilter to replace the raw MUI color="primary" value with the project’s
Sistent semantic badge color or theme palette token. Preserve the existing
activeFilterCount, overlap, and visibility behavior while using the established
theme-aware styling approach.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/__testing__/publishedTypeSurfaceDependencies.test.ts`:
- Around line 95-97: Update specifiersIn to recognize bare side-effect imports
such as import 'package' in addition to from and dynamic import() forms, while
preserving extraction of the module specifier. Add a detector fixture covering a
declaration bundle containing only a side-effect import and assert that the
referenced package is detected by the dependency-contract test.
- Around line 140-181: Extend the published type-surface test around the
existing dist/index.d.ts checks with a scoped consumer fixture that imports the
package and is type-checked via tsc. Verify the fixture is present in tsc’s
--listFiles output, filter diagnostics to the fixture, and fail on relevant
resolution or type errors while preserving the existing metadata and
declaration-text assertions.
- Around line 66-77: Restore the documented `@mui/x-date-pickers` exemption in
OPTIONAL_PEERS_ON_THE_RECORD so the published type-surface test remains
consistent with the barrel’s DateTimePickerProps re-export, or remove that
public type reference before narrowing the exemption list. Prefer reusing the
optional-peer enforcement or exemption definition from
optionalPeerDependencies.test.ts instead of maintaining a separate independently
narrowed list.

In `@src/custom/UniversalFilter.tsx`:
- Around line 244-251: Update the Select associated with the quick-range
InputLabel to include the matching labelId value `${testId}-quick-range-label`,
ensuring the control is programmatically named “Quick Ranges.”

---

Nitpick comments:
In `@src/custom/UniversalFilter.tsx`:
- Around line 290-294: Update the Badge in UniversalFilter to replace the raw
MUI color="primary" value with the project’s Sistent semantic badge color or
theme palette token. Preserve the existing activeFilterCount, overlap, and
visibility behavior while using the established theme-aware styling approach.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cbd00669-0971-4d97-b83f-8939ac126815

📥 Commits

Reviewing files that changed from the base of the PR and between 33880e5 and 82f39f3.

📒 Files selected for processing (3)
  • src/__testing__/UniversalFilter.test.tsx
  • src/__testing__/publishedTypeSurfaceDependencies.test.ts
  • src/custom/UniversalFilter.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/testing/UniversalFilter.test.tsx

@Uday9909
Uday9909 force-pushed the feat/filter-count-badge branch from 82f39f3 to 33880e5 Compare July 25, 2026 07:47
Signed-off-by: Udaybir Singh <writetoudaybir@gmail.com>
@Uday9909

Copy link
Copy Markdown
Contributor Author

@KhushamBansal ready for review!!

@KhushamBansal KhushamBansal 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.

Image Image

Tested it in meshery-ui, LGTM!!

@Uday9909

Copy link
Copy Markdown
Contributor Author

@rishiraj38 @YASHMAHAKAL @leecalcote
ready for review!

@PARTH-TUSSLE PARTH-TUSSLE 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.

@Uday9909 All the changes LGTM.

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.

[Feature] Add active filter count badge to filter icon

4 participants