Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/__testing__/UniversalFilter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ jest.mock('../custom/PopperListener', () => ({
default: ({ children, open }: any) => (open ? <div>{children}</div> : null)
}));

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

Comment on lines +59 to +66

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

jest.mock('../custom/TooltipIconButton', () => ({
TooltipIcon: ({ onClick, title }: any) => (
<button aria-label={title} onClick={onClick}>
Expand Down
23 changes: 17 additions & 6 deletions src/custom/UniversalFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Drawer, styled, useMediaQuery } from '@mui/material';
import { SelectChangeEvent } from '@mui/material/Select';
import React from 'react';
import { Badge } from '../base/Badge';
import { Button } from '../base/Button';
import { ClickAwayListener } from '../base/ClickAwayListener';
import { DateTimePicker } from '../base/DateTimePicker';
Expand Down Expand Up @@ -110,6 +111,9 @@ function UniversalFilter({

const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const activeFilterCount = Object.values(selectedFilters).filter(
(value) => value && value !== 'All'
).length;

// Track the serialized value rather than the object reference so a parent that
// passes a new `selectedFilters` reference with unchanged values (e.g. an inline
Expand Down Expand Up @@ -283,12 +287,19 @@ function UniversalFilter({
return (
<>
<div id={id} data-testid={testId}>
<TooltipIcon
title="Filter"
onClick={handleClick}
icon={<FilterIcon fill={theme.palette.icon.default} />}
arrow
/>
<Badge
badgeContent={activeFilterCount}
color="primary"
overlap="circular"
invisible={activeFilterCount === 0}
>
<TooltipIcon
title="Filter"
onClick={handleClick}
icon={<FilterIcon fill={theme.palette.icon.default} />}
arrow
/>
</Badge>
{!isMobile ? (
<PopperListener
id={open && anchorEl ? 'transition-popper' : undefined}
Expand Down
Loading