Skip to content

Mount Columns and Sort on the search page - #3432

Open
elizabetdev wants to merge 26 commits into
mainfrom
elizabet/search-columns-sort
Open

elizabetdev wants to merge 26 commits into
mainfrom
elizabet/search-columns-sort

Conversation

@elizabetdev

@elizabetdev elizabetdev commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Moves SELECT and ORDER BY off the query form. On a results search, Columns and Sort sit on the results table and edit those clauses. Event Deltas and Event Patterns do not show them. On a form narrower than 900px, the where clause and the time controls each take a full row, with the where clause first. Columns and Sort wrap with the table actions instead of overlapping them.

The editors landed in #3431.

Screenshots were not captured.

Screenshots or video

Screenshot 2026-11-19 at 16 39 30

How to reproduce

Starting point: yarn app:dev:local connected to the demo server, or the Vercel preview. Open a log search and run it.

On main:

  1. The query form has SELECT and ORDER BY fields.
  2. The results table has no Columns or Sort button.

On this branch:

  1. The query form has no SELECT or ORDER BY field. Group by is still there.
  2. Above the results table, Columns and Sort are next to the table controls.
  3. Click Columns. Fields lists the columns; SQL edits the SELECT clause. Reset, then Apply. A removed column is dropped from the sort when it is one of the sort fields.
  4. Click Sort. Fields lists sort fields with direction; SQL edits the ORDER BY clause. Apply runs the search.
  5. Narrow the window below 900px. The where clause takes the first row and the time controls wrap onto the next. Columns and Sort wrap with the table controls; a multi-field summary shows only the count.

How to test on Vercel preview

Preview routes: /search

Steps:

  1. Open /search, choose a log source, and run the search.
  2. Confirm the query form has no SELECT or ORDER BY field.
  3. Confirm Columns and Sort appear with the results table controls.
  4. Click Columns. Confirm Fields and SQL are shown, then click Cancel.
  5. Click Sort. Confirm Fields and SQL are shown, then click Cancel.
  6. Confirm Group by is still in the query form.

References

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

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Diff size: 975 production lines changed (Tier 2 max: < 250)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 10
  • Production lines changed: 975 (+ 820 in test files, excluded from tier calculation)
  • Branch: elizabet/search-columns-sort
  • Author: elizabetdev

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

@github-actions

github-actions Bot commented Oct 21, 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 107 in total (1.12%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

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 — Columns and Sort pickers never offer Timestamp or other DateTime fields, nor whole Map/JSON columns

getSqlSourceKeys/getSqlSourceColumnKeys (packages/app/src/components/AdhocDashboardFilter/useAdhocFilterOptions.ts:63-88) belong to the ad hoc filter. They drop every key where isAdhocComparableDataType (common-utils/src/filters.ts:963, !/\bDateTime/) is false, and they skip non-scalar top-level columns. So Timestamp/TimestampTime, the most common sort fields, never show up under 'Add sort' or 'Search columns', and neither does a whole column such as LogAttributes. Build the clause options from all columns plus map/JSON subpaths without the DateTime filter. Add a hook test with a DateTime64 column. The popover tests pass a hardcoded fieldOptions=['Body','Timestamp'], so they cannot catch this.

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

isFieldMetadataDisabled || fields == null
? getSqlSourceColumnKeys(columns)
: getSqlSourceKeys(fields, columns);
return Array.from(

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; the second toQuotedClickHouseKeyExpression pass and its knownColumns set can't change anything

getSqlSourceKeys and getSqlSourceColumnKeys already run every key through toQuotedKeys → toQuotedClickHouseKeyExpression (useAdhocFilterOptions.ts:54-57), and that function leaves already-quoted input alone. Drop the extra .map(...) and the knownColumns set, and just dedupe and sort the keys.

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 21, 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:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • 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
    priority. Reply with one sentence; if it is P0, 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.

3 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 1 P3

Already reported on an earlier push — no new comments. 3 unchanged from an earlier push (already inline above).


Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@elizabetdev
elizabetdev changed the base branch from main to elizabet/column-sort-editors October 21, 2026 15:59
@elizabetdev
elizabetdev added this pull request to stack #3433 October 21, 2026 16:00
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 474 passed • 1 skipped • 1133s

Status Count
✅ Passed 474
❌ Failed 0
⚠️ Flaky 11
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

Scope: PR #3432 — mounts the SELECT (Columns) and ORDER BY (Sort) clause editors as popovers on the results-table toolbar (results mode only), refactors the alias-stripping/sort-fallback helpers in utils.ts, adds in-place column editing and a discard-confirm flow, and reworks the narrow-screen form layout. Diff base ef88a9d3.

Intent (author-stated, advisory): move clause editing off the query form onto the results table without regressing saved-search behavior or sort cleanup when columns are removed.

✅ No critical issues found. The core orderByAfterRemovingSelectItems fallback chain (form sort → saved-search sort → source default) was traced branch-by-branch and is internally consistent, including the "empty ORDER BY means use the fallback" case. The previously-flagged P1 (a bare message DESC sort surviving removal of upper(Body) AS message) is fixed — orderByWithoutAliases now matches bare, double-quoted, and backtick-quoted alias forms — and the new behavior is covered by the utils.test.ts additions. All prior review threads (phone toolbar overlap, dropdown-add, in-place edit, confirm-on-discard) are addressed in the code at HEAD.

🟡 P2 — recommended

  • packages/app/src/components/SearchResultsToolbar/ClausePopover.tsx:60 — nestedListHandlesEscape decides whether to let Escape through by matching hardcoded third-party DOM internals ([data-combobox-dropdown], [role="listbox"], .cm-tooltip-autocomplete, .cm-editor); a Mantine or CodeMirror upgrade that renames any of these silently flips Escape back to closing the popover and discarding the draft, with no test guarding the behavior.
    • Fix: add an integration test asserting Escape closes an open completion/autocomplete list without dismissing the popover, so a library upgrade that breaks the selectors fails loudly.
🔵 P3 nitpicks (2)
  • packages/app/src/components/SearchResultsToolbar/ColumnsPopover.tsx:156 — the dirty flag includes search.trim() !== '', so leaving un-submitted text in the add-column search field makes an outside click prompt "Discard unsaved changes?" even though that text was never part of the clause draft.
    • Fix: exclude the transient search field from dirty, or clear it before the dirty check, so only real clause edits trigger the confirm.
  • packages/app/src/components/SearchResultsToolbar/SortableColumn.tsx:97 — onBlur={() => finishEdit(editText)} commits the in-place edit on every blur; combined with the Enter/Escape handlers this relies on finishedRef to dedupe, which works but couples two unmount-ordering assumptions that are easy to break in later edits.
    • Fix: add a focused test for the blur-after-Enter and blur-after-Escape paths to pin the single-commit guarantee.

Reviewers (3): correctness (orchestrator trace of utils.ts fallback branches), maintainability, previous-comments. Learnings research found no applicable prior solutions (the app has no docs/solutions/ knowledge base yet).

Testing gaps: No automated coverage asserts the Escape-passthrough behavior survives a Mantine/CodeMirror DOM change; the in-place-edit blur-vs-Enter-vs-Escape single-commit path is exercised only indirectly.

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

Comment thread packages/app/src/DBSearchPage.tsx Resolved
Comment thread packages/app/src/DBSearchPage.tsx Resolved
</>
);
};
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 — applySelect repeats toggleColumn's logic for pruning ORDER BY

