diff --git a/.changeset/search-results-row-copy.md b/.changeset/search-results-row-copy.md new file mode 100644 index 000000000..2f9cd2901 --- /dev/null +++ b/.changeset/search-results-row-copy.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/app': patch +--- + +fix: tighten the search results row. Group by now comes first, followed by the +result count and a shorter `2,895 rows scanned · 216ms` summary, with the +actions on the right. Copy is now sentence case. diff --git a/packages/app/src/DBSearchPage.tsx b/packages/app/src/DBSearchPage.tsx index cf5f8270b..f3029434b 100644 --- a/packages/app/src/DBSearchPage.tsx +++ b/packages/app/src/DBSearchPage.tsx @@ -324,7 +324,7 @@ function ResumeLiveTailButton({ onClick={handleResumeLiveTail} leftSection={} > - Resume Live Tail + Resume live tail ); } @@ -368,52 +368,50 @@ function SearchResultsCountGroup({ onExpandFilters, totalCountConfig, enableParallelQueries, - children, + groupBy, + stats, }: { isFilterSidebarCollapsed: boolean; onExpandFilters: () => void; totalCountConfig: BuilderChartConfigWithDateRange; enableParallelQueries?: boolean; - children?: ReactNode; + groupBy?: ReactNode; + stats?: ReactNode; }) { return ( - - {isFilterSidebarCollapsed && ( - - )} - - - {children} + {isFilterSidebarCollapsed && ( + + )} + {groupBy} + + {stats} ); } +/** Rows scanned and elapsed time, e.g. `2,895 rows scanned · 216 ms`. */ export function SearchNumRows({ config, - sqlConfig, enabled, searchElapsedMs, isSearching, isLiveTail = false, }: { config: ChartConfigWithDateRange; - sqlConfig?: ChartConfigWithDateRange; enabled: boolean; searchElapsedMs: number | null; isSearching: boolean; isLiveTail?: boolean; }) { - const [statsOpened, { open: openStats, close: closeStats }] = - useDisclosure(false); const { data, isLoading, error } = useExplainQuery(config, { enabled, // Keep the previous row count on screen while a new EXPLAIN runs so the - // "Scanned Rows" value doesn't flash a loading state on every live-tail + // "rows scanned" value doesn't flash a loading state on every live-tail // poll (each poll changes the dateRange, and thus the query key). placeholderData: keepPreviousData, }); @@ -422,63 +420,79 @@ export function SearchNumRows({ return null; } - const explainRow = data?.[0]; - const numRows = explainRow?.rows; - const hasData = !isLoading && !error && numRows != null; + const numRows = data?.[0]?.rows; // During live tail we keep showing the last measured elapsed time and never - // flash the "..." loading state, so the value doesn't flicker between polls. + // flash the "…" loading state, so the value doesn't flicker between polls. const showElapsedLoading = isSearching && !isLiveTail; const showElapsed = showElapsedLoading || searchElapsedMs != null; + const parts: string[] = []; + if (isLoading) { + parts.push('… rows scanned'); + } else if (!error && numRows != null) { + parts.push(`${Number(numRows).toLocaleString()} rows scanned`); + } + if (showElapsed) { + parts.push(showElapsedLoading ? '…ms' : formatDurationMs(searchElapsedMs!)); + } + + if (parts.length === 0) { + return null; + } + + return ( + <> + + · + + + {parts.join(' · ')} + + + ); +} + +export function GeneratedSqlButton({ + config, + sqlConfig, + enabled, +}: { + config: ChartConfigWithDateRange; + sqlConfig?: ChartConfigWithDateRange; + enabled: boolean; +}) { + const [opened, { open, close }] = useDisclosure(false); + + if (!enabled) { + return null; + } + + // The preview is derived purely from config, not the explain query, so it + // renders unconditionally. Gating it on explain loading/data would make it + // flicker on every live-tail poll, since each poll changes the dateRange + // (and thus the explain queryKey). return ( <> - - - {isLoading - ? 'Scanned Rows ...' - : error || numRows == null - ? '' - : `Scanned Rows: ${Number(numRows).toLocaleString()}`} - - {showElapsed && ( - <> - {(hasData || isLoading) && ( - - | - - )} - - {showElapsedLoading - ? 'Elapsed Time: ...' - : `Elapsed Time: ${formatDurationMs(searchElapsedMs!)}`} - - - )} - {/* The generated-SQL preview is derived purely from config, not the - explain query, so it renders unconditionally. Gating it on explain - loading/data would make it flicker on every live-tail poll, since - each poll changes the dateRange (and thus the explain queryKey). */} - - - - - - + + + + + ); } @@ -926,7 +940,9 @@ function formatDroppedFiltersMessage(count: number): string { function formatDroppedGroupByMessage(dropped: string[]): string { const verb = dropped.length === 1 ? 'was' : 'were'; - return `Group by ${dropped.join(', ')} didn't apply to this source and ${verb} removed.`; + return `Group by ${dropped.join( + ', ', + )} didn't apply to this source and ${verb} removed.`; } // This is outside as it needs to be a stable reference @@ -2615,12 +2631,18 @@ function DBSearchPageContent() { format="short" /> {savedSearch.updatedBy - ? ` by ${savedSearch.updatedBy.name || savedSearch.updatedBy.email}` + ? ` by ${ + savedSearch.updatedBy.name || + savedSearch.updatedBy.email + }` : ''} } > - {`Updated ${formatDistanceToNow(new Date(savedSearch.updatedAt), { addSuffix: true })}.`} + {`Updated ${formatDistanceToNow( + new Date(savedSearch.updatedAt), + { addSuffix: true }, + )}.`} )} @@ -2947,19 +2969,27 @@ function DBSearchPageContent() { isFilterSidebarCollapsed={filtersCollapsed} onExpandFilters={expandFilters} totalCountConfig={totalCountConfig} - > - {histogramGroupBySelect} - - + } + /> + @@ -3055,12 +3085,25 @@ function DBSearchPageContent() { onExpandFilters={expandFilters} totalCountConfig={totalCountConfig} enableParallelQueries - > - {/* The heatmap doesn't group. */} - {isHeatmapChartVisible - ? null - : histogramGroupBySelect} - + // The heatmap doesn't group. + groupBy={ + isHeatmapChartVisible + ? null + : histogramGroupBySelect + } + stats={ + + } + /> {traceChartsSource != null && ( )} - diff --git a/packages/app/src/__tests__/useSearchTelemetry.test.tsx b/packages/app/src/__tests__/useSearchTelemetry.test.tsx index b945044ad..1413a4e4c 100644 --- a/packages/app/src/__tests__/useSearchTelemetry.test.tsx +++ b/packages/app/src/__tests__/useSearchTelemetry.test.tsx @@ -3,7 +3,11 @@ import type { ChartConfigWithDateRange } from '@hyperdx/common-utils/dist/types' import { act, fireEvent, renderHook, screen } from '@testing-library/react'; import { fromPartial } from '@total-typescript/shoehorn'; -import { SearchNumRows, useSearchTelemetry } from '@/DBSearchPage'; +import { + GeneratedSqlButton, + SearchNumRows, + useSearchTelemetry, +} from '@/DBSearchPage'; jest.mock('@/layout', () => ({ withAppNav: (component: unknown) => component, @@ -320,10 +324,7 @@ describe('SearchNumRows', () => { isSearching={false} />, ); - expect(screen.queryByText(/Scanned Rows/)).not.toBeInTheDocument(); - expect( - screen.queryByRole('button', { name: /show generated sql/i }), - ).not.toBeInTheDocument(); + expect(screen.queryByText(/rows scanned/)).not.toBeInTheDocument(); }); it('shows loading state while explain query is in flight', () => { @@ -336,22 +337,7 @@ describe('SearchNumRows', () => { isSearching={false} />, ); - expect(screen.getByText('Scanned Rows ...')).toBeInTheDocument(); - }); - - it('keeps the SQL icon visible while explain is loading (no flicker on poll)', () => { - mockExplainIsLoading = true; - renderWithMantine( - , - ); - expect( - screen.getByRole('button', { name: /show generated sql/i }), - ).toBeInTheDocument(); + expect(screen.getByText('… rows scanned')).toBeInTheDocument(); }); it('renders empty text on error', () => { @@ -365,7 +351,7 @@ describe('SearchNumRows', () => { />, ); // No row count text shown on error - expect(screen.queryByText(/Scanned Rows:/)).not.toBeInTheDocument(); + expect(screen.queryByText(/rows scanned/)).not.toBeInTheDocument(); }); it('shows formatted scanned row count when data is present', () => { @@ -378,10 +364,10 @@ describe('SearchNumRows', () => { isSearching={false} />, ); - expect(screen.getByText('Scanned Rows: 1,482,447')).toBeInTheDocument(); + expect(screen.getByText('1,482,447 rows scanned')).toBeInTheDocument(); }); - it('shows "Elapsed Time: ..." while searching', () => { + it('shows "…ms" while searching', () => { mockExplainData = [{ rows: 100 }]; renderWithMantine( { isSearching />, ); - expect(screen.getByText('Elapsed Time: ...')).toBeInTheDocument(); + expect(screen.getByText(/…ms/)).toBeInTheDocument(); }); it('does not flash the "..." elapsed loading state during live tail', () => { @@ -406,8 +392,8 @@ describe('SearchNumRows', () => { />, ); // While live and fetching, keep showing the last value, not the "..." - expect(screen.queryByText('Elapsed Time: ...')).not.toBeInTheDocument(); - expect(screen.getByText(/Elapsed Time:/)).toBeInTheDocument(); + expect(screen.queryByText(/…ms/)).not.toBeInTheDocument(); + expect(screen.getByText(/342ms/)).toBeInTheDocument(); }); it('hides elapsed during live tail before the first measurement', () => { @@ -421,7 +407,7 @@ describe('SearchNumRows', () => { isLiveTail />, ); - expect(screen.queryByText(/Elapsed Time:/)).not.toBeInTheDocument(); + expect(screen.queryByText(/\dms/)).not.toBeInTheDocument(); }); it('shows formatted elapsed time after search completes', () => { @@ -434,8 +420,8 @@ describe('SearchNumRows', () => { isSearching={false} />, ); - expect(screen.getByText(/Elapsed Time:/)).toBeInTheDocument(); - expect(screen.queryByText('Elapsed Time: ...')).not.toBeInTheDocument(); + expect(screen.getByText(/342ms/)).toBeInTheDocument(); + expect(screen.queryByText(/…ms/)).not.toBeInTheDocument(); }); it('hides elapsed time section when there is no elapsed value and not searching', () => { @@ -448,10 +434,10 @@ describe('SearchNumRows', () => { isSearching={false} />, ); - expect(screen.queryByText(/Elapsed Time:/)).not.toBeInTheDocument(); + expect(screen.queryByText(/\dms/)).not.toBeInTheDocument(); }); - it('still shows elapsed time and SQL icon when the explain query fails', () => { + it('still shows elapsed time when the explain query fails', () => { mockExplainError = new Error('explain timed out'); renderWithMantine( { />, ); // Elapsed time is independent of the explain query and must remain visible - expect(screen.getByText(/Elapsed Time:/)).toBeInTheDocument(); - // SQL preview is also independent of explain data - expect( - screen.getByRole('button', { name: /show generated sql/i }), - ).toBeInTheDocument(); + expect(screen.getByText('200ms')).toBeInTheDocument(); }); it('shows elapsed time while searching even when explain has no data yet', () => { @@ -479,19 +461,23 @@ describe('SearchNumRows', () => { isSearching />, ); - expect(screen.getByText('Elapsed Time: ...')).toBeInTheDocument(); + expect(screen.getByText('…ms')).toBeInTheDocument(); }); +}); - it('opens the modal when the SQL button is clicked', async () => { - mockExplainData = [{ rows: 50 }]; +describe('GeneratedSqlButton', () => { + it('renders nothing when enabled=false', () => { renderWithMantine( - , + , ); + expect( + screen.queryByRole('button', { name: /show generated sql/i }), + ).not.toBeInTheDocument(); + }); + + it('opens the modal when the SQL button is clicked', async () => { + mockExplainData = [{ rows: 50 }]; + renderWithMantine(); await act(async () => { fireEvent.click( @@ -503,18 +489,12 @@ describe('SearchNumRows', () => { expect(screen.getByTestId('chart-sql-preview')).toBeInTheDocument(); }); - it('uses sqlConfig in the modal when provided — title says "Timeline" and content uses sqlConfig', async () => { + it('uses sqlConfig in the modal when provided — title says "timeline" and content uses sqlConfig', async () => { mockExplainData = [{ rows: 50 }]; const sqlConfig = { ...baseConfig, source: 'timeline-source' }; renderWithMantine( - , + , ); await act(async () => { @@ -524,7 +504,7 @@ describe('SearchNumRows', () => { }); expect(screen.getByTestId('modal-title')).toHaveTextContent( - 'Generated SQL (Timeline)', + 'Generated SQL (timeline)', ); expect(lastSQLPreviewConfig).toEqual(sqlConfig); }); @@ -533,14 +513,7 @@ describe('SearchNumRows', () => { mockExplainData = [{ rows: 50 }]; const rowsConfig = { ...baseConfig, source: 'rows-source' }; - renderWithMantine( - , - ); + renderWithMantine(); await act(async () => { fireEvent.click( @@ -552,7 +525,7 @@ describe('SearchNumRows', () => { 'Generated SQL', ); expect( - screen.queryByText('Generated SQL (Timeline)'), + screen.queryByText('Generated SQL (timeline)'), ).not.toBeInTheDocument(); expect(lastSQLPreviewConfig).toEqual(rowsConfig); }); diff --git a/packages/app/src/components/SearchTotalCountChart.tsx b/packages/app/src/components/SearchTotalCountChart.tsx index 6899344e7..4065b13dc 100644 --- a/packages/app/src/components/SearchTotalCountChart.tsx +++ b/packages/app/src/components/SearchTotalCountChart.tsx @@ -115,11 +115,11 @@ export default function SearchTotalCountChart({ return ( {isLoading ? ( - ··· Results + ··· results ) : totalCount !== null && !isError ? ( - `${totalCount?.toLocaleString()} Results` + `${totalCount?.toLocaleString()} results` ) : ( - '0 Results' + '0 results' )} ); diff --git a/packages/app/tests/e2e/features/search/total-count-matches-table.spec.ts b/packages/app/tests/e2e/features/search/total-count-matches-table.spec.ts index e17271fa0..ba262820a 100644 --- a/packages/app/tests/e2e/features/search/total-count-matches-table.spec.ts +++ b/packages/app/tests/e2e/features/search/total-count-matches-table.spec.ts @@ -1,5 +1,5 @@ /** - * Regression guard for: histogram "X Results" count must reflect the user's + * Regression guard for: histogram "X results" count must reflect the user's * exact selected time range, not a granularity-bucket-aligned expansion of it. * * To get a deterministic assertion we seed our own logs directly into @@ -127,7 +127,7 @@ test.describe( await searchPage.waitForTotalCountLoaded(); await expect(searchPage.table.getRows()).toHaveCount(5); - await expect(searchPage.totalCountText).toHaveText('5 Results'); + await expect(searchPage.totalCountText).toHaveText('5 results'); }); }, ); diff --git a/packages/app/tests/e2e/page-objects/SearchPage.ts b/packages/app/tests/e2e/page-objects/SearchPage.ts index 9bb4af303..c2019baca 100644 --- a/packages/app/tests/e2e/page-objects/SearchPage.ts +++ b/packages/app/tests/e2e/page-objects/SearchPage.ts @@ -292,7 +292,7 @@ export class SearchPage { /** Only rendered while live tail is stopped. */ get resumeLiveTailButton() { - return this.page.getByRole('button', { name: 'Resume Live Tail' }); + return this.page.getByRole('button', { name: 'Resume live tail' }); } async resumeLiveTail() {