diff --git a/.changeset/nested-filter-key-search.md b/.changeset/nested-filter-key-search.md new file mode 100644 index 0000000000..1a8a304d26 --- /dev/null +++ b/.changeset/nested-filter-key-search.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/app': patch +--- + +fix: add a key search to Map and JSON filter groups (e.g. `ResourceAttributes`, +`LogAttributes`) in the search page filter sidebar, matching the value search on +regular filters. diff --git a/packages/app/src/components/DBSearchPageFilters.tsx b/packages/app/src/components/DBSearchPageFilters.tsx index 08c35d32da..5f848ff44d 100644 --- a/packages/app/src/components/DBSearchPageFilters.tsx +++ b/packages/app/src/components/DBSearchPageFilters.tsx @@ -27,7 +27,6 @@ import { Stack, Tabs, Text, - TextInput, Tooltip, UnstyledButton, } from '@mantine/core'; @@ -43,7 +42,6 @@ import { IconMinus, IconPlus, IconRefresh, - IconSearch, IconShadow, IconSitemap, } from '@tabler/icons-react'; @@ -65,6 +63,10 @@ import { import { useSource } from '@/source'; import { isColumnInSelect, useLocalStorage } from '@/utils'; +import { + FILTER_SEARCH_MIN_ITEMS, + FilterSearchInput, +} from './DBSearchPageFilters/FilterSearchInput'; import { FilterSettingsPanel } from './DBSearchPageFilters/FilterSettingsPopover'; import { useFetchFacets } from './DBSearchPageFilters/hooks'; import { NestedFilterGroup } from './DBSearchPageFilters/NestedFilterGroup'; @@ -667,23 +669,13 @@ const FilterGroupBody = ({ return ( - {augmentedOptions.length > 5 && ( -
- ) => - handleSetSearch(event.currentTarget.value) - } - rightSectionWidth={20} - rightSection={} - classNames={{ - input: 'ps-0.5', - }} - /> -
+ {augmentedOptions.length > FILTER_SEARCH_MIN_ITEMS && ( + )} {displayedOptions.map(option => ( void; + placeholder: string; + 'data-testid'?: string; +}; + +export const FilterSearchInput = ({ + value, + onChange, + placeholder, + 'data-testid': dataTestId, +}: FilterSearchInputProps) => ( +
+ ) => + onChange(event.currentTarget.value) + } + rightSectionWidth={20} + rightSection={} + classNames={{ + input: 'ps-0.5', + }} + /> +
+); diff --git a/packages/app/src/components/DBSearchPageFilters/NestedFilterGroup.tsx b/packages/app/src/components/DBSearchPageFilters/NestedFilterGroup.tsx index 89720f035d..7da5b45a33 100644 --- a/packages/app/src/components/DBSearchPageFilters/NestedFilterGroup.tsx +++ b/packages/app/src/components/DBSearchPageFilters/NestedFilterGroup.tsx @@ -4,6 +4,10 @@ import { Accordion, Group, Text, Tooltip, UnstyledButton } from '@mantine/core'; import { useVirtualizer } from '@tanstack/react-virtual'; import { FilterGroup } from '@/components/DBSearchPageFilters'; +import { + FILTER_SEARCH_MIN_ITEMS, + FilterSearchInput, +} from '@/components/DBSearchPageFilters/FilterSearchInput'; import { isColumnInSelect } from '@/utils'; import classes from '@styles/SearchPage.module.scss'; @@ -93,14 +97,23 @@ export const NestedFilterGroup = ({ isDefaultExpanded ?? hasSelections, ); + const [search, setSearch] = useState(''); + const matchingChildFilters = useMemo(() => { + const query = search.trim().toLowerCase(); + if (!query) return childFilters; + return childFilters.filter(child => + child.propertyPath.toLowerCase().includes(query), + ); + }, [childFilters, search]); + const scrollContainerRef = useRef(null); const rowVirtualizer = useVirtualizer({ - count: isExpanded ? childFilters.length : 0, + count: isExpanded ? matchingChildFilters.length : 0, getScrollElement: () => scrollContainerRef.current, estimateSize: () => VIRTUAL_ITEM_HEIGHT_ESTIMATE, overscan: 10, - getItemKey: index => childFilters[index]?.key ?? index, + getItemKey: index => matchingChildFilters[index]?.key ?? index, }); return ( @@ -155,7 +168,15 @@ export const NestedFilterGroup = ({ pl="xs" >
- {childFilters.length === 0 ? ( + {childFilters.length > FILTER_SEARCH_MIN_ITEMS && ( + + )} + {matchingChildFilters.length === 0 ? ( No properties found @@ -177,7 +198,7 @@ export const NestedFilterGroup = ({ }} > {rowVirtualizer.getVirtualItems().map(virtualRow => { - const child = childFilters[virtualRow.index]; + const child = matchingChildFilters[virtualRow.index]; const childSelectedValues = selectedValues[child.key] || { included: new Set(), excluded: new Set(), diff --git a/packages/app/src/components/__tests__/DBSearchPageFilters.test.tsx b/packages/app/src/components/__tests__/DBSearchPageFilters.test.tsx index 092b58141c..7ec0223d0f 100644 --- a/packages/app/src/components/__tests__/DBSearchPageFilters.test.tsx +++ b/packages/app/src/components/__tests__/DBSearchPageFilters.test.tsx @@ -49,6 +49,21 @@ describe('cleanClickHouseExpression', () => { }); }); +// jsdom has no layout, so the real virtualizer in NestedFilterGroup renders no +// rows. Render every row as if visible. +jest.mock('@tanstack/react-virtual', () => ({ + useVirtualizer: ({ count }: { count: number }) => ({ + getVirtualItems: () => + Array.from({ length: count }, (_, index) => ({ + index, + key: index, + start: index * 26, + })), + getTotalSize: () => count * 26, + measureElement: () => {}, + }), +})); + jest.mock('@/hooks/useMetadata', () => ({ useGetValuesDistribution: jest .fn() @@ -850,4 +865,60 @@ describe('NestedFilterGroup', () => { await userEvent.click(control); expect(panel).toHaveAttribute('aria-hidden', 'false'); }); + + const manyChildFilters = [ + 'service.name', + 'service.version', + 'host.name', + 'host.arch', + 'k8s.pod.name', + 'k8s.namespace.name', + ].map(propertyPath => ({ + key: `ResourceAttributes['${propertyPath}']`, + value: ['val'], + propertyPath, + })); + + it('should not show the key search when there are few keys', () => { + renderWithMantine( + , + ); + + expect(screen.queryByPlaceholderText('Search keys...')).toBeNull(); + }); + + it('should filter keys when searching', async () => { + renderWithMantine( + , + ); + + await userEvent.type(screen.getByPlaceholderText('Search keys...'), 'K8S'); + + expect(screen.getByText('k8s.pod.name')).toBeInTheDocument(); + expect(screen.getByText('k8s.namespace.name')).toBeInTheDocument(); + expect(screen.queryByText('service.name')).toBeNull(); + expect(screen.queryByText('host.name')).toBeNull(); + }); + + it('should show an empty state when no keys match', async () => { + renderWithMantine( + , + ); + + await userEvent.type( + screen.getByPlaceholderText('Search keys...'), + 'nonexistent', + ); + + expect(screen.getByText('No properties found')).toBeInTheDocument(); + expect(screen.getByPlaceholderText('Search keys...')).toBeInTheDocument(); + }); });