Repository navigation
Add the column and sort editors #3431
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4c20cba
feat(app): add the column and sort editors
elizabetdev 804ed04
fix(app): keep an empty column or sort from restoring the default
elizabetdev 1293b77
Merge branch 'main' into elizabet/column-sort-editors
elizabetdev 27a1e6c
fix(app): offer DateTime columns in the column and sort pickers
elizabetdev 4103e15
fix(app): share the clause apply rule and the field key list
elizabetdev 91fed66
Merge branch 'main' into elizabet/column-sort-editors
elizabetdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@hyperdx/app': patch | ||
| --- | ||
|
|
||
| When a removed column is one field in a multi-field sort, drop only that field |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
packages/app/src/components/SearchResultsToolbar/ClausePopover.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import { type ReactNode, useState } from 'react'; | ||
| import { Button, Group, Popover, SegmentedControl, Stack } from '@mantine/core'; | ||
|
|
||
| import { SplitValueButton } from '@/components/SplitValueButton/SplitValueButton'; | ||
|
|
||
| export type ClauseMode = 'pick' | 'sql'; | ||
|
|
||
| const matchesDefault = (draft: string, defaultValue: string) => | ||
| draft.trim() === defaultValue.trim(); | ||
|
|
||
| /** | ||
| * What Apply writes. An empty form value means "use the source default", so a | ||
| * draft that matches the default is stored as "" rather than a copy of it. | ||
| */ | ||
| export function storedClause( | ||
| draft: string, | ||
| value: string, | ||
| defaultValue: string, | ||
| ) { | ||
| return matchesDefault(draft, defaultValue) | ||
| ? '' | ||
| : draft === (value || defaultValue) | ||
| ? value | ||
| : draft; | ||
| } | ||
|
|
||
| export const clauseResetDisabled = matchesDefault; | ||
|
|
||
| export const clauseApplyDisabled = (draft: string) => draft.trim() === ''; | ||
|
|
||
| const MODE_OPTIONS = [ | ||
| { label: 'Fields', value: 'pick' }, | ||
| { label: 'SQL', value: 'sql' }, | ||
| ]; | ||
|
|
||
| /** | ||
| * A toolbar button that edits one query clause in a popover. Edits stay in a | ||
| * draft owned by the caller until Apply, so closing the popover discards them. | ||
| */ | ||
| export function ClausePopover({ | ||
| name, | ||
| summary, | ||
| count, | ||
| dimmed, | ||
| title, | ||
| initialMode, | ||
| onOpen, | ||
| onApply, | ||
| onReset, | ||
| resetDisabled, | ||
| applyDisabled, | ||
| renderPick, | ||
| renderSql, | ||
| 'data-testid': testId, | ||
| }: { | ||
| /** The muted side of the split button, such as Columns or Sort. */ | ||
| name: string; | ||
| /** Desktop value: a field name, "3 fields", or "none". */ | ||
| summary: string; | ||
| /** How many fields the summary counts. */ | ||
| count: number; | ||
| /** The clause is still the source default, so the value is quiet. */ | ||
| dimmed?: boolean; | ||
| /** The full clause, shown on hover since the value only summarizes it. */ | ||
| title: string; | ||
| /** The tab to show each time the popover opens. */ | ||
| initialMode: ClauseMode; | ||
| /** Reset the caller's draft to the current value. */ | ||
| onOpen: () => void; | ||
| onApply: () => void; | ||
| /** Restore the source default in the draft. Apply still has to confirm it. */ | ||
| onReset: () => void; | ||
| resetDisabled?: boolean; | ||
| /** An empty clause is stored as the source default, so Apply cannot submit one. */ | ||
| applyDisabled?: boolean; | ||
| renderPick: (apply: () => void) => ReactNode; | ||
| renderSql: (apply: () => void) => ReactNode; | ||
| 'data-testid': string; | ||
| }) { | ||
| const [opened, setOpened] = useState(false); | ||
| const [mode, setMode] = useState<ClauseMode>(initialMode); | ||
|
|
||
| const open = () => { | ||
| onOpen(); | ||
| setMode(initialMode); | ||
| setOpened(true); | ||
| }; | ||
|
|
||
| const apply = () => { | ||
| if (applyDisabled) return; | ||
| onApply(); | ||
| setOpened(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <Popover | ||
| opened={opened} | ||
| onChange={setOpened} | ||
| position="bottom-start" | ||
| width={440} | ||
| shadow="md" | ||
| withinPortal | ||
| > | ||
| <Popover.Target> | ||
| <SplitValueButton | ||
| name={name} | ||
| summary={summary} | ||
| count={count} | ||
| dimmed={dimmed} | ||
| title={title} | ||
| onClick={() => (opened ? setOpened(false) : open())} | ||
| data-testid={testId} | ||
| /> | ||
| </Popover.Target> | ||
| <Popover.Dropdown data-testid={`${testId}-popover`}> | ||
| <Stack gap="sm"> | ||
| <SegmentedControl | ||
| size="xs" | ||
| fullWidth | ||
| value={mode} | ||
| onChange={value => setMode(value === 'sql' ? 'sql' : 'pick')} | ||
| data={MODE_OPTIONS} | ||
| data-testid={`${testId}-mode`} | ||
| /> | ||
| {mode === 'pick' ? renderPick(apply) : renderSql(apply)} | ||
| <Group justify="space-between" gap="xs" wrap="nowrap"> | ||
| <Button | ||
| variant="link" | ||
| size="xs" | ||
| onClick={onReset} | ||
| disabled={resetDisabled} | ||
| data-testid={`${testId}-reset`} | ||
| > | ||
| Reset to default | ||
| </Button> | ||
| <Group gap="xs" wrap="nowrap"> | ||
| <Button | ||
| variant="secondary" | ||
| size="xs" | ||
| onClick={() => setOpened(false)} | ||
| > | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| variant="primary" | ||
| size="xs" | ||
| onClick={apply} | ||
| disabled={applyDisabled} | ||
| data-testid={`${testId}-apply`} | ||
| > | ||
| Apply | ||
| </Button> | ||
| </Group> | ||
| </Group> | ||
| </Stack> | ||
| </Popover.Dropdown> | ||
| </Popover> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 — ClausePopover is a second copy of the Group by popover shell
SearchGroupBySelect.tsx:109-189already has the same shell: a split button target, a Fields/SQLSegmentedControl, the draft reset on open, and Reset to default / Apply buttons. Now thatClausePopoverexists, the two will drift; they already differ in Cancel vs Clear and in thesubtlevslinkvariant for Reset. MoveSearchGroupBySelectontoClausePopoverso all three toolbar clauses share one shell.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