Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .changeset/nested-filter-key-search.md
Original file line number Diff line number Diff line change
@@ -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.
30 changes: 11 additions & 19 deletions packages/app/src/components/DBSearchPageFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
Stack,
Tabs,
Text,
TextInput,
Tooltip,
UnstyledButton,
} from '@mantine/core';
Expand All @@ -43,7 +42,6 @@ import {
IconMinus,
IconPlus,
IconRefresh,
IconSearch,
IconShadow,
IconSitemap,
} from '@tabler/icons-react';
Expand All @@ -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';
Expand Down Expand Up @@ -667,23 +669,13 @@ const FilterGroupBody = ({

return (
<Stack gap={0}>
{augmentedOptions.length > 5 && (
<div className="px-2 pb-2">
<TextInput
size="xs"
placeholder="Search values..."
value={search}
data-testid={`filter-search-${name}`}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
handleSetSearch(event.currentTarget.value)
}
rightSectionWidth={20}
rightSection={<IconSearch size={12} stroke={2} />}
classNames={{
input: 'ps-0.5',
}}
/>
</div>
{augmentedOptions.length > FILTER_SEARCH_MIN_ITEMS && (
<FilterSearchInput
placeholder="Search values..."
value={search}
data-testid={`filter-search-${name}`}
onChange={handleSetSearch}
/>
)}
{displayedOptions.map(option => (
<FilterCheckbox
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { TextInput } from '@mantine/core';
import { IconSearch } from '@tabler/icons-react';

/* Lists with more items than this get a search input */
export const FILTER_SEARCH_MIN_ITEMS = 5;

type FilterSearchInputProps = {
value: string;
onChange: (value: string) => void;
placeholder: string;
'data-testid'?: string;
};

export const FilterSearchInput = ({
value,
onChange,
placeholder,
'data-testid': dataTestId,
}: FilterSearchInputProps) => (
<div className="px-2 pb-2">
<TextInput
size="xs"
placeholder={placeholder}
value={value}
data-testid={dataTestId}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
onChange(event.currentTarget.value)
}
rightSectionWidth={20}
rightSection={<IconSearch size={12} stroke={2} />}
classNames={{
input: 'ps-0.5',
}}
/>
</div>
);
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<HTMLDivElement>(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 (
Expand Down Expand Up @@ -155,7 +168,15 @@ export const NestedFilterGroup = ({
pl="xs"
>
<div className={classes.filterGroupPanel}>
{childFilters.length === 0 ? (
{childFilters.length > FILTER_SEARCH_MIN_ITEMS && (

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.

🔵 minor — Key search keeps filtering after its input is hidden, which can leave the group stuck on "No properties found"

childFilters comes from facet results (useFetchFacets in DBSearchPageFilters/hooks.ts), so changing the date range or query can drop the key count to 5 or fewer. When that happens the input stops rendering, but matchingChildFilters still applies the old search. Example: type k8s, then narrow the time range so that 4 keys come back and none of them match. The header still says {4}, the body says "No properties found", and there is no input left to clear the search. Fix: only apply the filter while the input is shown (const query = childFilters.length > FILTER_SEARCH_MIN_ITEMS ? search.trim().toLowerCase() : ''), or reset search when the input goes away. Add a test that rerenders with fewer childFilters after typing a search.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

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.

P1 Hidden search keeps hiding keys

When a refresh leaves an existing group with five or fewer keys, this condition hides the search input but keeps its query active. NestedFilterGroup keeps the same React key, so nonmatching keys stay hidden with no way to clear the search—even after collapsing and reopening the group. Users can see “No properties found” despite valid keys being available.

Keep the input visible while search is nonempty, or stop applying the query when the input disappears.

Suggested change
{childFilters.length > FILTER_SEARCH_MIN_ITEMS && (
{(childFilters.length > FILTER_SEARCH_MIN_ITEMS || search !== '') && (

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

<FilterSearchInput
placeholder="Search keys..."
value={search}
data-testid={`nested-filter-search-${name}`}
onChange={setSearch}
/>
)}
{matchingChildFilters.length === 0 ? (
<Group m={6} gap="xs">
<Text c="dimmed" size="xs">
No properties found
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
<NestedFilterGroup {...defaultNestedProps} isDefaultExpanded={true} />,
);

expect(screen.queryByPlaceholderText('Search keys...')).toBeNull();
});

it('should filter keys when searching', async () => {
renderWithMantine(
<NestedFilterGroup
{...defaultNestedProps}
childFilters={manyChildFilters}
isDefaultExpanded={true}
/>,
);

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(
<NestedFilterGroup
{...defaultNestedProps}
childFilters={manyChildFilters}
isDefaultExpanded={true}
/>,
);

await userEvent.type(
screen.getByPlaceholderText('Search keys...'),
'nonexistent',
);

expect(screen.getByText('No properties found')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Search keys...')).toBeInTheDocument();
});
});
Loading