Repository navigation
feat: search bar for keys in nested filter groups #3368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
| 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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<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 ( | ||||||
|
|
@@ -155,7 +168,15 @@ export const NestedFilterGroup = ({ | |||||
| pl="xs" | ||||||
| > | ||||||
| <div className={classes.filterGroupPanel}> | ||||||
| {childFilters.length === 0 ? ( | ||||||
| {childFilters.length > FILTER_SEARCH_MIN_ITEMS && ( | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a refresh leaves an existing group with five or fewer keys, this condition hides the search input but keeps its query active. Keep the input visible while
Suggested change
|
||||||
| <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 | ||||||
|
|
@@ -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(), | ||||||
|
|
||||||
There was a problem hiding this comment.
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"
childFilterscomes from facet results (useFetchFacetsin 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, butmatchingChildFiltersstill applies the oldsearch. Example: typek8s, 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 resetsearchwhen the input goes away. Add a test that rerenders with fewerchildFiltersafter 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