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
10 changes: 10 additions & 0 deletions .changeset/shareable-fullscreen-tile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@hyperdx/app': minor
---

feat: keep the fullscreen dashboard tile in the URL, so a single tile can be
shared by link. `fullscreenTileId` holds the tile, and `fullscreenFrom`,
`fullscreenTo` and `fullscreenGranularity` hold the range and granularity
picked inside the fullscreen view, separate from the dashboard's own. Opening
the link lands on that tile in fullscreen, browser back/forward steps through
the view, and the other dashboard URL params are kept.
228 changes: 199 additions & 29 deletions packages/app/src/DBDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import { pick } from 'lodash';
import {
parseAsArrayOf,
parseAsBoolean,
parseAsFloat,
parseAsString,
parseAsStringEnum,
useQueryState,
useQueryStates,
} from 'nuqs';
import { ErrorBoundary } from 'react-error-boundary';
import RGL from 'react-grid-layout';
Expand All @@ -29,6 +32,7 @@ import {
import {
convertToDashboardTemplate,
Granularity,
isDateRangeEqual,
isTimeSeriesDisplayType,
savedChartConfigSupportsAlerts,
} from '@hyperdx/common-utils/dist/core/utils';
Expand Down Expand Up @@ -483,6 +487,22 @@ const TilePlaceholder = ({
</ChartContainer>
);

type FullscreenTileView = {
dateRange?: [Date, Date];
granularity?: Granularity | 'auto';
};

// Module-level so useQueryStates gets a stable key map and setter.
const fullscreenQueryStateMap = {
fullscreenTileId: parseAsString,
fullscreenFrom: parseAsFloat,
fullscreenTo: parseAsFloat,
fullscreenGranularity: parseAsStringEnum<Granularity | 'auto'>([
...Object.values(Granularity),
'auto',
]),
};

const Tile = ({
chart,
dateRange,
Expand All @@ -501,6 +521,7 @@ const Tile = ({
showAlertAnnotations,
showReleaseAnnotations,
isLive,
isLiveMode,
readOnly,
onFilter,

Expand All @@ -512,6 +533,10 @@ const Tile = ({
onTouchEnd,
children,
isHighlighted,
isFullscreen,
onFullscreenChange,
fullscreenView,
onFullscreenViewChange,
isSelected,
onSelect,
ref,
Expand Down Expand Up @@ -543,6 +568,11 @@ const Tile = ({
// When true, draw release markers on this tile's chart.
showReleaseAnnotations?: boolean;
isLive?: boolean;
/**
* The dashboard is in live mode. Unlike `isLive`, stays true while the
* browser tab is hidden and refreshes pause.
*/
isLiveMode?: boolean;
readOnly?: boolean;
/** Set when an ad hoc filter broadcasts to this tile; clicked values update it. */
onFilter?: TileFilterHandler;
Expand All @@ -555,11 +585,15 @@ const Tile = ({
onTouchEnd?: (e: React.TouchEvent) => void;
children?: React.ReactNode; // Resizer tooltip
isHighlighted?: boolean;
isFullscreen: boolean;
onFullscreenChange: (isFullscreen: boolean) => void;
/** The fullscreen view's own picker values, where they differ from the dashboard's. */
fullscreenView?: FullscreenTileView;
onFullscreenViewChange: (view: FullscreenTileView) => void;
isSelected?: boolean;
onSelect?: (tileId: string) => void;
ref?: ForwardedRef<HTMLDivElement>;
}) => {
const [isFullscreen, setIsFullscreen] = useState(false);
const [isFocused, setIsFocused] = useState(false);

// A live dashboard's granularity is the coarse refresh interval; heatmaps
Expand Down Expand Up @@ -591,35 +625,78 @@ const Tile = ({

const timeZone = useDisplayTimeZone();

// Date range and granularity state local to the fullscreen view so that
// changing them does not propagate up to the dashboard.
const [fullscreenDateRange, setFullscreenDateRange] =
useState<[Date, Date]>(dateRange);
// The fullscreen view starts from the dashboard's range and granularity.
// Its own picker changes go to `fullscreenView` (URL params read only by
// this view), so they never refetch the dashboard. `fullscreenSeed` holds
// the dashboard values the view starts from, or null while closed. It
// follows the dashboard when those values change underneath (back/forward,
// a shared link whose range resolves after mount), except on a live
// dashboard, whose range moves every refresh.
const [fullscreenSeed, setFullscreenSeed] = useState<{
dateRange: [Date, Date];
granularity: SQLInterval | undefined;
} | null>(null);
const isOpeningFullscreen = isFullscreen && fullscreenSeed == null;
if (!isFullscreen && fullscreenSeed != null) {

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 — The new reseed rules are untested: following the dashboard range while open, and the live-mode exception

No spec changes the dashboard range or granularity while fullscreen is open (for example, back across a time-range change), and none runs in live mode or with the tab hidden. Commit b8cd7b5 fixes exactly that case. Add an e2e case for back/forward across a range change with the tile open. Add another that turns on live mode, changes the fullscreen picker, and checks the picker survives a refresh.

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

Choose a reason for hiding this comment

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

Added the live-mode case in f68ae78. It turns on live mode, changes both fullscreen pickers, then hides and re-shows the tab, and checks the picker values are kept. It fails on the commit before b8cd7b5 and passes now. I haven't added the back/forward case: while fullscreen is open the modal covers the dashboard's own pickers, so no history entry can hold the tile open across a dashboard range change. The reseed-after-mount path is covered by "a link with the param opens that tile fullscreen with the URL time range and granularity".

setFullscreenSeed(null);
} else if (
isOpeningFullscreen ||
(isFullscreen &&
fullscreenSeed != null &&
!isLiveMode &&
(fullscreenSeed.dateRange !== dateRange ||
fullscreenSeed.granularity !== granularity))
) {
setFullscreenSeed({ dateRange, granularity });
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}
const fullscreenDateRange =
fullscreenView?.dateRange ?? fullscreenSeed?.dateRange ?? dateRange;
const fullscreenGranularity: Granularity | 'auto' =
fullscreenView?.granularity ??
((fullscreenSeed ? fullscreenSeed.granularity : granularity) as
| Granularity
| undefined) ??
'auto';

// Rewrite the picker text on open and when the range changes from outside
// it (back/forward, chart brush), but keep what the user typed or picked
// ("Last 15 minutes") for the range their own search produced.
const [fullscreenInputValue, setFullscreenInputValue] =
useTimeRangeInputText(fullscreenDateRange);
const [fullscreenGranularity, setFullscreenGranularity] = useState<
Granularity | 'auto' | undefined
>(() => (granularity as Granularity | undefined) ?? 'auto');

const openFullscreen = useCallback(() => {
// Reinitialize to the dashboard's current date range and granularity
// each time the fullscreen view is opened.
setFullscreenDateRange(dateRange);
setFullscreenInputValue(dateRangeToString(dateRange, timeZone));
setFullscreenGranularity(
(granularity as Granularity | undefined) ?? 'auto',
);
setIsFullscreen(true);
}, [dateRange, granularity, timeZone, setFullscreenInputValue]);
const [fullscreenInputRange, setFullscreenInputRange] =
useState(fullscreenDateRange);
const [fullscreenSearchedRange, setFullscreenSearchedRange] = useState<
[Date, Date] | null
>(null);
if (
isOpeningFullscreen ||
!isDateRangeEqual(fullscreenInputRange, fullscreenDateRange)
) {
setFullscreenInputRange(fullscreenDateRange);
setFullscreenSearchedRange(null);
if (
isOpeningFullscreen ||
fullscreenSearchedRange == null ||
!isDateRangeEqual(fullscreenSearchedRange, fullscreenDateRange)
) {
setFullscreenInputValue(dateRangeToString(fullscreenDateRange, timeZone));
}
}

const openFullscreen = useCallback(
() => onFullscreenChange(true),
[onFullscreenChange],
);

const handleFullscreenSearch = useCallback(
(value: string) => {
const [start, end] = parseTimeRangeInput(value, timeZone);
if (start != null && end != null) {
setFullscreenDateRange([start, end]);
setFullscreenSearchedRange([start, end]);
onFullscreenViewChange({ dateRange: [start, end] });
}
},
[timeZone],
[timeZone, onFullscreenViewChange],
);

useEffect(() => {
Expand All @@ -636,11 +713,7 @@ const Tile = ({
'f',
() => {
if (!isFocused) return;
if (isFullscreen) {
setIsFullscreen(false);
} else {
openFullscreen();
}
onFullscreenChange(!isFullscreen);
},
],
]);
Expand Down Expand Up @@ -1361,7 +1434,10 @@ const Tile = ({
readOnly
? undefined
: isFullscreenView
? (start, end) => setFullscreenDateRange([start, end])
? (start, end) =>
onFullscreenViewChange({
dateRange: [start, end],
})
: onTimeRangeSelect
}
setDisplayType={
Expand Down Expand Up @@ -1572,6 +1648,7 @@ const Tile = ({
dateRange,
fullscreenDateRange,
fullscreenGranularity,
onFullscreenViewChange,
filterWarning,
isSourceMissing,
isSourceUnset,
Expand Down Expand Up @@ -1666,7 +1743,7 @@ const Tile = ({
{/* Fullscreen Modal */}
<FullscreenPanelModal
opened={isFullscreen}
onClose={() => setIsFullscreen(false)}
onClose={() => onFullscreenChange(false)}
>
{isFullscreen && (
<Flex direction="column" gap="sm" h="100%" w="100%">
Expand All @@ -1678,7 +1755,9 @@ const Tile = ({
/>
<GranularityPicker
value={fullscreenGranularity}
onChange={setFullscreenGranularity}
onChange={value =>
onFullscreenViewChange({ granularity: value ?? 'auto' })
}
/>
</Flex>
<Box style={{ flex: 1, minHeight: 0 }}>
Expand Down Expand Up @@ -1976,6 +2055,50 @@ function DBDashboardPage({
const { data: allDashboards } = useDashboards();

const [highlightedTileId] = useQueryState('highlightedTileId');
// The fullscreen tile and the range and granularity picked inside its view,
// so a link reopens exactly that view. Kept apart from `from`/`to` and
// `granularity` so fullscreen changes don't refetch every dashboard tile.
// Pushed (not replaced) so back/forward steps through them.
const [fullscreenState, setFullscreenState] = useQueryStates(
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
fullscreenQueryStateMap,
{ history: 'push' },
);
const { fullscreenTileId, fullscreenFrom, fullscreenTo } = fullscreenState;
const fullscreenView = useMemo((): FullscreenTileView => {
const hasRange =
fullscreenFrom != null &&
fullscreenTo != null &&
Number.isFinite(fullscreenFrom) &&
Number.isFinite(fullscreenTo) &&
fullscreenFrom < fullscreenTo;
return {
dateRange: hasRange
? [new Date(fullscreenFrom), new Date(fullscreenTo)]
: undefined,
granularity: fullscreenState.fullscreenGranularity ?? undefined,
};
}, [fullscreenFrom, fullscreenTo, fullscreenState.fullscreenGranularity]);
const setFullscreenTileId = useCallback(
(tileId: string | null) =>
setFullscreenState({
fullscreenTileId: tileId,
fullscreenFrom: null,
fullscreenTo: null,
fullscreenGranularity: null,
}),
[setFullscreenState],
);
const setFullscreenView = useCallback(
({ dateRange, granularity }: FullscreenTileView) =>
setFullscreenState({
...(dateRange && {
fullscreenFrom: dateRange[0].getTime(),
fullscreenTo: dateRange[1].getTime(),
}),
...(granularity && { fullscreenGranularity: granularity }),
}),
[setFullscreenState],
);

const [granularity, setGranularity] = useQueryState(
'granularity',
Expand Down Expand Up @@ -2544,6 +2667,7 @@ function DBDashboardPage({
onEditClick={() => setEditedTile(chart)}
readOnly={isKioskMode}
isLive={isRefreshEnabled}
isLiveMode={isLive || isKioskMode}
granularity={
isRefreshEnabled ? granularityOverride : (granularity ?? undefined)
}
Expand All @@ -2555,6 +2679,14 @@ function DBDashboardPage({
showAlertAnnotations={showAlertAnnotations}
showReleaseAnnotations={showReleaseAnnotations}
isHighlighted={highlightedTileId === chart.id}
isFullscreen={fullscreenTileId === chart.id}
onFullscreenChange={isFullscreen =>
setFullscreenTileId(isFullscreen ? chart.id : null)
}
fullscreenView={
fullscreenTileId === chart.id ? fullscreenView : undefined
}
onFullscreenViewChange={setFullscreenView}
onUpdateChart={
isKioskMode
? undefined
Expand Down Expand Up @@ -2644,9 +2776,14 @@ function DBDashboardPage({
dashboard,
searchedTimeRange,
isRefreshEnabled,
isLive,
granularityOverride,
granularity,
highlightedTileId,
fullscreenTileId,
setFullscreenTileId,
fullscreenView,
setFullscreenView,
confirm,
setDashboard,
onTimeRangeSelect,
Expand Down Expand Up @@ -2741,6 +2878,39 @@ function DBDashboardPage({
],
);

// The fullscreen view renders inside its tile, so a ?fullscreenTileId link
// must activate the tile's tab and expand its group for the tile to mount.
// A tile ID that matches no tile leaves the dashboard as it is.
useEffect(() => {

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 — The new tile-reveal effect repeats the existing highlightedTileId tab-switch effect

The effect at DBDashboardPage.tsx:2451 already finds the tile, looks up its container and calls setUrlActiveTabs when getActiveTabId(container) !== tile.tabId. This new effect repeats that and also expands collapsed groups. Move it into one helper, e.g. revealTile(tileId), and call it from both effects. That way a ?highlightedTileId link to a tile in a collapsed group also gets expanded, and the two copies 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

Choose a reason for hiding this comment

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

Leaving this out of this PR. A shared revealTile would also change how ?highlightedTileId links behave (they would start expanding collapsed groups), so it fits better as a separate follow-up than inside the fullscreen change.

if (!fullscreenTileId || !dashboard) return;
const tile = dashboard.tiles.find(t => t.id === fullscreenTileId);
const container = tile?.containerId
? containers.find(c => c.id === tile.containerId)
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
: undefined;
if (!tile || !container) return;
const { tabId } = tile;
// A stale tabId never becomes active, so setting it would loop.
const isKnownTab = container.tabs?.some(t => t.id === tabId) ?? false;
if (tabId && isKnownTab && getActiveTabId(container) !== tabId) {
setUrlActiveTabs(prev => ({ ...(prev ?? {}), [container.id]: tabId }));
}
if (isContainerCollapsed(container)) {
addToUrlSet(setUrlExpandedIds, container.id);
removeFromUrlSet(setUrlCollapsedIds, container.id);
}
}, [
fullscreenTileId,
dashboard,
containers,
getActiveTabId,
isContainerCollapsed,
setUrlActiveTabs,
addToUrlSet,
removeFromUrlSet,
setUrlCollapsedIds,
setUrlExpandedIds,
]);

// Collapsible-only subset, used both for bulk collapse/expand and for
// disabling the menu items when nothing can be toggled.
const collapsibleContainers = useMemo(
Expand Down
Loading
Loading