Repository navigation
feat: extend filter value truncation to all dashboard filter types #3900
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
base: main
Are you sure you want to change the base?
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 | ||
| --- | ||
|
|
||
| Collapse selected values past the first three behind a "+N more" toggle for all | ||
| dashboard filter types, matching ad hoc filters. Keeps the filters bar from | ||
| growing tall when a filter has many selections. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |
| useState, | ||
| } from 'react'; | ||
| import { | ||
| Button, | ||
| CheckIcon, | ||
| CloseButton, | ||
| Combobox, | ||
|
|
@@ -18,6 +19,10 @@ import { | |
| } from '@mantine/core'; | ||
| import { useVirtualizer } from '@tanstack/react-virtual'; | ||
|
|
||
| // Mirrors ad hoc filters: collapse past the first few selected values so a | ||
| // filter with many selections doesn't grow the filter bar tall. | ||
| const MAX_COLLAPSED_PILLS = 3; | ||
|
|
||
| type VirtualMultiSelectProps = { | ||
| data: string[]; | ||
| disabled?: boolean; | ||
|
|
@@ -46,6 +51,12 @@ export function VirtualMultiSelect({ | |
| const viewportRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| const [search, setSearch] = useState(''); | ||
| const [isExpanded, setIsExpanded] = useState(false); | ||
|
|
||
| const hiddenCount = isExpanded | ||
| ? 0 | ||
| : Math.max(0, values.length - MAX_COLLAPSED_PILLS); | ||
| const visibleValues = values.slice(0, values.length - hiddenCount); | ||
|
|
||
| const sorted = useMemo(() => { | ||
| return sort ? data.toSorted((a, b) => a.localeCompare(b)) : data; | ||
|
|
@@ -158,7 +169,7 @@ export function VirtualMultiSelect({ | |
| })} | ||
| > | ||
| <Pill.Group> | ||
| {values.map(item => ( | ||
| {visibleValues.map(item => ( | ||
| <Pill | ||
| key={item} | ||
| withRemoveButton | ||
|
|
@@ -172,6 +183,25 @@ export function VirtualMultiSelect({ | |
| </Pill> | ||
| ))} | ||
|
|
||
| {values.length > MAX_COLLAPSED_PILLS && ( | ||
| <Button | ||
| variant="subtle" | ||
| size="compact-xs" | ||
| disabled={disabled} | ||
| onClick={event => { | ||
| // Keep the toggle from opening the dropdown or stealing focus | ||
| // into the search field. | ||
| event.stopPropagation(); | ||
| setIsExpanded(expanded => !expanded); | ||
| }} | ||
|
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. Toggle still opens the dropdownMedium Severity The Reviewed by Cursor Bugbot for commit a1215e2. Configure here. |
||
| data-testid={ | ||
| dataTestId ? `${dataTestId}-toggle-more` : undefined | ||
| } | ||
| > | ||
| {isExpanded ? 'Show less' : `+${hiddenCount} more`} | ||
| </Button> | ||
| )} | ||
|
|
||
| <Combobox.EventsTarget> | ||
| <PillsInput.Field | ||
| onFocus={() => combobox.openDropdown()} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { useState } from 'react'; | ||
| import { screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| import { VirtualMultiSelect } from '@/components/VirtualMultiSelect/VirtualMultiSelect'; | ||
|
|
||
| const data = ['a', 'b', 'c', 'd', 'e', 'f']; | ||
|
|
||
| const Harness = ({ initial }: { initial: string[] }) => { | ||
| const [values, setValues] = useState(initial); | ||
| return ( | ||
| <VirtualMultiSelect | ||
| data={data} | ||
| values={values} | ||
| onChange={setValues} | ||
| data-testid="multi-select" | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const pills = () => | ||
| screen.getByTestId('multi-select').querySelectorAll('.mantine-Pill-root'); | ||
|
|
||
| describe('VirtualMultiSelect', () => { | ||
| it('collapses selected values past the first three until expanded', async () => { | ||
| renderWithMantine(<Harness initial={['a', 'b', 'c', 'd', 'e']} />); | ||
| const toggle = screen.getByTestId('multi-select-toggle-more'); | ||
|
|
||
| expect(pills()).toHaveLength(3); | ||
| expect(toggle).toHaveTextContent('+2 more'); | ||
|
|
||
| await userEvent.click(toggle); | ||
| expect(pills()).toHaveLength(5); | ||
| expect(toggle).toHaveTextContent('Show less'); | ||
|
|
||
| await userEvent.click(toggle); | ||
| expect(pills()).toHaveLength(3); | ||
| }); | ||
|
|
||
| it('shows no toggle for three values or fewer', () => { | ||
| renderWithMantine(<Harness initial={['a', 'b', 'c']} />); | ||
| expect( | ||
| screen.queryByTestId('multi-select-toggle-more'), | ||
| ).not.toBeInTheDocument(); | ||
| expect(pills()).toHaveLength(3); | ||
| }); | ||
| }); |


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.
🟡 P2 — Calling stopPropagation in onClick doesn't stop the toggle from focusing the field and opening the dropdown
Mantine's
PillsInputroot has anonMouseDownhandler that callspreventDefault()and focuses the inner field. Mousedown fires before click, so pressing the toggle still focusesPillsInput.Field, and itsonFocusopens the dropdown. The behaviour the comment and PR description promise doesn't happen. Fix: also addonMouseDown={e => e.stopPropagation()}on the toggle Button, or move the toggle outside thePillsInput. Then add a test that clicking the toggle leaves the dropdown closed.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