applySelect repeats toggleColumn's steps (lines 1838-1872): set select, read orderBy with getValues, call orderByAfterRemovingSelectItem with defaultSearchConfig.orderBy, then setValue('orderBy'). Move this into one helper, for example pruneOrderByForRemovedItems(items), and call it from both places, so a change to the pruning rule cannot reach only one of them.

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

@changeset-bot

changeset-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2d920b5

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

@vercel

vercel Bot commented Oct 21, 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 Nov 23, 2026 5:28pm UTC
hyperdx-storybook Ready Ready Preview Nov 23, 2026 5:28pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect the search page and its results-table workflow.

Fix sort cleanup for removed aliases before merging.

Fix All in Claude CodeFindings

  1. P1 Removed columns leave broken sorts ▶

Summary

Moves SELECT and ORDER BY into Columns and Sort popovers above search results.

  • Search results put Columns and Sort beside the table.
  • Table actions stay above the results while the table scrolls.
  • Narrow search forms put WHERE above the time controls.

The earlier toolbar-overlap thread is addressed by wrapping the controls. elizabetdev kept the where field first to preserve reading order; Greptile agreed that this matches the updated description. Both supplied threads are unnumbered.

Reviews (6) · Last reviewed commit: "fix(app): keep the clause footer above t..." · Reviewed by Greptile

Base automatically changed from elizabet/column-sort-editors to main October 23, 2026 11:59
SELECT and ORDER BY move off the query form onto the results table, and the
where row wraps under the time controls on a narrow form.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jordan-simonovski
jordan-simonovski force-pushed the elizabet/search-columns-sort branch from 2096af9 to b5442e5 Compare October 23, 2026 11:59
@github-actions github-actions Bot added review/tier-3 Standard — full human review required and removed review/tier-4 Critical — deep review + domain expert sign-off labels Oct 23, 2026
Comment thread packages/app/src/DBSearchPage.tsx Resolved
);
};
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 — applySelect repeats the ORDER BY pruning that toggleColumn already does

Lines 2307-2316 copy the getValues('orderBy') → orderByAfterRemovingSelectItem(..., defaultSearchConfig.orderBy) → setValue('orderBy') sequence from toggleColumn at lines 1851-1860. Move it into one local helper, for example pruneOrderByForRemoved(items: string[]), and call it from both, so the two column-removal paths 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

Columns, Sort, and the table actions move onto another line instead of
overlapping when the results panel is narrow.

Co-authored-by: Cursor <cursoragent@cursor.com>
Apply stores an empty SELECT or sort when the draft matches the default. On a saved search the default is the saved clause, so Update wrote the source default SELECT and cleared the sort. Save the clause the results table runs: the saved one when the form is blank, else the source default.

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

