Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
263 changes: 139 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,57 @@ 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

);

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 applySelect's ORDER BY cleanup

applySelect rewrites ORDER BY for each removed SELECT item via orderByAfterRemovingSelectItem. The only page-level test (DBSearchPage.directTrace.test.tsx) mocks the popovers away, and the popover tests only check onApply arguments. Add a test that removes an aliased column that is also the sort key, and assert the form's orderBy falls back to the 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

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 — 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

(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

setValue('select', select);
let orderBy = getValues('orderBy') ?? '';
for (const item of removedItems) {
orderBy = orderByAfterRemovingSelectItem(
item,
orderBy,
defaultSearchConfig.orderBy ?? '',
);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}
setValue('orderBy', orderBy);
onSubmit();
},
[setValue, getValues, defaultSearchConfig.orderBy, onSubmit],
);

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

// 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 toolbarLeading JSX on every render defeats the memo on DBSqlRowTable/RawLogTable

resultsClauseEditors is a new React element on every render of DBSearchPageContent, which re-renders on each WHERE keystroke because of useWatch({name: 'where'}) at line 1565. Passing it as toolbarLeading busts the memo on DBSqlRowTable and RawLogTable (DBRowTable.tsx:346, 2029), so the results table re-renders on every keystroke. 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

analysisMode === 'results' ? (
<Group gap="xs" wrap="nowrap">
<ColumnsPopover
value={inputSelect ?? ''}
defaultValue={defaultSearchConfig.select ?? ''}
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 +2494,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 +2515,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 +2533,6 @@ function DBSearchPageContent() {
onClick={() => {
setSaveSearchModalState('update');
}}
style={{ flexShrink: 0 }}
>
Update
</Button>
Expand All @@ -2536,82 +2543,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.
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 +2620,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 +2668,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 +2887,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 +3044,8 @@ function DBSearchPageContent() {
selectionResetKey={selectionResetKey}
onSelectedRowsChange={onSelectedRowsChange}
onResolvedColumnsChange={onResolvedColumnsChange}
toolbarLeading={resultsClauseEditors}
controlsAboveTable
/>
)}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ jest.mock('@/components/SearchGroupBy/SearchGroupBySelect', () => ({
SearchGroupBySelect: () => <div />,
}));
jest.mock('@/components/SearchPageActionBar', () => () => <div />);
jest.mock('@/components/SearchResultsToolbar/ColumnsPopover', () => ({
ColumnsPopover: () => <div />,
}));
jest.mock('@/components/SearchResultsToolbar/SortPopover', () => ({
SortPopover: () => <div />,
}));
jest.mock('@/components/SearchResultsToolbar/useClauseFieldOptions', () => ({
useClauseFieldOptions: () => [],
}));
jest.mock('@/components/SearchTotalCountChart', () => () => <div />);
jest.mock('@/components/Sources/SourceForm', () => ({
TableSourceForm: () => <div />,
Expand Down
Loading
Loading