Skip to content

Edit search columns and sort from the results table - #3387

Closed
elizabetdev wants to merge 16 commits into
mainfrom
elizabet/search-table-select-order-by
Closed

elizabetdev wants to merge 16 commits into
mainfrom
elizabet/search-table-select-order-by

Conversation

@elizabetdev

Copy link
Copy Markdown
Member

Summary

SELECT and ORDER BY now belong to the results table. They open from Columns and Sort on the table toolbar, and they stay hidden on Event Deltas and Event Patterns. The source row and the WHERE line are split again so the WHERE clause keeps the width of the row.

  • Columns lists the current SELECT items, with drag-to-reorder and remove. A suggestion or a typed expression, such as upper(Body) as message, is added only when Add is clicked. SQL edits the full SELECT.
  • Sort lists each ORDER BY field and its direction, including a tuple such as (toDateTime(Timestamp), Timestamp) DESC. SQL edits the raw clause. An expression that cannot be split, such as Timestamp DESC NULLS LAST, opens on SQL.
  • Apply writes the clause and runs the search. Cancel discards the draft. Reset to default restores the source default and, on Apply, stores an empty clause so the search keeps following that default.
  • The table actions (reset widths, wrap lines, generated SQL, CSV) sit on the right of that toolbar as subtle icon buttons. The row selection menu sits with Columns and Sort.
  • On the search form, the source is on the left of the first line and Update / Alerts are on the right. The WHERE clause, Live Tail, refresh interval, and Run are on the next line.

I could not capture before/after screenshots from this session. The table below is left for those.

Screenshots or video

Before After

How to reproduce

Starting point: play.hyperdx.io → Search, with the Logs source selected. The same flow works on a Vercel preview (local mode, demo ClickHouse).

On main:

  1. Open Search and run a query so the results table is visible.
  2. Confirm SELECT and ORDER BY are inputs in the form above the WHERE clause, and the results table actions sit in the table header.

On this branch:

  1. Open Search and run a query.
  2. Confirm the first form line is the source on the left and Update or Save plus Alerts on the right, and the WHERE clause has its own line with Live Tail and Run.
  3. On the results table, open Columns. Remove a column, drag one to a new position, type upper(Body) as message, click Add, then Apply. Confirm the table columns match that list.
  4. Open Sort. Confirm the current ORDER BY fields are listed, including a function such as toDateTime(Timestamp) when that is the source default. Change a direction and click Apply.
  5. Open Sort or Columns, click Reset to default, then Apply. Confirm the clause returns to the source default.
  6. Switch to SQL in either popover and confirm the editor shows the real clause, not placeholder text.
  7. Switch the analysis mode to Event Deltas or Event Patterns and confirm Columns and Sort are hidden.

How to test on Vercel preview

Preview routes: /search

Steps:

  1. Open /search and run a search on the Logs source.
  2. Confirm the WHERE clause is on its own line, with the source and Save or Update on the line above.
  3. Open Columns, click Add after choosing a column, then click Apply. Verify the results table shows that column.
  4. Open Sort, change the direction, and click Apply. Verify the row order changes.
  5. Open Columns, click Reset to default, then Apply. Verify the column list matches the source default.
  6. Switch to Event Patterns. Verify Columns and Sort are not shown.

References

  • Linear Issue:
  • Related PRs:

Made with Cursor

elizabetdev and others added 3 commits October 16, 2026 11:56
Those clauses and the table actions belong with the results table.
They stay hidden on Event Deltas and Event Patterns.

Co-authored-by: Cursor <cursoragent@cursor.com>
…table

SELECT and ORDER BY move into Columns and Sort buttons on the results
table toolbar. Each opens a popover with a Pick tab (column list with
add/remove, or field plus asc/desc) and a SQL tab; Apply writes the
clause and runs the search, Cancel discards the draft. Custom ORDER BY
expressions open on the SQL tab.

The table controls become subtle action icons grouped on the right,
with sentence-case tooltips, and the row selection menu sits next to
the clause buttons.

