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
7 changes: 7 additions & 0 deletions .changeset/filter-overflow-truncation.md
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
Expand Up @@ -50,3 +50,17 @@ export default meta;
type Story = StoryObj<typeof VirtualMultiSelect>;

export const Primary: Story = {};

/** Many selected values collapse behind a "+N more" toggle. */
export const Overflow: Story = {
decorators: [
(Story, ctx) => {
const [values, setValues] = useState<string[]>(data.slice(0, 6));
return (
<Box maw={256}>
<Story args={{ ...ctx.args, data, values, onChange: setValues }} />
</Box>
);
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useState,
} from 'react';
import {
Button,
CheckIcon,
CloseButton,
Combobox,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -158,7 +169,7 @@ export function VirtualMultiSelect({
})}
>
<Pill.Group>
{values.map(item => (
{visibleValues.map(item => (
<Pill
key={item}
withRemoveButton
Expand All @@ -172,6 +183,25 @@ export function VirtualMultiSelect({
</Pill>
))}

{values.length > MAX_COLLAPSED_PILLS && (
<Button
variant="subtle"
size="compact-xs"
disabled={disabled}
onClick={event => {

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.

🟡 P2 — Calling stopPropagation in onClick doesn't stop the toggle from focusing the field and opening the dropdown

Mantine's PillsInput root has an onMouseDown handler that calls preventDefault() and focuses the inner field. Mousedown fires before click, so pressing the toggle still focuses PillsInput.Field, and its onFocus opens the dropdown. The behaviour the comment and PR description promise doesn't happen. Fix: also add onMouseDown={e => e.stopPropagation()} on the toggle Button, or move the toggle outside the PillsInput. 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

// Keep the toggle from opening the dropdown or stealing focus
// into the search field.
event.stopPropagation();
setIsExpanded(expanded => !expanded);
}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toggle still opens the dropdown

Medium Severity

The +N more toggle only calls stopPropagation on click, but Mantine PillsInput focuses its field on mousedown, and that field's onFocus opens the dropdown. Clicking the toggle still moves focus into the search field and opens the menu, which this handler was meant to prevent.

Fix in Cursor Fix in Web

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()}
Expand Down
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);
});
});
Loading