Copy link
Copy Markdown
Member

If I click a dropdown, I shouldn't have to hit "Add" imo - feels like an extra unnecessary click

Screenshot 2026-11-23 at 8 27 13 AM

@brandon-pereira

Copy link
Copy Markdown
Member
Screenshot 2026-11-23 at 8 28 49 AM

another idea: you can't edit a field currently, ex I wanted to change the alias for tz but couldn't unless I went to sql

Picking a suggestion in the Columns popover only filled the input, so
adding a column took a second click on Add. It now adds the column right
away, the same way the Sort popover does. Add stays for typed expressions.

Rows in the column list can now be edited in place, so an alias such as
tz can be renamed without switching to the SQL tab. Escape in the edit
field cancels the edit without discarding the popover draft.
@elizabetdev

Copy link
Copy Markdown
Member Author

Re this comment: fixed in 2f7bd71.

Picking a suggestion in the Columns popover now adds the column right away, like Sort does. Map keys still get their alias. Add stays for typed expressions such as upper(Body) as message.

@elizabetdev

elizabetdev commented Nov 23, 2026 •

Copy link
Copy Markdown
Member Author

Re this comment: fixed in 2f7bd71.

Columns in the list can now be edited in place. Click a column, or its pencil icon, change the expression (for example the tz alias), then press Enter or click away. Escape cancels the edit without discarding the rest of the draft, and an empty value reverts instead of removing the column.

// Lets ClausePopover pass Escape through instead of discarding.
data-handles-escape
data-testid="search-columns-edit-input"
/>

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 — An unfinished inline column edit is lost without a prompt when the user clicks outside the popover

The inline edit is only written to ColumnsPopover's draft on blur. Mantine's click-outside handler runs on mousedown, which fires before the input loses focus, so requestClose sees dirty === false and closes the popover. The blur-time onEdit then runs on a closed popover, and the next onOpen overwrites the draft. To fix it, report the in-progress edit up to ClausePopover so it counts toward dirty (for example an onEditingChange(dirty) callback), or commit the edit on pointerdown/mousedown outside the row before ClausePopover reads dirty.

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
if (aliases.length === 0) return undefined;
// An alias can be written bare, double-quoted, or backtick-quoted in ORDER BY
const aliasKeys = new Set(
aliases.flatMap(alias => [alias, `"${alias}"`, `\`${alias}\``]),

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 — Matching bare aliases now drops sorts on real table columns

orderByWithoutAliases now also matches the unquoted alias. This affects both the header toggle (toggleColumn → orderByAfterRemovingSelectItem) and Columns Apply. Example: SELECT Timestamp, lower(ServiceName) AS ServiceName with sort ServiceName ASC. Removing that item resets the sort to the default, even though ServiceName is still a real column ClickHouse can sort by. Fix: skip the bare form when the alias is in knownColumns, or only strip the bare form when it is not a source column.

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

Conflicts were in three test files:
- searchFilters.test.ts and filterSources.test.ts: both sides fixed the same
  lint warnings. Took main's version, so this PR no longer touches them.
- utils.test.ts: kept this PR's imports and dropped
  orderByStringToSortingState and sortingStateToOrderByString, which main
  removed from utils.ts in #3746.

Committed with --no-verify: the pre-commit oxlint check counts every line
merged from main as new and flagged 5 warnings in code this PR does not touch.
The inline edit field was a single-line input, so a long expression such
as a map key with an alias scrolled sideways and was hard to edit. Use an
auto-growing textarea in the same monospace font and wrapping as the row,
and place the caret at the end. Pasted line breaks are collapsed to spaces
because a column is a single expression.
Long column names such as LogAttributes['browser.resource_timing...'] were
clipped in the suggestion list, and the clipped part is the part that
tells similar names apart. Let options wrap and widen the dropdown, capped
to stay inside the popover.
The inline column edit only reached the popover draft on blur, but the
click-outside check runs on mousedown, before blur. A click outside the
popover during an edit therefore closed it with no prompt. Unadded search
text had the same gap.

The edit now lives in ColumnsPopover, so an edit with a changed value and
search text not yet added count as unsaved. Escape in the edit field still
cancels only that edit, as before.

Escape while the suggestion list is open also prompted once search text
counted as unsaved. The list is a sibling of its input, so the Escape check
missed it. The check now also looks for an open listbox in the same popover.
@brandon-pereira

Copy link
Copy Markdown
Member

LGTM - Ideally we should get a second review (cc @teeohhem) plus - can we make sure product is aligned (Mike or Alex) if not already?

@elizabetdev

Copy link
Copy Markdown
Member Author

Thanks, @brandon-pereira. Yes, @alex-fedotyev is aligned on this, and I’ve already shown it to Mike. I’ll wait for @teeohhem’s review.

@elizabetdev
elizabetdev requested review from teeohhem and a balanced review from Copilot and removed request for Copilot November 24, 2026 15:57

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 2d920b57 Deployed Nov 23, 2026 by vercel[bot]
Preview – hyperdx-storybook — 2d920b57 Deployed Nov 23, 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-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants