Skip to content
Merged
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/compact-search-layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/app': patch
---

fix: saved search is usable on a phone. Below 900px the filters open in a
drawer, SELECT and ORDER BY stay behind "Columns", and the log table
keeps the remaining screen.
15 changes: 15 additions & 0 deletions agent_docs/page_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ Sessions keeps a **single-row** query toolbar (source, where filter, time range,
- Kubernetes Dashboard, Clickhouse Dashboard — `PageLayout` with `breadcrumbs`, `leading`, `actions`, `padded` (no `title`)
- Client Sessions — `PageLayout` with custom `PageHeader` containing the full single-row query toolbar

## Compact viewports

A viewport under 900px is compact. `useCompactViewport` (`packages/app/src/components/CompactViewport/useCompactViewport.ts`) is the cutoff, and the nav collapses on the same width. Pages that switch layout use this hook.

A page that is a side panel plus a main pane uses `ResponsiveSidePanel` (`packages/app/src/components/CompactViewport/ResponsiveSidePanel.tsx`):

- Wide: the panel sits beside the main pane.
- Compact: the main pane uses the full width. The panel opens in a drawer and does not take horizontal space. Pass a `title`; the drawer has no default. The panel stays unmounted until the first open, then stays mounted so closing the drawer does not drop its state.

The caller owns whether the panel is open. Keep that state separate from any desktop collapse preference stored in localStorage. A phone session that wrote the desktop preference would hide the panel the next time the same browser opened the page on a desktop.

Give the main pane `flex: 1` and `min-height: 0` inside a full-height column, so it keeps the space under the toolbar and scrolls inside itself. A hard `min-width` on the panel inside `overflow: hidden` clips the main pane on a phone.

Search is the first page on this pattern. Other side-panel pages should adopt it the same way instead of a one-off media query.

## Knip

`packages/app` Knip entry roots are `pages/`, `scripts/`, and e2e tests. After you add or move a `PageLayout` import, run `yarn knip` from the repo root (or `yarn knip` in `packages/app` if configured) so new consumers stay wired.
211 changes: 149 additions & 62 deletions packages/app/src/DBSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import CodeMirror from '@uiw/react-codemirror';
import api, { useCompleteOnboardingTask } from '@/api';
import { ActiveFilterPills } from '@/components/ActiveFilterPills';
import { AlertStatusIcon } from '@/components/AlertStatusIcon';
import { ResponsiveSidePanel } from '@/components/CompactViewport/ResponsiveSidePanel';
import { useCompactViewport } from '@/components/CompactViewport/useCompactViewport';
import { ContactSupportText } from '@/components/ContactSupportText';
import { DBSearchPageFilters } from '@/components/DBSearchPageFilters';
import { cleanClickHouseExpression } from '@/components/DBSearchPageFilters/utils';
Expand Down Expand Up @@ -1117,6 +1119,31 @@ function DBSearchPageContent() {

const [isFilterSidebarCollapsed, setIsFilterSidebarCollapsed] =
useLocalStorage<boolean>('isFilterSidebarCollapsed', false);
// Compact open state stays out of `isFilterSidebarCollapsed`. Writing that
Comment thread
elizabetdev marked this conversation as resolved.
Resolved
Comment thread
elizabetdev marked this conversation as resolved.
Resolved
// 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);

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 — The new compact search behaviour has no test

The PR's main claims are that opening or closing the drawer never writes the isFilterSidebarCollapsed localStorage key, that filters start closed below 900px, and that the Columns toggle shows and hides SELECT/ORDER BY. None of these are tested; the only DBSearchPage test change mocks useWindowSize to a desktop width. Add a DBSearchPage test with a compact width that clicks Show filters / Close and checks localStorage is unchanged, and that toggles Columns.

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 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
: isFilterSidebarCollapsed;
Comment thread
elizabetdev marked this conversation as resolved.
Resolved
const collapseFilters = useCallback(() => {
if (isCompact) {
setIsCompactFiltersOpen(false);
return;
}
setIsFilterSidebarCollapsed(true);
}, [isCompact, setIsFilterSidebarCollapsed]);
const expandFilters = useCallback(() => {
if (isCompact) {
setIsCompactFiltersOpen(true);
return;
}
setIsFilterSidebarCollapsed(false);
}, [isCompact, setIsFilterSidebarCollapsed]);

const [denoiseResults, _setDenoiseResults] = useQueryState(
'denoise',
Expand Down Expand Up @@ -2209,6 +2236,52 @@ 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>
</>
);
};

return (
<Flex
direction="column"
Expand Down Expand Up @@ -2345,7 +2418,12 @@ function DBSearchPageContent() {
className={searchPageStyles.searchForm}
>
{/* <DevTool control={control} /> */}
<Flex gap="sm" px="sm" pt="sm" wrap="nowrap">
<Flex
gap={isCompact ? 'xs' : 'sm'}
px="sm"
pt={isCompact ? 4 : 'sm'}
wrap={isCompact ? 'wrap' : 'nowrap'}
>
<SourceSelectControlled
key={`${savedSearchId}`}
size="xs"
Expand All @@ -2360,42 +2438,17 @@ function DBSearchPageContent() {
)}
allowedSourceKinds={ALLOWED_SOURCE_KINDS}
data-testid="source-selector"
style={{ minWidth: 150 }}
style={
isCompact ? { flex: '1 1 140px', minWidth: 0 } : { minWidth: 150 }
}
/>
<SourceSchemaPreview
source={inputSourceObj}
controlled
open={isSourceSchemaPreviewOpen}
onClose={() => setIsSourceSchemaPreviewOpen(false)}
/>
<Box style={{ flex: '1 1 0%', minWidth: 100 }}>
<SQLInlineEditorControlled
tableConnection={inputSourceTableConnection}
control={control}
name="select"
defaultValue={defaultSearchConfig.select}
placeholder={defaultSearchConfig.select || 'SELECT Columns'}
onSubmit={onSubmit}
label="SELECT"
size="xs"
allowMultiline
dateRange={searchedTimeRange}
sourceId={inputSource}
/>
</Box>
<Box style={{ maxWidth: 400, width: '20%' }}>
<SQLInlineEditorControlled
tableConnection={inputSourceTableConnection}
control={control}
name="orderBy"
defaultValue={defaultSearchConfig.orderBy}
onSubmit={onSubmit}
label="ORDER BY"
size="xs"
dateRange={searchedTimeRange}
sourceId={inputSource}
/>
</Box>
{!isCompact && columnFields(true, false)}
<>
{!savedSearchId ? (
<Button
Expand Down Expand Up @@ -2434,8 +2487,24 @@ function DBSearchPageContent() {
</Group>
</Button>
)}
{isCompact && (
Comment thread
elizabetdev marked this conversation as resolved.
Resolved
<Button
variant="subtle"
size="xs"
style={{ flexShrink: 0 }}
aria-expanded={columnsOpen}
onClick={() => setColumnsOpen(open => !open)}
>
{columnsOpen ? 'Hide columns' : 'Columns'}
</Button>
)}
</>
</Flex>
{isCompact && columnsOpen && (
<Flex direction="column" gap={4} px="sm" pt={4}>
{columnFields(false, true)}
</Flex>
)}
<SourceEditModal
opened={modelFormExpanded}
onClose={onModelFormExpandClose}
Expand All @@ -2446,7 +2515,12 @@ function DBSearchPageContent() {
onClose={setNewSourceModalClosed}
onCreate={onNewSourceCreate}
/>
<Flex gap="sm" mt="sm" px="sm" wrap="wrap">
<Flex
gap={isCompact ? 'xs' : 'sm'}
mt={isCompact ? 4 : 'sm'}
px="sm"
wrap="wrap"
>
<SearchWhereInput
tableConnection={inputSourceTableConnection}
control={control}
Expand Down Expand Up @@ -2532,7 +2606,7 @@ function DBSearchPageContent() {
/>
<Flex
direction="column"
style={{ overflow: 'hidden', height: '100%' }}
style={{ overflow: 'hidden', flex: 1, minHeight: 0 }}
className="bg-body"
>
{!queryReady ? (
Expand All @@ -2544,14 +2618,12 @@ function DBSearchPageContent() {
/>
) : (
<>
<div
<ResponsiveSidePanel
className={searchPageStyles.searchPageContainer}
style={{
minHeight: 0,
height: '100%',
}}
>
{!isFilterSidebarCollapsed && (
opened={!filtersCollapsed}
onClose={collapseFilters}
title="Filters"
panel={
<ErrorBoundary message="Unable to render search filters">
<DBSearchPageFilters
denoiseResults={denoiseResults}
Expand All @@ -2568,11 +2640,13 @@ function DBSearchPageContent() {
}
onColumnToggle={toggleColumn}
displayedColumns={displayedColumns}
onCollapse={() => setIsFilterSidebarCollapsed(true)}
onCollapse={isCompact ? undefined : collapseFilters}
fill={isCompact}
{...searchFilters}
/>
</ErrorBoundary>
)}
}
>
{analysisMode === 'pattern' &&
histogramTimeChartConfig != null && (
<Flex direction="column" w="100%" gap="0px" mih="0" miw={0}>
Expand All @@ -2583,10 +2657,8 @@ function DBSearchPageContent() {
style={{ width: '100%' }}
>
<SearchResultsCountGroup
isFilterSidebarCollapsed={isFilterSidebarCollapsed}
onExpandFilters={() =>
setIsFilterSidebarCollapsed(false)
}
isFilterSidebarCollapsed={filtersCollapsed}
onExpandFilters={expandFilters}
histogramTimeChartConfig={histogramTimeChartConfig}
/>
<SearchNumRows
Expand All @@ -2604,7 +2676,11 @@ function DBSearchPageContent() {
</Box>
{!hasQueryError && (
<Box
className={searchPageStyles.timeChartContainer}
className={
isCompact
? `${searchPageStyles.timeChartContainer} ${searchPageStyles.timeChartContainerCompact}`
: searchPageStyles.timeChartContainer
}
mih="0"
>
<DBTimeChart
Expand Down Expand Up @@ -2652,16 +2728,25 @@ function DBSearchPageContent() {
{analysisMode === 'delta' &&
searchedSource != null &&
isTraceSource(searchedSource) && (
<DBSearchHeatmapChart
chartConfig={{
...chartConfig,
dateRange: searchedTimeRange,
with: aliasWith,
}}
isReady={isReady}
source={searchedSource}
onAddFilter={searchFilters.setFilterValue}
/>
<Flex direction="column" mih="0" miw={0} flex="1">
{filtersCollapsed && (
<Box className={searchPageStyles.searchStatsContainer}>
<ExpandFiltersButton onExpand={expandFilters} />
</Box>
)}
<Box flex="1" mih="0">
<DBSearchHeatmapChart
chartConfig={{
...chartConfig,
dateRange: searchedTimeRange,
with: aliasWith,
}}
isReady={isReady}
source={searchedSource}
onAddFilter={searchFilters.setFilterValue}
/>
</Box>
</Flex>
)}
{analysisMode === 'results' && (
<Flex direction="column" mih="0" miw={0}>
Expand All @@ -2674,10 +2759,8 @@ function DBSearchPageContent() {
style={{ width: '100%' }}
>
<SearchResultsCountGroup
isFilterSidebarCollapsed={isFilterSidebarCollapsed}
onExpandFilters={() =>
setIsFilterSidebarCollapsed(false)
}
isFilterSidebarCollapsed={filtersCollapsed}
onExpandFilters={expandFilters}
histogramTimeChartConfig={histogramTimeChartConfig}
enableParallelQueries
/>
Expand All @@ -2704,7 +2787,11 @@ function DBSearchPageContent() {
</Box>
{!hasQueryError && (
<Box
className={searchPageStyles.timeChartContainer}
className={
isCompact
? `${searchPageStyles.timeChartContainer} ${searchPageStyles.timeChartContainerCompact}`
: searchPageStyles.timeChartContainer
}
mih="0"
>
<DBTimeChart
Expand Down Expand Up @@ -2884,7 +2971,7 @@ function DBSearchPageContent() {
)}
</Flex>
)}
</div>
</ResponsiveSidePanel>
</>
)}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ jest.mock('@/utils', () => ({
jest.fn(),
],
usePrevious: (value: unknown) => value,
useWindowSize: () => ({ width: 1200, height: 800 }),
}));

jest.mock('@tanstack/react-query', () => ({
Expand Down
Loading
Loading