Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/search-columns-sort-popovers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': minor
---

feat: Edit search SELECT and ORDER BY from Columns and Sort popovers on the results table, and tidy the table controls row
279 changes: 155 additions & 124 deletions packages/app/src/DBSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ import SearchWhereInput, {
getStoredLanguage,
} from '@/components/SearchInput/SearchWhereInput';
import SearchPageActionBar from '@/components/SearchPageActionBar';
import { ColumnsPopover } from '@/components/SearchResultsToolbar/ColumnsPopover';
import { SortPopover } from '@/components/SearchResultsToolbar/SortPopover';
import { useClauseFieldOptions } from '@/components/SearchResultsToolbar/useClauseFieldOptions';
import SearchTotalCountChart from '@/components/SearchTotalCountChart';
import { TableSourceForm } from '@/components/Sources/SourceForm';
import { SourceSelectControlled } from '@/components/SourceSelect';
import { SQLInlineEditorControlled } from '@/components/SQLEditor/SQLInlineEditor';
import { Tags } from '@/components/Tags';
import { TimePicker } from '@/components/TimePicker';
import { IS_LOCAL_MODE } from '@/config';
Expand Down Expand Up @@ -1146,9 +1148,6 @@ function DBSearchPageContent() {
// key from a phone would collapse the sidebar the next time the same
// browser opens the page on a desktop.
const [isCompactFiltersOpen, setIsCompactFiltersOpen] = useState(false);
// SELECT grows with its text. On a phone that pushes the logs off the
// screen, so the column editors stay closed until the user asks.
const [columnsOpen, setColumnsOpen] = useState(false);
const isCompact = useCompactViewport();
const filtersCollapsed = isCompact
? !isCompactFiltersOpen
Expand Down Expand Up @@ -2171,6 +2170,15 @@ function DBSearchPageContent() {
[inputSourceObj],
);

const inputSelect = useWatch({ name: 'select', control });
const inputOrderBy = useWatch({ name: 'orderBy', control });
const clauseFieldOptions = useClauseFieldOptions({
tableConnection: inputSourceTableConnection,
columns: inputSourceColumns,
dateRange: searchedTimeRange,
timestampValueExpression: inputSourceObj?.timestampValueExpression,
});

const [isSourceSchemaPreviewOpen, setIsSourceSchemaPreviewOpen] =
useState(false);

Expand Down Expand Up @@ -2293,51 +2301,73 @@ function DBSearchPageContent() {
[setValue, setNewSourceModalClosed],
);

const columnFields = (allowMultiline: boolean, stacked: boolean) => {
const select = (
<SQLInlineEditorControlled
tableConnection={inputSourceTableConnection}
control={control}
name="select"
defaultValue={defaultSearchConfig.select}
placeholder={defaultSearchConfig.select || 'SELECT Columns'}
onSubmit={onSubmit}
label="SELECT"
size="xs"
allowMultiline={allowMultiline}
dateRange={searchedTimeRange}
sourceId={inputSource}
/>
);
const orderBy = (
<SQLInlineEditorControlled
tableConnection={inputSourceTableConnection}
control={control}
name="orderBy"
defaultValue={defaultSearchConfig.orderBy}
onSubmit={onSubmit}
label="ORDER BY"
size="xs"
allowMultiline={allowMultiline}
dateRange={searchedTimeRange}
sourceId={inputSource}
/>
);
if (stacked) {
return (
<>
{select}
{orderBy}
</>
);
}
return (
<>
<Box style={{ flex: '1 1 0%', minWidth: 100 }}>{select}</Box>
<Box style={{ maxWidth: 400, width: '20%' }}>{orderBy}</Box>
</>
);
};
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

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 copies the ORDER BY cleanup from toggleColumn

toggleColumn (lines 1851-1860) already does this: read getValues('orderBy'), apply orderByAfterRemovingSelectItem with defaultSearchConfig.orderBy, then setValue('orderBy'). Move it into one local helper, e.g. orderByWithout(items: string[]), and call it from both places so the two removal paths can't drift apart. The helper should also skip setValue when nothing changed, 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

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 — No test covers the Columns and Sort apply logic on the search page

The PR says a removed column is also dropped from ORDER BY, but no test checks this. The DBSearchPage unit test mocks ColumnsPopover, SortPopover and useClauseFieldOptions with empty stubs. The changed e2e specs only read the button title. Add a test that removes a SELECT item that is also in ORDER BY through the Columns popover, then checks the submitted orderBy (or the search-sort-button title) after Apply.

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

(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

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 duplicates toggleColumn's logic for pruning the sort and resubmitting

toggleColumn (DBSearchPage.tsx:1838) already sets select, runs orderByAfterRemovingSelectItem with defaultSearchConfig.orderBy, and calls onSubmit. That is the same as applySelect(newSelect, selected ? [selected] : []). Declare applySelect before toggleColumn and have toggleColumn call it, so the removal-to-sort rule lives in one place.

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

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 rule for pruning ORDER BY

toggleColumn (~line 1851) already runs getValues('orderBy'), then orderByAfterRemovingSelectItem(..., defaultSearchConfig.orderBy), then setValue. applySelect now does the same thing in a loop. Move this into one helper, e.g. orderByAfterRemovingSelectItems(items, orderBy, default) in utils.ts next to orderByAfterRemovingSelectItem, and call it from both places so the rule can't drift.

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

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 — No test covers the new Columns-apply wiring that drops removed columns from the sort

The PR description says removing a column drops it from the sort, but nothing tests the applySelect path. The e2e tests only set SELECT/ORDER BY through SQL, and DBSearchPage.directTrace.test mocks ColumnsPopover out. Add a test that removes an aliased column used in ORDER BY via Apply, and assert the resulting orderBy in the form or URL (including the fallback to the default 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

setValue('select', select);
let orderBy = getValues('orderBy') ?? '';
for (const item of removedItems) {
orderBy = orderByAfterRemovingSelectItem(
item,
orderBy,
defaultSearchConfig.orderBy ?? '',
);
Comment on lines +2309 to +2313

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.

P1 Removed columns leave broken sorts

Select upper(Body) AS message, set Sort to message DESC, then remove that column through Columns and Apply. applySelect calls orderByAfterRemovingSelectItem, but that helper only matches "message", not message. The search then fails because the removed alias no longer exists. Match valid quoted and unquoted alias references when dropping sort fields.

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

}
setValue('orderBy', orderBy);
onSubmit();
},
[setValue, getValues, defaultSearchConfig.orderBy, onSubmit],
);

const applyOrderBy = useCallback(
(orderBy: string) => {
setValue('orderBy', orderBy);
onSubmit();
},
[setValue, onSubmit],
);

// The dropdown source can move before the URL source does. An empty SELECT
// is shown as this default, so it has to follow the dropdown, the same way
// the sort default follows useDefaultOrderBy(inputSource).
const savedSelect =

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 — defaultSelect copies defaultSearchConfig's saved-search check and creates a second SELECT default

savedSelect repeats the _savedSearch gating in defaultSearchConfig (line ~1218). The only difference is that it uses inputSourceObj, while defaultSearchConfig.select uses searchedSource. Header column toggles (displayedColumns/toggleColumn, ~1832) and the Columns popover can therefore start from different defaults while the dropdown and URL sources differ. Expose the gated saved search (or both defaults) from the one memo instead of rebuilding the logic here.

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

savedSearchId &&
savedSearch?.id === savedSearchId &&
inputSource === savedSearch.source
? savedSearch.select
: undefined;
const sourceDefaultSelect =
inputSourceObj?.kind === SourceKind.Log ||
inputSourceObj?.kind === SourceKind.Trace
? inputSourceObj.defaultTableSelectExpression
: undefined;
const defaultSelect = savedSelect ?? sourceDefaultSelect ?? '';

// SELECT and ORDER BY shape the results table, so they sit on that table
// and stay hidden on Event Deltas and Event Patterns.
const resultsClauseEditors =

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 toolbar element on every render defeats the memo on DBSqlRowTable and RawLogTable

resultsClauseEditors is a new JSX element on every DBSearchPageContent render. It is passed as toolbarLeading through DBSqlRowTableWithSideBar into the memoized DBSqlRowTable (components/DBRowTable.tsx:2071) and RawLogTable. The page memoizes every other prop to that table (useCallback/useMemo), but now any page render re-renders the whole virtualized table, for example each keystroke in the time picker input. Wrap resultsClauseEditors in useMemo, with its inputs as dependencies.

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

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 — resultsClauseEditors is a new JSX element on every render, which defeats the memo on DBSqlRowTable and RawLogTable

DBSqlRowTable and RawLogTable are both wrapped in memo (components/DBRowTable.tsx:355 and :2078). Passing a fresh toolbarLeading element means every DBSearchPageContent render now re-renders the whole results table. Wrap the element in useMemo, keyed on analysisMode, inputSelect, inputOrderBy, defaultSelect, clauseFieldOptions, the two apply callbacks, the connection, the source and the date range. Or pass the popovers' props down and let the table render 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

analysisMode === 'results' ? (

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 — resultsClauseEditors is a new element on every page render, so the memoized results table re-renders on every keystroke

toolbarLeading={resultsClauseEditors} gets a fresh JSX element each time DBSearchPageContent renders. That breaks memo on both DBSqlRowTable and RawLogTable (DBRowTable.tsx:2074 and :391), whose other props from DBSqlRowTableWithSidebar are stable. The page re-renders on every WHERE keystroke because of useWatch({ name: 'where' }) at line 1631, so the virtualized table now re-renders on each one. Fix: wrap resultsClauseEditors in useMemo, keyed on analysisMode, inputSelect, inputOrderBy, clauseFieldOptions, knownColumns, applySelect, applyOrderBy, inputSourceTableConnection, inputSource and searchedTimeRange.

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

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 — A new toolbarLeading element on every render cancels the memo on DBSqlRowTable and RawLogTable

Every other prop passed to DBSqlRowTableWithSideBar is wrapped in useMemo or useCallback (rowTableContext, onSortingChange, initialSortBy, …). resultsClauseEditors is fresh JSX on each render, so the memoized DBSqlRowTable and RawLogTable in DBRowTable.tsx now re-render the virtualized results table on every page render. Wrap resultsClauseEditors in useMemo, keyed on its inputs.

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

<Group gap="xs" wrap="wrap">
<ColumnsPopover
value={inputSelect ?? ''}
defaultValue={defaultSelect}
fieldOptions={clauseFieldOptions}
knownColumns={knownColumns}
onApply={applySelect}
tableConnection={inputSourceTableConnection}
sourceId={inputSource}
dateRange={searchedTimeRange}
/>
<SortPopover
value={inputOrderBy ?? ''}
defaultValue={defaultSearchConfig.orderBy ?? ''}
fieldOptions={clauseFieldOptions}
onApply={applyOrderBy}
tableConnection={inputSourceTableConnection}
sourceId={inputSource}
dateRange={searchedTimeRange}
/>
</Group>
) : null;

return (
<Flex
Expand Down Expand Up @@ -2480,6 +2510,8 @@ function DBSearchPageContent() {
px="sm"
pt={isCompact ? 4 : 'sm'}
wrap={isCompact ? 'wrap' : 'nowrap'}
justify="space-between"
align="center"
>
<SourceSelectControlled
key={`${savedSearchId}`}
Expand All @@ -2499,21 +2531,13 @@ function DBSearchPageContent() {
isCompact ? { flex: '1 1 140px', minWidth: 0 } : { minWidth: 150 }
}
/>
<SourceSchemaPreview
source={inputSourceObj}
controlled
open={isSourceSchemaPreviewOpen}
onClose={() => setIsSourceSchemaPreviewOpen(false)}
/>
{!isCompact && columnFields(true, false)}
<>
<Group gap="sm" wrap="nowrap" style={{ flexShrink: 0 }}>
{!savedSearchId ? (
<Button
data-testid="save-search-button"
variant="secondary"
size="xs"
onClick={onSaveSearch}
style={{ flexShrink: 0 }}
>
Save
</Button>
Expand All @@ -2525,7 +2549,6 @@ function DBSearchPageContent() {
onClick={() => {
setSaveSearchModalState('update');
}}
style={{ flexShrink: 0 }}
>
Update
</Button>
Expand All @@ -2536,82 +2559,60 @@ function DBSearchPageContent() {
variant="secondary"
size="xs"
onClick={openAlertModal}
style={{ flexShrink: 0 }}
>
<Group gap={4}>
Alerts
<AlertStatusIcon alerts={savedSearch?.alerts} />
</Group>
</Button>
)}
{isCompact && (
<Button
variant="subtle"
size="xs"
style={{ flexShrink: 0 }}
aria-expanded={columnsOpen}
onClick={() => setColumnsOpen(open => !open)}
>
{columnsOpen ? 'Hide columns' : 'Columns'}
</Button>
)}
</>
</Group>
</Flex>
{isCompact && columnsOpen && (
<Flex direction="column" gap={4} px="sm" pt={4}>
{columnFields(false, true)}
</Flex>
)}
<SourceEditModal
opened={modelFormExpanded}
onClose={onModelFormExpandClose}
inputSource={inputSource}
/>
<NewSourceModal
opened={newSourceModalOpened}
onClose={setNewSourceModalClosed}
onCreate={onNewSourceCreate}
/>
<Flex
className={searchPageStyles.whereRow}
gap={isCompact ? 'xs' : 'sm'}
mt={isCompact ? 4 : 'sm'}
px="sm"
wrap="wrap"
>
<SearchWhereInput
tableConnection={inputSourceTableConnection}
control={control}
name="where"
onSubmit={onSubmit}
sqlQueryHistoryType={QUERY_LOCAL_STORAGE.SEARCH_SQL}
luceneQueryHistoryType={QUERY_LOCAL_STORAGE.SEARCH_LUCENE}
enableHotkey
data-testid="search-input"
minWidth="min(600px, 100%)"
dateRange={searchedTimeRange}
sourceId={inputSource}
size="xs"
/>
<Box className={searchPageStyles.whereField}>
<SearchWhereInput
tableConnection={inputSourceTableConnection}
control={control}
name="where"
onSubmit={onSubmit}
sqlQueryHistoryType={QUERY_LOCAL_STORAGE.SEARCH_SQL}
luceneQueryHistoryType={QUERY_LOCAL_STORAGE.SEARCH_LUCENE}
enableHotkey
data-testid="search-input"
minWidth="100%"
dateRange={searchedTimeRange}
sourceId={inputSource}
size="xs"
/>
</Box>
<Flex
className={searchPageStyles.timeControls}
gap="sm"
style={{ flex: '0 1 500px', minWidth: 0 }}
wrap="wrap"
align="flex-start"
>
<TimePicker
data-testid="time-picker"
inputValue={displayedTimeInputValue}
setInputValue={setDisplayedTimeInputValue}
onSearch={onTimePickerSearch}
onRelativeSearch={onTimePickerRelativeSearch}
showLive={analysisMode === 'results'}
isLiveMode={isLive}
// Default to relative time mode if the user has made changes to interval and reloaded.
defaultRelativeTimeMode={
isLive && interval !== LIVE_TAIL_DURATION_MS
}
width="100%"
size="xs"
/>
<Box className={searchPageStyles.timePicker}>
<TimePicker
data-testid="time-picker"
width="100%"
inputValue={displayedTimeInputValue}
setInputValue={setDisplayedTimeInputValue}
onSearch={onTimePickerSearch}
onRelativeSearch={onTimePickerRelativeSearch}
showLive={analysisMode === 'results'}
isLiveMode={isLive}
// Default to relative time mode if the user has made changes to interval and reloaded.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

My only major feedback is this works, but the page has 5 rows of elements before the search results appear. We should in the future consider how we can save vertical space. it looks very off with the amount of empty space is in the source/save column.. i feel like we could compact/rearrange further.

defaultRelativeTimeMode={
isLive && interval !== LIVE_TAIL_DURATION_MS
}
size="xs"
/>
</Box>
{isLive && (
<Tooltip label="Live tail refresh interval">
<Box style={{ width: 80, minWidth: 80, flexShrink: 0 }}>
Expand All @@ -2635,6 +2636,22 @@ function DBSearchPageContent() {
<SearchSubmitButton isFormStateDirty={formState.isDirty} />
</Flex>
</Flex>
<SourceSchemaPreview
source={inputSourceObj}
controlled
open={isSourceSchemaPreviewOpen}
onClose={() => setIsSourceSchemaPreviewOpen(false)}
/>
<SourceEditModal
opened={modelFormExpanded}
onClose={onModelFormExpandClose}
inputSource={inputSource}
/>
<NewSourceModal
opened={newSourceModalOpened}
onClose={setNewSourceModalClosed}
onCreate={onNewSourceCreate}
/>
<ActiveFilterPills
searchFilters={searchFilters}
chartConfig={filtersChartConfig}
Expand Down Expand Up @@ -2667,12 +2684,19 @@ function DBSearchPageContent() {
className="bg-body"
>
{!queryReady ? (
<EmptyState
h="100%"
icon={<IconStack2 size={32} />}
title="No data to display"
description="Select a source and click the play button to query data."
/>
<Flex direction="column" h="100%">
{resultsClauseEditors != null && (
<Box px="sm" pt="sm">
{resultsClauseEditors}
</Box>
)}
<EmptyState
h="100%"
icon={<IconStack2 size={32} />}
title="No data to display"
description="Select a source and click the play button to query data."
/>
</Flex>
) : (
<>
<ResponsiveSidePanel
Expand Down Expand Up @@ -2879,6 +2903,11 @@ function DBSearchPageContent() {
)}
{hasQueryError && queryError ? (
<>
{resultsClauseEditors != null && (
<Box px="sm" pt="xs">
{resultsClauseEditors}
</Box>
)}
<div className="h-100 w-100 px-4 mt-4 align-items-center justify-content-center text-muted overflow-auto">
{whereSuggestions && whereSuggestions.length > 0 && (
<Box mb="xl">
Expand Down Expand Up @@ -3031,6 +3060,8 @@ function DBSearchPageContent() {
selectionResetKey={selectionResetKey}
onSelectedRowsChange={onSelectedRowsChange}
onResolvedColumnsChange={onResolvedColumnsChange}
toolbarLeading={resultsClauseEditors}
controlsAboveTable
/>
)}
</Box>
Expand Down
Loading
Loading