Repository navigation
Mount Columns and Sort on the search page - #3432
elizabetdev wants to merge 18 commits into
Conversation
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Review process: Full human review — logic, architecture, edge cases. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
| 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 = |
There was a problem hiding this comment.
🟠 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( |
There was a problem hiding this comment.
🔵 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
PR Review
2 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 1 P3 No inline comments. 1 P3 folded at the bottom. 1 unchanged from an earlier push (already inline above). 🔵 1 P3 — no action needed before merge
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. |
E2E Test Results✅ All tests passed • 475 passed • 1 skipped • 1257s
Tests ran across 4 shards in parallel. |
Deep ReviewScope: PR #3432 — moves Intent: On a results search, Columns and Sort sit on the table and edit those clauses; Event Deltas/Patterns hide them; narrow forms stack the where-clause above the time controls; removing a column drops a now-dangling sort on its alias. ✅ No critical issues found. The previously-flagged P1 "removed columns leave broken sorts" is genuinely fixed and well-tested: 🟡 P2 — recommended
🔵 P3 nitpicks (2)
Review dimensions applied: correctness, adversarial, TypeScript, frontend-races, testing, maintainability, previous-comments, project-standards. Testing gaps: No direct assertion for 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 |
| </> | ||
| ); | ||
| }; | ||
| const applySelect = useCallback( |
There was a problem hiding this comment.
🔵 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 detectedLatest commit: a307dc2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
[Medium impact] The changes affect the search page and its results-table workflow. Fix sort cleanup for removed aliases before merging.
|
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>
2096af9 to
b5442e5
Compare
| ); | ||
| }; | ||
| const applySelect = useCallback( | ||
| (select: string, removedItems: string[]) => { |
There was a problem hiding this comment.
🔵 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>
| // is shown as this default, so it has to follow the dropdown, the same way | ||
| // the sort default follows useDefaultOrderBy(inputSource). | ||
| const savedSelect = | ||
| savedSearchId && |
There was a problem hiding this comment.
🔵 minor — Default SELECT is now worked out in two places that can disagree
savedSelect/sourceDefaultSelect repeat the saved-search guards and the Log/Trace defaultTableSelectExpression lookup from defaultSearchConfig (lines 1215-1238). The only difference is that this copy keys off inputSourceObj while the original keys off searchedSource. Table-header column removal (displayedColumns/toggleColumn, line 1837) and the Columns popover therefore start from different defaults until the debounced submit catches up. Fix: derive the default SELECT once (or have defaultSearchConfig.select follow the input source) and use that value in both places.
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( |
There was a problem hiding this comment.
🔵 minor — applySelect copies toggleColumn's sort-pruning logic
The loop that calls orderByAfterRemovingSelectItem(item, getValues('orderBy'), defaultSearchConfig.orderBy) and then writes orderBy repeats toggleColumn (lines 1856-1866). The two paths that remove a column can drift apart. Fix: move 'set the select, prune the sort for removed items, submit' into one callback and call it from both places.
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( |
There was a problem hiding this comment.
🔵 minor — The page-level apply logic has no test
Both DBSearchPage suites mock ColumnsPopover, SortPopover and useClauseFieldOptions with stubs. Nothing checks that applying Columns writes select, drops removed aliases from orderBy (falling back to the default sort), and submits, or that Sort writes orderBy. Fix: add a page-level test with a real (or callback-capturing) ColumnsPopover that calls onApply with removed items, then 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
| // The SQL completion list overflows the editor onto these buttons. | ||
| // Fields mode uses an in-popover Autocomplete, which must stay above them. | ||
| style={ | ||
| mode === 'sql' |
There was a problem hiding this comment.
🔵 minor — In SQL mode the button row covers the autocomplete list
Giving the Reset/Cancel/Apply row z-index: var(--mantine-z-index-max) in SQL mode puts it above the CodeMirror completion list. Suggestions that overflow onto that row are hidden and can't be clicked. The new e2e applyClause helper has to work around this. Fix: give the popover body enough room, or let the completion tooltip render above the footer (e.g. portal it or position it above the editor), instead of burying it.
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
|
The P1 in the summary above is fixed. Removing This summary still describes the October 26 review ( |
The popovers had a fixed 440px width, so on a phone the dropdown ran past the right edge and clipped Apply. Cap the width to the viewport and let shift slide the dropdown left of the button when there is not enough room on the right. Co-authored-by: Cursor <cursoragent@cursor.com>
| inputSourceObj?.kind === SourceKind.Trace | ||
| ? inputSourceObj.defaultTableSelectExpression | ||
| : undefined; | ||
| const defaultSelect = savedSelect ?? sourceDefaultSelect ?? ''; |
There was a problem hiding this comment.
🔵 minor — defaultSelect re-implements the saved-search/source default from defaultSearchConfig.select
Lines 1215-1238 already gate on savedSearchId, savedSearch id, and source, then fall back to defaultTableSelectExpression. The copy differs only in using inputSourceObj instead of searchedSource, so there are now two hand-synced definitions of 'the default SELECT'. Fix: derive both from one helper that takes the source object, or add an inputSelect field to the defaultSearchConfig memo.
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
findByTestId does not take a hidden option in this Testing Library, so the lint job's type check failed on the new assertion. Co-authored-by: Cursor <cursoragent@cursor.com>
| inputSourceObj?.kind === SourceKind.Trace | ||
| ? inputSourceObj.defaultTableSelectExpression | ||
| : undefined; | ||
| const defaultSelect = savedSelect ?? sourceDefaultSelect ?? ''; |
There was a problem hiding this comment.
🔵 minor — Default SELECT is now worked out in two places that must stay in sync
savedSelect/sourceDefaultSelect repeat the saved-search checks (id match, source match) and the Log/Trace defaultTableSelectExpression fallback from defaultSearchConfig (DBSearchPage.tsx:1215-1238). The only difference is which source is used: inputSourceObj here, searchedSource there. Move this into one helper that takes the source, e.g. resolveDefaultSelect(savedSearch, savedSearchId, source), and call it from both places so a future change to the default rules updates both.
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( |
There was a problem hiding this comment.
🔵 minor — applySelect copies toggleColumn's logic for dropping sorts on removed columns
The getValues('orderBy') → orderByAfterRemovingSelectItem(..., defaultSearchConfig.orderBy) steps are the same ones toggleColumn already runs at DBSearchPage.tsx:1856-1866. Add a shared orderByAfterRemovingSelectItems(items, orderBy, default) in utils.ts and call it from both. Also skip the unconditional setValue('orderBy', ...) when the value did not change, as toggleColumn does.
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( |
There was a problem hiding this comment.
🔵 minor — No test covers the new page wiring (applySelect / applyOrderBy / defaultSelect)
Both DBSearchPage suites mock ColumnsPopover, SortPopover and useClauseFieldOptions as empty stubs, so none of the code this PR adds to the page runs: dropping sorts on removed columns, falling back to the default sort, and choosing defaultSelect when the dropdown source differs from the searched one. Add a page-level test that runs onApply with removed items and checks the submitted orderBy/select.
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
- Escape closed the popover and asked to discard a dirty SQL draft even when it was only meant to dismiss the completion list. Let CodeMirror take Escape while a completion is open. - A saved search's sort is also the fallback sort, so removing an aliased column could restore the alias it just dropped. Strip removed aliases from the fallback too, and handle several removed items in one pass. - The Columns and Sort elements were rebuilt on every page render, so each where keystroke handed the results table a new element and defeated its memo. Memoize them. Co-authored-by: Cursor <cursoragent@cursor.com>
…is empty An empty form ORDER BY means "use the saved sort". The helper treated the empty string as already clean, so removing an aliased column after resetting Sort left the saved alias sort in the query and it failed on an unknown identifier. Run the empty case through the same alias removal. Co-authored-by: Cursor <cursoragent@cursor.com>
The popover handles Escape before the input does, so closing the column or sort suggestions also closed the popover and dropped the text that had not been added yet. Skip that close while the suggestion list is open. Co-authored-by: Cursor <cursoragent@cursor.com>
Changing an aliased column's expression or the case of AS (for example upper(Body) AS message to lower(Body) AS message) counted the old item as removed. The sort on the alias was then dropped even though the alias was still selected. Ignore a removed item whose alias is still in the new SELECT. Co-authored-by: Cursor <cursoragent@cursor.com>
| wrap="wrap" | ||
| // The SQL completion list overflows the editor onto these buttons. | ||
| // Fields mode uses an in-popover Autocomplete, which must stay above them. | ||
| style={ |
There was a problem hiding this comment.
🟡 P2 — SQL-mode footer at max z-index covers the completion entries it overlaps
The comment says the CodeMirror completion list spills onto the footer. Raising the Reset/Cancel/Apply row to --mantine-z-index-max puts those buttons on top of the list (.cm-tooltip is z-index 100 in the same dropdown stacking context). On a short Sort editor, completion entries under the buttons can't be seen or clicked. Keep the footer below the tooltip. If Apply has to stay clickable, use tooltips({ position: 'fixed', parent }) or reserve space under the editor instead of stacking the buttons over the list.
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
There was a problem hiding this comment.
Not changing this. Apply has to stay reachable when the completion list is open, so the footer stays above the list. Raising the .cm-tooltip above it would also cover the Reset/Cancel/Apply row. Left as is.
| if (availableWidth > 0) { | ||
| elements.floating.style.maxWidth = `${availableWidth}px`; | ||
| } | ||
| if (availableHeight > 0) { |
There was a problem hiding this comment.
🟡 P2 — maxHeight from the size middleware has no effect without overflow
Mantine's Popover.Dropdown sets no overflow. Content taller than availableHeight therefore spills past the capped box, and on a short viewport Apply still ends up off screen. Add overflowY: 'auto' to the dropdown, or to an inner scroll wrapper that excludes the footer, so the cap actually keeps Apply reachable.
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
There was a problem hiding this comment.
Not changing this. Adding overflow: auto to the dropdown clips the Fields autocomplete and the SQL completion list, which was the earlier overflow thread. The height cap keeps the popover inside the viewport; the list itself can still extend past the popover's box. Left as is.
Apply stores an empty SELECT when the draft matches the default. The alias check then read no aliases from the new SELECT and dropped a sort on an alias the default still defines. Check against the effective SELECT instead. Co-authored-by: Cursor <cursoragent@cursor.com>
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
How to reproduce
Starting point:
yarn app:dev:localconnected to the demo server, or the Vercel preview. Open a log search and run it.On
main:On this branch:
How to test on Vercel preview
Preview routes: /search
Steps:
References