Co-authored-by: Cursor <cursoragent@cursor.com>
Show the source SELECT and ORDER BY as editor text, add a column only
when Add is clicked, and let columns be reordered. Sort pick lists
tuple fields, including function calls. Both popovers can reset to the
source default. The search form keeps WHERE on its own line, with
Update and Alerts at the end of the source row.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Oct 21, 2026 1:30pm UTC
hyperdx-storybook Ready Ready Preview Oct 21, 2026 1:30pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2ac10de

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Minor
@hyperdx/api Minor
@hyperdx/otel-collector Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the review/tier-4 Critical — deep review + domain expert sign-off label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Tier 4 — Critical

Touches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI.

Why this tier:

  • Large diff: 1496 production lines changed (threshold: 1000)

Review process: Deep review from a domain expert. Synchronous walkthrough may be required.
SLA: Schedule synchronous review within 2 business days.

Stats
  • Production files changed: 14
  • Production lines changed: 1496 (+ 937 in test files, excluded from tier calculation)
  • Branch: elizabet/search-table-select-order-by
  • Author: elizabetdev

To override this classification, remove the review/tier-4 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 123 in total (1.61%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@@ -2209,6 +2220,58 @@ function DBSearchPageContent() {
[setValue, setNewSourceModalClosed],

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.

🔵 minor — applySelect re-implements toggleColumn's ORDER BY pruning

The loop of orderByAfterRemovingSelectItem(item, orderBy, defaultSearchConfig.orderBy) followed by setValue('orderBy') and onSubmit() duplicates toggleColumn (DBSearchPage.tsx ~1785-1796). Extract one helper, for example pruneOrderByForRemovedItems(removed, orderBy, default), and call it from both places so the two removal paths can't drift. There is also no test that removing an aliased column in the Columns popover resets an ORDER BY on that alias.

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

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

7 finding(s): 🔴 0 critical · 🟠 1 major · 🔵 6 minor

6 posted as inline comment(s) on the changed lines. 1 listed below.

Findings outside the changed lines

1 minor
  • 🔵 packages/app/src/DBSearchPage.tsx:1833 — SELECT is now split by two different splitters that disagree on backtick-quoted names → The Columns popover splits SELECT with the new splitClauseList, which keeps `a,b` as one item. displayedColumns here still uses splitAndTrimWithBracket, and toggleColumn builds the SELECT from it, so removing a column from the table header still breaks `a,b` into two items. Fix: split with splitClauseList here too, so both paths read the same column list.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; all three numbered findings are addressed.

Summary

Moves SELECT and ORDER BY editing into Columns and Sort popovers on the results table.

  • Search users edit columns and sort from the results table.
  • Table actions stay in a toolbar above the results.
  • The source and search actions share a row above WHERE.
  • Group by, Columns, and Sort share a compact value button.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Columns or Sort] --> B[Edit draft]
  B --> C[Apply]
  B --> D[Cancel]
  C --> E[Update search clause]
  E --> F[Run search]
  D --> G[Discard draft]
Loading

Reviews (11) · Last reviewed commit: "fix(app): keep quoted column names and c..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. The three P1 regressions raised in earlier review rounds (backtick-quoted names mangled on column removal, custom/tuple sorts overwritten, suggested names inserted unquoted) are all confirmed fixed in the current code, and an independent trace of the parsing primitives (splitClauseList, parseSortKeys, orderByAfterRemovingSelectItem) round-trips correctly on the adversarial inputs that previously broke. Agent-native parity is preserved — the popovers only setValue('select'/'orderBy') over the same config fields the MCP tools already expose.

The notes below are test-coverage recommendations, not behavioral defects.

🟡 P2 -- recommended

  • packages/app/src/components/SearchResultsToolbar/sortClause.ts:1 -- New core clause-parsing module (parseSortKeys, serializeSortKeys, sameKeys, sortSummary) has no dedicated unit test; all branches are exercised only transitively through SortPopover DOM tests, leaving edge branches (doubled-backtick escape at :27, single/empty-element tuple guard at :59, blank-id filter at :76) unasserted, so a silent regression in ORDER BY rewriting would not be caught.
    • Fix: Add sortClause.test.ts covering the doubled-backtick escape, (a) DESC / (a, ) DESC tuple guards, and serializeSortKeys dropping blank-id keys.
    • testing
🔵 P3 nitpicks (3)
  • packages/app/src/utils.ts:1302 -- splitClauseList has only a single happy-path test and no empty-input or multiple-backtick-token case.
    • Fix: Add table-driven cases for empty input and multiple backtick-quoted identifiers to the utils.test.ts suite.
  • packages/app/src/components/SearchResultsToolbar/sortClause.ts:86 -- sameKeys length-mismatch and per-key-mismatch branches are asserted only indirectly via the reset-button disabled state.
    • Fix: Add direct unit assertions for sameKeys on mismatched lengths and differing keys.
  • packages/app/src/components/SearchResultsToolbar/SortableColumn.tsx:1 -- The drag-to-reorder-and-serialize path is unverified; tests only assert the reorder handles render.
    • Fix: Add a reorder test (or document the jsdom/dnd-kit limitation) so reorderColumns serialization regressions are caught.

Reviewers (4 of 10 reported): testing, agent-native, learnings-researcher, previous-comments. The correctness, adversarial, maintainability, project-standards, kieran-typescript, and julik-frontend-races reviewers were dispatched but had not returned when output was finalized — their findings are not reflected here. The orchestrator independently traced splitClauseList, replaceBacktickedIdentifiers/restoreReplacements, parseSortKeys/findBalancedParens, and orderByAfterRemovingSelectItem against the known adversarial inputs and found the prior-round fixes intact.

Testing gaps: sortClause.ts is untested directly despite being new parsing logic; splitClauseList and sameKeys are thinly covered; dnd-kit reorder serialization is not exercised in unit tests.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 454 passed • 1 skipped • 1852s

Status Count
✅ Passed 454
❌ Failed 0
⚠️ Flaky 3
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

Co-authored-by: Cursor <cursoragent@cursor.com>
[setValue, setNewSourceModalClosed],
);

const applySelect = useCallback(

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.

🔵 minor — New applySelect ORDER BY clean-up and the toolbar wiring are untested

The popover tests mock onApply, and the DBSearchPage test mocks out both popovers. Nothing checks that removing an aliased column that ORDER BY sorts by resets ORDER BY through orderByAfterRemovingSelectItem. Nothing checks that the new controlsAboveTable toolbar in DBRowTable renders the table controls and the row-selection menu. Add a DBSearchPage or DBRowTable test that applies a SELECT without the sorted alias and asserts the resulting orderBy.

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

Suggested names with spaces or hyphens were inserted raw, an emptied column list snapped back to the source default, and a sort of two tuples was parsed as one broken list.

Co-authored-by: Cursor <cursoragent@cursor.com>
@elizabetdev

Copy link
Copy Markdown
Member Author

The PR still needs fixes for suggested column names that break searches and tuple sorts that become invalid when edited.

Addressed in 87937b3:

  • Suggested names that are not bare identifiers are backtick-quoted before they can be added.
  • A sort of two tuples stays two keys. Parentheses are unwrapped only when they wrap the whole expression.
  • Removing the last column leaves the list empty instead of restoring the source default.
  • Teams with field discovery off still get suggestions for their scalar columns.

The where field and the time group each claimed hundreds of pixels, so Live Tail and Run wrapped while the form was still wide. They now share a row until the form itself is under 900px, the compact layout cutoff.

Co-authored-by: Cursor <cursoragent@cursor.com>
A newline inside a parenthesized sort hid the field controls, because the direction match stopped at the end of the line.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread packages/app/src/DBSearchPage.tsx Resolved
const knownColumns = new Set(columns.map(column => column.name));
// Field discovery is off for some teams, and `useAllFields` then returns
// [] rather than "still loading". Scalar columns are still known.
const keys =

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.

🟠 major — Pick suggestions leave out every DateTime column (Timestamp, TimestampTime), and every Map, Array and JSON column

getSqlSourceKeys/getSqlSourceColumnKeys (AdhocDashboardFilter/useAdhocFilterOptions.ts) were written for ad hoc filters. They drop anything that fails isAdhocComparableDataType, which is !/\bDateTime/ in common-utils/src/filters.ts, and they keep only scalar columns. So Timestamp, the most common sort key, is never offered in Sort or Columns. Build the options from all of columns plus the map and JSON keys, without the ad hoc comparability filter. Also add a DateTime column to the hook test so this is covered.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

}}
data={addOptions}
limit={50}
onOptionSubmit={id => {

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.

🟠 major — "Add sort" only adds a suggested option, so a typed field or expression can never be added

A key is added only through onOptionSubmit, and there is no Add button or Enter handler. Typing toDateTime(Timestamp), or any field missing from fieldOptions (every DateTime column today), then pressing Enter does nothing. Add the free-typed value on Enter or through an Add button, as ColumnsPopover does.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

};

return (
<Popover

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.

🟠 major — Pressing Escape to dismiss SQL autocomplete closes the popover and throws away the draft

Mantine Popover's closeOnEscape handles keydown in the capture phase, before CodeMirror sees it. An Escape meant to close the completion list closes the popover instead, and the next onOpen resets the draft. The e2e helper in SearchPage.ts works around exactly this. Pass closeOnEscape={false} (or skip closing while a CodeMirror completion is active), or keep the draft until Cancel or Apply.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

size="xs"
placeholder="Search columns"
value={search}
onChange={next => {

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.

🔵 minor — The search input rewrites a typed map subscript on every keystroke, so its alias cannot be removed

withMapKeyAlias runs in onChange. As soon as the input matches Col['k'] (when ] is typed, or when the user backspaces the alias away), the value jumps to Col['k'] AS "k" and the cursor moves. Apply the alias only when an option is picked from the dropdown (onOptionSubmit), not on free typing.

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

const count = storedColumns(value).length;
const items = splitAndTrimWithBracket(draft);

const options = useMemo(

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.

🔵 minor — Duplicate and suggestion checks ignore aliases, so an added map key stays suggested and can be added twice

!items.includes(option) and !items.includes(trimmed) compare the raw subscript with the stored Col['k'] AS "k", which never matches. The option stays in the list, and adding it again appends an unaliased duplicate. Use the existing isColumnInSelect from packages/app/src/utils.ts, which matches on selectItemExpression. The useMemo here also depends on items, which is a new array every render, so it never memoizes.

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

setSearch('');
}}
resetDisabled={draft.trim() === defaultValue.trim()}
onApply={() => {

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.

🔵 minor — Applying with every column removed silently restores the source default

With an empty draft, submitted is '', which the page reads as "use source default". The UI shows "No columns selected." and the code comment says an empty draft is not the default, yet the default comes back. Disable Apply while items.length === 0.

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

onApply(
draft.trim() === defaultValue.trim()
? ''
: draft === baseline

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.

🔵 minor — The draft === baseline ? value : draft branch can never change the result (same in ColumnsPopover)

baseline is value || defaultValue. If value is non-empty, draft === baseline means draft === value. If value is empty, an equal draft was already caught by the default check. Simplify to draft.trim() === defaultValue.trim() ? '' : draft in both popovers.

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

: getSqlSourceKeys(fields, columns);
return Array.from(
new Set(
keys.map(key => toQuotedClickHouseKeyExpression(key, knownColumns)),

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.

🔵 minor — Keys are quoted twice

getSqlSourceKeys and getSqlSourceColumnKeys already pass every key through toQuotedClickHouseKeyExpression (toQuotedKeys in useAdhocFilterOptions.ts). The second pass is a no-op because the function is idempotent, and so is the extra knownColumns set. Drop both and just dedupe and sort.

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

/** Restore the source default in the draft. Apply still has to confirm it. */
onReset: () => void;
resetDisabled?: boolean;
renderPick: (apply: () => void) => ReactNode;

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.

🔵 minor — The apply argument passed to renderPick is never used

Neither ColumnsPopover nor SortPopover reads the apply passed to renderPick, because only the SQL tab submits on Enter. Change it to renderPick: () => ReactNode.

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

<Stack gap="xs">
<Box mah={220} style={{ overflowX: 'hidden', overflowY: 'auto' }}>
{items.length === 0 ? (
<Text size="xs" c="dimmed">

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.

🔵 minor — Ad hoc empty state uses Text c="dimmed"

This breaks the EmptyState (REQUIRED) rule and the semantic-token rule in the repository conventions. Render <EmptyState title="No columns selected" /> from @/components/EmptyState instead of raw dimmed text.

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

Removing an aliased column left it in a multi-field sort, a comma inside a backtick-quoted name was split, and typing a map key rewrote the input. The time controls also wrap so Run stays visible on a narrow screen.

Co-authored-by: Cursor <cursoragent@cursor.com>
@elizabetdev

Copy link
Copy Markdown
Member Author

Addressed in 0e8a7ae:

  • Removing an aliased column now drops only the sort keys that use that alias, including when the sort has more than one field.
  • A comma inside a backtick-quoted sort name stays on the SQL tab, so Pick does not split it.
  • The time controls wrap and the picker shrinks, so Run stays visible on a narrow screen.
  • A map key is aliased only when that suggestion is picked, not while it is typed.

);
};

const addKey = (id: string) => {

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.

🟠 major — Adding a sort key on a custom ORDER BY silently replaces the whole clause

If the ORDER BY cannot be parsed (for example Timestamp DESC NULLS LAST), keys is null. The Pick tab then says "Custom sort. Edit it in SQL." but still shows the "Add sort" input (line 262). Picking a field there calls addKey, which runs commitKeys([...(keys ?? []), new]), so the draft becomes just Body DESC and Apply throws the custom sort away. Fix: hide or disable the Add sort input when keys == null, and add a test that covers this case.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

};

return (
<Popover

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.

🟠 major — Pressing Escape to dismiss SQL autocomplete closes the popover and discards the draft

The Popover keeps Mantine's default closeOnEscape. Pressing Escape inside the SQL tab's CodeMirror editor, which is the usual way to close its autocomplete, closes the whole popover and loses the unapplied SELECT or ORDER BY edit. The PR's own page object works around this (tests/e2e/page-objects/SearchPage.ts: "Blur rather than Escape: Escape also closes the popover, dropping the draft"). Fix: pass closeOnEscape={false}, or ignore Escape while a .cm-tooltip-autocomplete is open.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond


const count = storedColumns(value).length;
const items = splitAndTrimWithBracket(draft);

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.

🔵 minor — Backtick-quoted SELECT items containing a comma get split and rewritten in Columns Pick

splitAndTrimWithBracket (common-utils/src/core/utils.ts:132) does not treat backticks as quotes. SortPopover guards against this with its own local hasCommaInsideBackticks, but ColumnsPopover does not. A SELECT such as `a,b`, Body becomes the items `a and b`, and any remove or reorder writes back `a, b`, which is a different identifier. Fix: make splitAndTrimWithBracket skip commas inside backticks so every caller gets it, and drop the local guard in SortPopover.

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

<Box mah={220} style={{ overflowX: 'hidden', overflowY: 'auto' }}>
{items.length === 0 ? (
<Text size="xs" c="dimmed">
No columns selected.

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.

🔵 minor — Ad-hoc inline empty state violates the REQUIRED EmptyState rule

The "No columns selected." message is a bare <Text size="xs" c="dimmed">. The conventions say to use EmptyState (@/components/EmptyState) for all empty and no-data states. Render <EmptyState title="No columns selected" /> here instead, with no trailing period in the title.

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

opened={opened}
onChange={setOpened}
position="bottom-start"
width={440}

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.

🔵 minor — Fixed 440px popover width overflows phone viewports

This PR removed the compact-viewport Columns toggle, so on phones the Columns and Sort editors are now only these popovers, and they always render at width={440}. On a 375px-wide phone, Mantine's shift can move the dropdown but cannot shrink it, so part of the dropdown, including Apply, sits off-screen. Fix: cap the width, for example width="min(440px, calc(100vw - 16px))", or set a maw on the Dropdown.

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

const count = storedColumns(value).length;
const items = splitAndTrimWithBracket(draft);

const options = useMemo(

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.

🔵 minor — options useMemo never memoizes because items is a new array every render

items = splitAndTrimWithBracket(draft) creates a new array on every render, so useMemo(..., [fieldOptions, items]) recomputes every time. Either memoize items on draft, or remove the useMemo and compute options inline.

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

/** Restore the source default in the draft. Apply still has to confirm it. */
onReset: () => void;
resetDisabled?: boolean;
renderPick: (apply: () => void) => ReactNode;

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.

🔵 minor — renderPick's apply argument is never used

renderPick is passed apply, but neither caller (ColumnsPopover and SortPopover both use renderPick={() => ...}) reads it. Change the type to renderPick: () => ReactNode and render renderPick(), or remove the prop and pass the pick content as a ReactNode.

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

Comment thread packages/app/src/utils.ts Resolved
elizabetdev and others added 2 commits October 21, 2026 12:33
A field count collapses to a number on a narrow screen so the three controls still fit. Storybook records when to use each clause.

Co-authored-by: Cursor <cursoragent@cursor.com>
Splitting the remaining ORDER BY on every comma rewrote `a,b` as `a, b`. Sort parsing now lives beside the popover so the component stays under 300 lines.

Co-authored-by: Cursor <cursoragent@cursor.com>
const keys =
isFieldMetadataDisabled || fields == null
? getSqlSourceColumnKeys(columns)
: getSqlSourceKeys(fields, columns);

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.

🟠 major — Columns and Sort suggestions never include Timestamp or any other DateTime column, or whole Map/JSON columns

getSqlSourceKeys and getSqlSourceColumnKeys (AdhocDashboardFilter/useAdhocFilterOptions.ts) were written for ad-hoc filters. They drop every type that matches isAdhocComparableDataType (common-utils/src/filters.ts:963, which rejects /\bDateTime/), and they also drop whole non-scalar columns. So Timestamp/TimestampTime can't be picked in “Add sort”, which is the most common sort key, and LogAttributes can't be added as a column. Build the options from the fields/columns without the ad-hoc comparability filter. Add a hook test with a DateTime64 column. The popover tests miss this because they hand-pass 'Timestamp' in fieldOptions.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

setSearch('');
};

const removeColumn = (item: string) => {

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.

🔵 minor — Removing one of two identical SELECT items removes both

removeColumn filters by value (items.filter(i => i !== item)). For a SELECT such as Timestamp, Body, Body, clicking Remove on one Body row drops every Body. The rows are keyed by index (columnId) precisely because duplicates can exist, so remove by index: items.filter((_, i) => i !== index).

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

setSearch('');
}}
resetDisabled={draft.trim() === defaultValue.trim()}
onApply={() => {

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.

🔵 minor — Applying an empty column list (or an empty sort) silently restores the source default

The comment says an empty draft is not “use the default”, and the picker shows “No columns selected.” But Apply submits '', which the search reads as the source default. The same happens in SortPopover when every key is removed. Disable Apply when the draft is empty, or show the user that empty means default.

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

setSearch('');
}}
resetDisabled={draft.trim() === defaultValue.trim()}
onApply={() =>

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.

🔵 minor — The draft-to-stored-value Apply logic is copied verbatim in ColumnsPopover and SortPopover

Both contain the same draft.trim() === defaultValue.trim() ? '' : draft === baseline ? value : draft rule and the same resetDisabled check, so the “empty means default” contract now lives in two places. Move it into ClausePopover (pass value, defaultValue and draft, and have it compute the stored value) so the two editors can't drift apart.

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

<Stack gap="xs">
<Box mah={220} style={{ overflowX: 'hidden', overflowY: 'auto' }}>
{items.length === 0 ? (
<Text size="xs" c="dimmed">

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.

🔵 minor — Ad-hoc inline empty state violates the EmptyState convention

<Text size="xs" c="dimmed">No columns selected.</Text> is the pattern the REQUIRED EmptyState rule forbids. Use EmptyState from @/components/EmptyState, for example title="No columns selected".

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

const shown = storedColumns(value);
const items = splitAndTrimWithBracket(draft);

const options = useMemo(

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.

🔵 minor — useMemo for options never memoizes because items is a new array on every render

items = splitAndTrimWithBracket(draft) is recomputed on every render, so [fieldOptions, items] changes every time and the memo always reruns. Memoize items on draft, or drop the useMemo.

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

'"service.name" ASC, Timestamp DESC',
'Timestamp DESC',
),
).toBe('Timestamp DESC');

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.

🔵 minor — Multi-key removal test can't tell keeping the remaining key apart from falling back to the default

In the first case the kept key Timestamp DESC is also the defaultOrderBy. An implementation that still returns the default whenever any key matches, which is the old behaviour, would pass. Use a different default (for example 'TimestampTime DESC') so the assertion proves only the alias key was dropped.

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

@elizabetdev

Copy link
Copy Markdown
Member Author

On #3387 (comment)

Fix the sort rewrite and satisfy the two repository requirements before merging.

  • Removing columns changes sort names: fixed in 9978039. Backtick-quoted names are tokenized before the remaining ORDER BY is split.
  • Component exceeds the file size limit: fixed in 9978039. Sort parsing moved to sortClause.ts. SortPopover.tsx is 219 lines.
  • Empty list skips shared styling: declined. EmptyState is a page-scale title and would crowd the column list inside the popover.

The column list split backtick-quoted names on commas, and Add sort replaced a clause the field list could not parse. The column row moved out so ColumnsPopover stays under 300 lines.

Co-authored-by: Cursor <cursoragent@cursor.com>
@elizabetdev

Copy link
Copy Markdown
Member Author

On #3387 (comment)

Fix the column-name rewrite and custom-sort replacement before merging, and satisfy the remaining component requirements.

  • Editing columns changes quoted names: fixed in 2ac10de. The column list tokenizes backtick-quoted names before it splits.
  • Adding fields drops custom sorts: fixed in 2ac10de. Add sort is hidden when the clause cannot be split.
  • Component exceeds the file size limit: fixed in 2ac10de. SortableColumn moved out. ColumnsPopover.tsx is 226 lines.


const addColumn = (column: string) => {
const trimmed = column.trim();
if (trimmed && !items.includes(trimmed)) {

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.

🟠 major — An already-aliased map column can be added a second time

Suppose the SELECT already has LogAttributes['x'] AS "x". Because options and addColumn check with items.includes(...), the bare LogAttributes['x'] is still offered. If the user adds it, withMapKeyAlias sees that the alias x is taken and returns the bare subscript, so the same column ends up in the SELECT twice. Fix: use the existing isColumnInSelect(items, option) from packages/app/src/utils.ts:1253 for both the option filter and the duplicate check. It already matches aliased items by their expression, and toggleColumn in DBSearchPage relies on the same match.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

const trimmed = orderBy.trim();
if (!trimmed) return [];
// A comma inside a backtick-quoted name would be split into extra fields.
if (hasCommaInsideBackticks(trimmed)) return null;

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.

🔵 minor — parseSortKeys adds a second backtick scanner instead of using splitClauseList

hasCommaInsideBackticks repeats work that splitClauseList (packages/app/src/utils.ts, built on replaceBacktickedIdentifiers in common-utils) already does. Because of the bail-out, a sort like (`a,b`, Timestamp) DESC opens on SQL, although the same PR's Columns popover handles that name. The scanner also does not skip string literals the way replaceBacktickedIdentifiers does. Fix: split with splitClauseList, both for the tuple body and for the top-level keys, and delete hasCommaInsideBackticks.

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

onChange={setOpened}
position="bottom-start"
width={440}
shadow="md"

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.

🔵 minor — Fixed 440px popover overflows on phones now that the compact column toggle is gone

This PR removes the compact-viewport handling for SELECT and ORDER BY (columnsOpen and the stacked editors). On compact viewports these popovers now open at a fixed width={440}, which is wider than a typical 375px phone screen, so the Apply and Cancel buttons can render off screen. Fix: cap the width, for example width="min(440px, calc(100vw - 16px))", or switch to width="target" with a max width when useCompactViewport() is true.

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

<Stack gap="xs">
<Box mah={220} style={{ overflowX: 'hidden', overflowY: 'auto' }}>
{items.length === 0 ? (
<Text size="xs" c="dimmed">

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.

🔵 minor — Ad-hoc empty state breaks the EmptyState convention

<Text size="xs" c="dimmed">No columns selected.</Text> is the inline empty-state pattern that the REQUIRED "EmptyState Component" rule forbids. Fix: render <EmptyState title="No columns selected" /> from @/components/EmptyState (headline style, no trailing period) and update the test that queries this text.

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

const shown = storedColumns(value);
const items = splitClauseList(draft);

const options = useMemo(

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.

🔵 minor — useMemo for options never memoizes

items is a new array from splitClauseList(draft) on every render, so the [fieldOptions, items] dependency changes every time and the memo recomputes on each render. Fix: either drop the useMemo, or memoize items on draft (useMemo(() => splitClauseList(draft), [draft])).

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

);
};
const applySelect = useCallback(
(select: string, removedItems: string[]) => {

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.

🔵 minor — New applySelect sort pruning and popover placement have no test

applySelect now prunes ORDER BY in a loop over every removed item and submits. The popovers are also rendered in three places: the empty state, the query error, and the table toolbar. DBSearchPage.directTrace.test.tsx mocks out ColumnsPopover, SortPopover and useClauseFieldOptions, so none of this is exercised. A regression such as passing removedItems wrongly, or editors missing from the error branch, would still pass. Fix: add a DBSearchPage test that uses the real ColumnsPopover. It should remove an aliased column that ORDER BY sorts on and assert the submitted orderBy.

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

@elizabetdev
elizabetdev marked this pull request as draft October 21, 2026 13:39
kodiakhq Bot pushed a commit that referenced this pull request Oct 21, 2026
## Summary

Group by uses a new shared split button: a fixed name, then the current value. On a narrow screen a count such as `3 fields` shows as `3`. A single field still shows its name.

Columns and Sort will use the same button in a follow-up. This PR only switches Group by, so that button can be reviewed on its own. Storybook (`Components/SplitValueButton`) says when to use it.

Related: #3387. Replaces #3429, which closed when the branch moved off the `agent/` prefix.

### Screenshots or video

<img width="599" height="436" alt="Screenshot 2026-10-21 at 15 10 27" src="https://github.com/user-attachments/assets/4c40486d-d015-446b-bc45-269851e0772b" />

On the search page:
<img width="556" height="99" alt="Screenshot 2026-10-21 at 15 14 15" src="https://github.com/user-attachments/assets/f7f77c13-65d9-48c7-9604-540b1b535b8a" />

### How to reproduce

**Starting point:** Vercel preview, or `yarn app:dev:local` connected to the demo server.

**On `main`:**

1. Open Search.
2. Open Group by and select two fields, then Apply.
3. Narrow the window below 900px. The button still reads `2 fields`.

**On this branch:**

1. Open Search.
2. Open Group by and select two fields, then Apply.
3. Narrow the window below 900px. The value shows `2`. One field still shows its name, and an empty selection still shows `none`.

### How to test on Vercel preview

**Preview routes:** /search

**Steps:**

1. Open Group by.
2. Select two fields and click Apply.
3. Verify the button reads Group by and `2 fields` at a desktop width.
4. Narrow the viewport below 900px.
5. Verify the value shows `2`.

### References

- Related PR: #3387


Made with [Cursor](https://cursor.com)

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 2ac10de0 Deployed Oct 21, 2026 by vercel[bot]
Preview – hyperdx-storybook — 2ac10de0 Deployed Oct 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-4 Critical — deep review + domain expert sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant