From dad989047c12e9619b73fd093323b30c0e8d28f5 Mon Sep 17 00:00:00 2001 From: Elizabet Oliveira Date: Wed, 21 Oct 2026 14:48:49 +0100 Subject: [PATCH 1/3] feat(app): share the group by split button Group by needs the same name-and-value button Columns and Sort will use. On a narrow screen a field count is only the number. Co-authored-by: Cursor --- .changeset/split-value-button.md | 5 + .../SearchGroupBy/SearchGroupBySelect.tsx | 50 +++----- .../SplitValueButton.module.scss} | 0 .../SplitValueButton.stories.tsx | 108 ++++++++++++++++++ .../SplitValueButton/SplitValueButton.tsx | 91 +++++++++++++++ .../__tests__/SplitValueButton.test.tsx | 53 +++++++++ 6 files changed, 271 insertions(+), 36 deletions(-) create mode 100644 .changeset/split-value-button.md rename packages/app/src/components/{SearchGroupBy/SearchGroupBySelect.module.scss => SplitValueButton/SplitValueButton.module.scss} (100%) create mode 100644 packages/app/src/components/SplitValueButton/SplitValueButton.stories.tsx create mode 100644 packages/app/src/components/SplitValueButton/SplitValueButton.tsx create mode 100644 packages/app/src/components/SplitValueButton/__tests__/SplitValueButton.test.tsx diff --git a/.changeset/split-value-button.md b/.changeset/split-value-button.md new file mode 100644 index 0000000000..4c6d3339f6 --- /dev/null +++ b/.changeset/split-value-button.md @@ -0,0 +1,5 @@ +--- +'@hyperdx/app': patch +--- + +Show a Group by field count as a number on a narrow screen diff --git a/packages/app/src/components/SearchGroupBy/SearchGroupBySelect.tsx b/packages/app/src/components/SearchGroupBy/SearchGroupBySelect.tsx index 6794ad77fb..d90cf8d5d6 100644 --- a/packages/app/src/components/SearchGroupBy/SearchGroupBySelect.tsx +++ b/packages/app/src/components/SearchGroupBy/SearchGroupBySelect.tsx @@ -6,12 +6,13 @@ import { Group, Popover, SegmentedControl, - Text, TextInput, - UnstyledButton, } from '@mantine/core'; -import { IconChevronDown } from '@tabler/icons-react'; +import { + fieldListSummary, + SplitValueButton, +} from '@/components/SplitValueButton/SplitValueButton'; import SQLInlineEditor from '@/components/SQLEditor/SQLInlineEditor'; import { GroupByFieldList } from './GroupByFieldList'; @@ -23,16 +24,8 @@ import { } from './searchGroupBy'; import { useGroupByKeyOptions } from './useGroupByKeyOptions'; -import classes from './SearchGroupBySelect.module.scss'; - type Mode = 'fields' | 'sql'; -function triggerLabel(fields: string[]) { - if (fields.length === 0) return 'none'; - if (fields.length === 1) return fields[0]; - return `${fields.length} fields`; -} - export function SearchGroupBySelect({ source, value, @@ -112,8 +105,6 @@ export function SearchGroupBySelect({ prev.includes(field) ? prev.filter(f => f !== field) : [...prev, field], ); - const label = triggerLabel(appliedFields); - return ( -
- - Group by - - - handleOpenChange(!opened)} - data-testid="search-group-by-button" - aria-label={`Group by ${label}`} - > - - {label} - - - - -
+ + handleOpenChange(!opened)} + data-testid="search-group-by-button" + /> + = { + title: 'Components/SplitValueButton', + component: SplitValueButton, + parameters: { + layout: 'padded', + docs: { + description: { + component: + 'The shared trigger for Group by, Columns, and Sort. Use it when a search control shows the current value of a clause and opens an editor. Do not use it for an action such as Save, Run, or Apply.', + }, + }, + }, +}; + +export default meta; +type Story = StoryObj; + +const noop = () => {}; + +export const WhenToUse: Story = { + render: () => ( + + + Use this button for a search clause whose value is one field, or a count + of fields. The name stays fixed. The value is what you press. + + + + Group by splits the histogram. One series for each value of the field. + + + + + + Columns chooses which columns the results table shows, and their + order. + + + + + + Sort sets the order of the result rows. One field includes its + direction. + + + + + + On a narrow screen a count is only the number. One field keeps its + name, and an empty clause stays none. + + + + + + + + + ), +}; diff --git a/packages/app/src/components/SplitValueButton/SplitValueButton.tsx b/packages/app/src/components/SplitValueButton/SplitValueButton.tsx new file mode 100644 index 0000000000..5815600b58 --- /dev/null +++ b/packages/app/src/components/SplitValueButton/SplitValueButton.tsx @@ -0,0 +1,91 @@ +import { ComponentPropsWithoutRef, Ref } from 'react'; +import cx from 'classnames'; +import { Text, UnstyledButton } from '@mantine/core'; +import { IconChevronDown } from '@tabler/icons-react'; + +import { useCompactViewport } from '@/components/CompactViewport/useCompactViewport'; + +import classes from './SplitValueButton.module.scss'; + +/** One field by name, several as a count, or none. */ +export function fieldListSummary(fields: string[]): string { + if (fields.length === 0) return 'none'; + if (fields.length === 1) return fields[0]; + return `${fields.length} fields`; +} + +type SplitValueButtonProps = { + /** Fixed name, such as Group by, Columns, or Sort. */ + name: string; + /** Desktop value: a field name, "3 fields", or "none". */ + summary: string; + /** How many fields the summary counts. Drives the narrow-screen number. */ + count: number; + /** The clause is still the source default, so the value is quiet. */ + dimmed?: boolean; + /** Full clause, shown on hover when the value is only a summary. */ + title?: string; + onClick: () => void; + /** Story and test override. Otherwise follows the compact viewport. */ + compact?: boolean; + 'data-testid': string; + ref?: Ref; +} & Omit, 'onClick' | 'title'>; + +/** + * Split button for a search clause: a fixed name, then the current value. + * + * Use it for Group by, Columns, and Sort. The name says which clause it is. + * The value is one field, or "3 fields" when there are several. On a narrow + * screen that count is only the number, so the row still fits. + * + * Group by splits the histogram, one series per value. Columns chooses and + * orders the results table. Sort sets the row order, and a single field + * includes its direction. + * + * Do not use it for an action such as Save, Run, or Apply. + */ +export function SplitValueButton({ + name, + summary, + count, + dimmed, + title, + onClick, + compact, + 'data-testid': testId, + className, + ref, + ...others +}: SplitValueButtonProps) { + const viewportCompact = useCompactViewport(); + const isCompact = compact ?? viewportCompact; + const shown = isCompact && count > 1 ? String(count) : summary; + + return ( +
+ + {name} + + + + {shown} + + + +
+ ); +} diff --git a/packages/app/src/components/SplitValueButton/__tests__/SplitValueButton.test.tsx b/packages/app/src/components/SplitValueButton/__tests__/SplitValueButton.test.tsx new file mode 100644 index 0000000000..e43815f63e --- /dev/null +++ b/packages/app/src/components/SplitValueButton/__tests__/SplitValueButton.test.tsx @@ -0,0 +1,53 @@ +import { screen } from '@testing-library/react'; + +import { SplitValueButton } from '@/components/SplitValueButton/SplitValueButton'; + +describe('SplitValueButton', () => { + it('shows a field count as words on a wide screen', () => { + renderWithMantine( + {}} + data-testid="columns" + />, + ); + expect(screen.getByTestId('columns')).toHaveTextContent('3 fields'); + expect(screen.getByTestId('columns')).toHaveAccessibleName( + 'Columns 3 fields', + ); + }); + + it('shows only the number on a narrow screen', () => { + renderWithMantine( + {}} + data-testid="columns" + />, + ); + expect(screen.getByTestId('columns')).toHaveTextContent('3'); + expect(screen.getByTestId('columns')).toHaveAccessibleName( + 'Columns 3 fields', + ); + }); + + it('keeps a single field name on a narrow screen', () => { + renderWithMantine( + {}} + data-testid="group-by" + />, + ); + expect(screen.getByTestId('group-by')).toHaveTextContent('SeverityText'); + }); +}); From 13028a80a70376393f6027370358f12d3dcce080 Mon Sep 17 00:00:00 2001 From: Elizabet Oliveira Date: Wed, 21 Oct 2026 15:08:27 +0100 Subject: [PATCH 2/3] fix(app): keep the split button only as wide as its value The frame was stretching in a column layout, so the chevron sat away from the end of the value. Co-authored-by: Cursor --- .../SplitValueButton/SplitValueButton.module.scss | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/app/src/components/SplitValueButton/SplitValueButton.module.scss b/packages/app/src/components/SplitValueButton/SplitValueButton.module.scss index 23f0eda5a9..8e3cd6ffd8 100644 --- a/packages/app/src/components/SplitValueButton/SplitValueButton.module.scss +++ b/packages/app/src/components/SplitValueButton/SplitValueButton.module.scss @@ -1,9 +1,12 @@ // The label sits in a filled addon so it reads as the frame's name rather than // something to press; only the value side is the button. .control { - display: flex; + display: inline-flex; align-items: center; + align-self: flex-start; flex-shrink: 0; + width: fit-content; + max-width: 100%; overflow: hidden; background: var(--color-bg-surface); border: 1px solid var(--color-border); @@ -23,6 +26,7 @@ .target { display: flex; align-items: center; + flex: none; gap: 6px; height: 28px; padding-inline: 8px; @@ -35,6 +39,7 @@ // Long expressions truncate rather than pushing the row's other controls off. .value { + flex: none; overflow: hidden; max-width: 220px; text-overflow: ellipsis; From ab2df8b9cfd3da0a63021394eb4d55cf1e1f4813 Mon Sep 17 00:00:00 2001 From: Elizabet Oliveira Date: Wed, 21 Oct 2026 15:50:55 +0100 Subject: [PATCH 3/3] test(app): require the narrow split button to show only the number A substring check for 3 also passed when the label was still 3 fields. Co-authored-by: Cursor --- .../SplitValueButton/__tests__/SplitValueButton.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/components/SplitValueButton/__tests__/SplitValueButton.test.tsx b/packages/app/src/components/SplitValueButton/__tests__/SplitValueButton.test.tsx index e43815f63e..9430b1f9fd 100644 --- a/packages/app/src/components/SplitValueButton/__tests__/SplitValueButton.test.tsx +++ b/packages/app/src/components/SplitValueButton/__tests__/SplitValueButton.test.tsx @@ -31,7 +31,7 @@ describe('SplitValueButton', () => { data-testid="columns" />, ); - expect(screen.getByTestId('columns')).toHaveTextContent('3'); + expect(screen.getByTestId('columns')).toHaveTextContent(/^3$/); expect(screen.getByTestId('columns')).toHaveAccessibleName( 'Columns 3 fields', );