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
7 changes: 7 additions & 0 deletions .changeset/search-results-row-copy.md
Original file line number Diff line number Diff line change
@@ -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.
208 changes: 124 additions & 84 deletions packages/app/src/DBSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function ResumeLiveTailButton({
onClick={handleResumeLiveTail}
leftSection={<IconBolt size={14} />}
>
Resume Live Tail
Resume live tail
</Button>
);
}
Expand Down Expand Up @@ -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 (
<Group gap="sm" align="center">
<Group gap={4} align="center">
{isFilterSidebarCollapsed && (
<ExpandFiltersButton onExpand={onExpandFilters} />
)}
<SearchTotalCountChart
config={totalCountConfig}
queryKeyPrefix={QUERY_KEY_PREFIX}
enableParallelQueries={enableParallelQueries}
/>
</Group>
{children}
{isFilterSidebarCollapsed && (
<ExpandFiltersButton onExpand={onExpandFilters} />
)}
{groupBy}
<SearchTotalCountChart
config={totalCountConfig}
queryKeyPrefix={QUERY_KEY_PREFIX}
enableParallelQueries={enableParallelQueries}
/>
{stats}
</Group>
);
}

/** 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,
});
Expand All @@ -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!));

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 — Elapsed placeholder …ms hardcodes a unit the real value may not use

Use a unit-free placeholder such as …. formatDurationMs (packages/app/src/utils.ts:1079) returns seconds or minutes for longer searches, so a 2.3s search shows …ms while loading and then jumps to 2.3s.

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

}

if (parts.length === 0) {
return null;
}

return (
<>
<Text size="xs" c="dimmed" aria-hidden>
&middot;
</Text>
<Text size="xs" c="dimmed">
{parts.join(' · ')}
</Text>
</>
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Middot gets extra flex gap

Low Severity

SearchNumRows emits the leading middot as its own Text node, and SearchResultsCountGroup places that fragment in a Group with gap="sm". Flex gap then lands on both sides of the first separator, so N results and the scanned/elapsed text do not read as one phrase the way the inner · does.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8ab7bc2. Configure here.

}

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 (
<>
<Modal
opened={statsOpened}
onClose={closeStats}
title={sqlConfig != null ? 'Generated SQL (Timeline)' : 'Generated SQL'}
opened={opened}
onClose={close}
title={sqlConfig != null ? 'Generated SQL (timeline)' : 'Generated SQL'}
size="xl"
>
<ChartSQLPreview config={sqlConfig ?? config} enableCopy />
</Modal>
<Group gap={4} align="center">
<Text size="xs">
{isLoading
? 'Scanned Rows ...'
: error || numRows == null
? ''
: `Scanned Rows: ${Number(numRows).toLocaleString()}`}
</Text>
{showElapsed && (
<>
{(hasData || isLoading) && (
<Text size="xs" c="dimmed">
|
</Text>
)}
<Text size="xs">
{showElapsedLoading
? 'Elapsed Time: ...'
: `Elapsed Time: ${formatDurationMs(searchElapsedMs!)}`}
</Text>
</>
)}
{/* 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). */}
<Tooltip label="Show Generated SQL" position="top">
<ActionIcon
variant="subtle"
size="sm"
color="gray"
onClick={openStats}
aria-label="Show Generated SQL"
>
<IconCode size={16} />
</ActionIcon>
</Tooltip>
</Group>
<Tooltip label="Show generated SQL" position="top">
<ActionIcon
variant="subtle"
size="sm"
color="gray"
onClick={open}
aria-label="Show generated SQL"
>
<IconCode size={16} />
</ActionIcon>
</Tooltip>
</>
);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2615,12 +2631,18 @@ function DBSearchPageContent() {
format="short"
/>
{savedSearch.updatedBy
? ` by ${savedSearch.updatedBy.name || savedSearch.updatedBy.email}`
? ` by ${
savedSearch.updatedBy.name ||
savedSearch.updatedBy.email
}`
: ''}
</>
}
>
<span>{`Updated ${formatDistanceToNow(new Date(savedSearch.updatedAt), { addSuffix: true })}.`}</span>
<span>{`Updated ${formatDistanceToNow(
new Date(savedSearch.updatedAt),
{ addSuffix: true },
)}.`}</span>
</Tooltip>
)}
</Text>
Expand Down Expand Up @@ -2947,19 +2969,27 @@ function DBSearchPageContent() {
isFilterSidebarCollapsed={filtersCollapsed}
onExpandFilters={expandFilters}
totalCountConfig={totalCountConfig}
>
{histogramGroupBySelect}
</SearchResultsCountGroup>
<SearchNumRows
groupBy={histogramGroupBySelect}
stats={
<SearchNumRows
config={{
...chartConfig,
dateRange: searchedTimeRange,
}}
enabled={isReady}
searchElapsedMs={searchElapsedMs}
isSearching={isAnyQueryFetching}
isLiveTail={isLive ?? false}
/>
}
/>
<GeneratedSqlButton
config={{
...chartConfig,
dateRange: searchedTimeRange,
}}
sqlConfig={histogramTimeChartConfig ?? undefined}
enabled={isReady}
searchElapsedMs={searchElapsedMs}
isSearching={isAnyQueryFetching}
isLiveTail={isLive ?? false}
/>
</Group>
</Box>
Expand Down Expand Up @@ -3055,12 +3085,25 @@ function DBSearchPageContent() {
onExpandFilters={expandFilters}
totalCountConfig={totalCountConfig}
enableParallelQueries
>
{/* The heatmap doesn't group. */}
{isHeatmapChartVisible
? null
: histogramGroupBySelect}
</SearchResultsCountGroup>
// The heatmap doesn't group.
groupBy={
isHeatmapChartVisible
? null
: histogramGroupBySelect
}
stats={
<SearchNumRows
config={{
...chartConfig,
dateRange: searchedTimeRange,
}}
enabled={isReady}
searchElapsedMs={searchElapsedMs}
isSearching={isAnyQueryFetching}
isLiveTail={isLive ?? false}
/>
}
/>
<Group gap="sm" align="center">
{traceChartsSource != null && (
<SegmentedControl
Expand Down Expand Up @@ -3088,7 +3131,7 @@ function DBSearchPageContent() {
handleResumeLiveTail={handleResumeLiveTail}
/>
)}
<SearchNumRows
<GeneratedSqlButton
config={{
...chartConfig,
dateRange: searchedTimeRange,
Expand All @@ -3097,9 +3140,6 @@ function DBSearchPageContent() {
histogramTimeChartConfig ?? undefined
}
enabled={isReady}
searchElapsedMs={searchElapsedMs}
isSearching={isAnyQueryFetching}
isLiveTail={isLive ?? false}
/>
</Group>
</Group>
Expand Down
Loading
Loading