Compare commits

...

12 Commits

Author SHA1 Message Date
Abhi Kumar
ff1cc79c00 feat(dashboard-v2): pin the query-type tabs to the top of the editor scroll area
Make the query-type tab nav + Run Query button sticky so they stay visible
while the query body scrolls underneath; move the top padding onto the nav so
it keeps its spacing at rest and when pinned.
2026-07-09 00:27:45 +05:30
Abhi Kumar
83dc3ef430 feat(dashboard-v2): support per-series legend colors for bar and histogram panels
Route BarChartPanel and HistogramPanel through the time-series legend path in
useLegendSeries and enable the Legend `colors` control in both kinds' sections,
extending the per-series color overrides to these kinds.
2026-07-09 00:27:31 +05:30
Abhi Kumar
03114ed645 refactor(dashboard-v2): read panel time preference via shared helper
Panel.tsx read visualization.timePreference through an inline cast; replace it
with getPanelTimePreference so the header pill and NoData's extend gate share
one reader.
2026-07-09 00:26:04 +05:30
Abhi Kumar
890234ac6c fix(dashboard-v2): hide "Extend time range" for panels with a fixed time preference
A panel locked to a non-global timePreference queries a fixed relative span
anchored to the dashboard end, so widening the ambient window can't surface
data for it — the "Extend time range" CTA was a no-op. NoData now takes the
panel and, via panelHasFixedTimePreference, drops the global extender for such
panels (only Retry remains). The View modal's local extender still wins.
2026-07-09 00:25:43 +05:30
Abhi Kumar
ec04a885f4 fix(dashboard-v2): lazy-load panels per-panel instead of per-section
Move the viewport intersection observer down from Section to a new
SectionGridItem wrapper so each panel gates its own fetch. A board with
many panels now only queries the ones actually on screen, instead of
loading every panel in any section that scrolls into view.
2026-07-08 23:49:28 +05:30
Abhi Kumar
a71aacc8fd fix(dashboard-v2): hide the empty panel header in editor preview
When a panel has no title, description, or status and the actions menu is
suppressed (editor preview), render nothing instead of an empty header bar.
Add a min-height so the header keeps a stable size when it does render.
2026-07-08 23:49:28 +05:30
Abhi Kumar
05f3862e23 feat(dashboard-v2): offer dashboard root and every section in the move menu
Rework the "Move to section" submenu to list the dashboard root plus every
titled section (minus the panel's own), instead of only titled sections with
a separate "move out of section" entry. Hide it entirely when there is
nowhere to move.
2026-07-08 23:49:28 +05:30
Abhi Kumar
d26a904d94 feat(dashboard-v2): support per-slice color overrides for pie charts
Enable the legend colors control for pie charts. The control is fed by
useLegendSeries, which only handled time-series data, so pie returned no
series. Resolve pie legend series from the same scalar slices the renderer
draws (without overrides, for default colors) so the color keys match what
the chart looks up.

Extract the series resolution into utils/legendSeries.ts (a shared dedupe
primitive plus a pie and a time-series resolver) and reduce the hook to a
kind switch that returns none for kinds without a colors control.
2026-07-08 23:49:28 +05:30
Abhi Kumar
85895d6c4f fix(dashboard-v2): measure chart dimensions before first paint
useResizeObserver seeded its size to 0 and only reported real dimensions
after paint via its debounced observer, so charts rendered once at 0 then
jumped — most visibly the pie legend, which rendered left-aligned then
re-centered once it learned it fit on one row. Add a useLayoutEffect that
measures the element synchronously before paint. In jsdom clientWidth is 0,
so tests are unaffected.
2026-07-08 23:49:28 +05:30
Abhi Kumar
2efbd04ae1 feat(dashboard-v2): add the list columns editor and pagination loader to the view modal
Surface the List panel's columns editor in the View modal (as in the full
editor) by exposing setSpec from useViewPanelMode and wiring it into the
query-builder footer. Its add-column combobox portals to body, so inside
the modal it opened behind the dialog — lift its z-index above the
query-builder popups so it stacks on top.

Also thread isPreviousData into PreviewPane so the List panel's page-change
loader shows during pagination, matching the full editor and dashboard.
2026-07-08 23:49:27 +05:30
Abhi Kumar
bb9acc2f65 fix(dashboard-v2): make antd popups usable inside the view panel modal
The editor's antd Selects/pickers portal to document.body, outside the
modal Radix dialog, where Radix disables pointer events and traps focus, so
their menus opened but couldn't be clicked. Wrap the modal body in an antd
ConfigProvider whose getPopupContainer points at the dialog content, so all
antd popups render inside the interactive, focus-trapped layer.
2026-07-08 21:26:26 +05:30
Abhi Kumar
67608b1d8c fix(dashboard-v2): tint chart-legend checkbox with its series color
The @signozhq/ui Checkbox declares --checkbox-checked-background on the
element itself via its data-color rule, so a value set on an ancestor was
shadowed and the per-series tint never applied. Feed the color through a
private --series-color var and override the vars on the element with a
selector that out-specifies the library rule.
2026-07-08 21:26:26 +05:30
41 changed files with 584 additions and 210 deletions

View File

@@ -0,0 +1,4 @@
.wrapper :global(button[data-color]) {
--checkbox-checked-background: var(--series-color);
--checkbox-border-color: var(--series-color);
}

View File

@@ -3,6 +3,7 @@ import { Checkbox } from '@signozhq/ui/checkbox';
import { CSSProperties } from 'react';
import { CheckBoxProps } from '../types';
import styles from './CustomCheckBox.module.scss';
function CustomCheckBox({
data,
@@ -15,12 +16,11 @@ function CustomCheckBox({
const isChecked = graphVisibilityState[index] || false;
const colorStyle = {
'--checkbox-checked-background': color,
'--checkbox-border-color': color,
'--series-color': color,
} as CSSProperties;
return (
<span style={colorStyle}>
<span className={styles.wrapper} style={colorStyle}>
<Checkbox
onChange={(checked): void => checkBoxOnChangeHandler(checked, index)}
value={isChecked}

View File

@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useLayoutEffect, useState } from 'react';
import debounce from 'lodash-es/debounce';
export type Dimensions = {
@@ -15,6 +15,15 @@ export function useResizeObserver<T extends HTMLElement>(
height: ref.current?.clientHeight || 0,
});
// Measure before paint so the first frame has real dimensions, not 0 (the
// debounced observer below only catches up after paint → layout jump).
useLayoutEffect(() => {
const node = ref.current;
if (node) {
setSize({ width: node.clientWidth, height: node.clientHeight });
}
}, [ref]);
useEffect(() => {
const handleResize = debounce(
(entries: ResizeObserverEntry[]) => {

View File

@@ -8,7 +8,7 @@ import { getPanelDefinition } from 'pages/DashboardPageV2/DashboardContainer/Pan
import { resolveSignal } from 'pages/DashboardPageV2/DashboardContainer/Panels/utils/getBuilderQueries';
import type { EQueryType } from 'types/common/dashboard';
import type { LegendSeries } from '../hooks/useLegendSeries';
import type { LegendSeries } from '../utils/legendSeries';
import type { TableColumnOption } from '../hooks/useTableColumns';
import ConfigActions from './ConfigActions/ConfigActions';
import SectionSlot from './SectionSlot/SectionSlot';

View File

@@ -5,7 +5,7 @@ import { Input } from 'antd';
import type { DashboardtypesLegendDTOCustomColors } from 'api/generated/services/sigNoz.schemas';
import { Virtuoso } from 'react-virtuoso';
import type { LegendSeries } from '../../../hooks/useLegendSeries';
import type { LegendSeries } from '../../../utils/legendSeries';
import LegendColorRow from './LegendColorRow';
import {
clearSeriesColor,

View File

@@ -1,6 +1,6 @@
import { fireEvent, render, screen } from '@testing-library/react';
import type { LegendSeries } from '../../../../hooks/useLegendSeries';
import type { LegendSeries } from '../../../../utils/legendSeries';
import LegendColors from '../LegendColors';
const SERIES: LegendSeries[] = [

View File

@@ -1,4 +1,4 @@
import type { LegendSeries } from '../../../../hooks/useLegendSeries';
import type { LegendSeries } from '../../../../utils/legendSeries';
import {
clearSeriesColor,
filterLegendSeries,

View File

@@ -1,6 +1,6 @@
import type { DashboardtypesLegendDTOCustomColors } from 'api/generated/services/sigNoz.schemas';
import type { LegendSeries } from '../../../hooks/useLegendSeries';
import type { LegendSeries } from '../../../utils/legendSeries';
/** Case-insensitive substring filter over series labels. Empty query → all series. */
export function filterLegendSeries(

View File

@@ -1,7 +1,7 @@
import type { TelemetrytypesSignalDTO } from 'api/generated/services/sigNoz.schemas';
import type { PanelKind } from '../../Panels/types/panelKind';
import type { LegendSeries } from '../hooks/useLegendSeries';
import type { LegendSeries } from '../utils/legendSeries';
import type { TableColumnOption } from '../hooks/useTableColumns';
import { EQueryType } from 'types/common/dashboard';

View File

@@ -7,4 +7,9 @@
.dropdown {
width: 260px;
/* The dropdown portals to body; lift it above the query builder's antd
* popups (1050) so it stays clickable, incl. inside the View modal.
* TODO: remove after the antd -> @signozhq/ui migration
**/
z-index: 1100;
}

View File

@@ -63,7 +63,7 @@ function AddColumnDropdown({
<Plus size={16} />
</Button>
</ComboboxTrigger>
<ComboboxContent arrow side="top" align="end" className={styles.dropdown}>
<ComboboxContent arrow side="bottom" align="end" className={styles.dropdown}>
<ComboboxCommand shouldFilter={false}>
<ComboboxInput
value={searchText}

View File

@@ -10,7 +10,9 @@
}
.scrollArea {
padding: 12px;
// Top padding lives on the sticky tab nav instead, so the nav keeps its
// breathing room both at rest and when pinned to the top.
padding: 0 12px 12px 12px;
}
.tabsContainer {
@@ -24,6 +26,15 @@
background-color: var(--l1-background) !important;
}
:global(.ant-tabs-nav) {
// Pin the query-type tabs + Run Query button to the top of the
// `.container` scroll area while the query body scrolls underneath.
// `padding-top` owns the nav's top spacing (moved off `.scrollArea`).
position: sticky;
top: 0px;
z-index: 1100;
padding-top: 12px;
background-color: var(--l1-background);
&::before {
border-color: var(--l2-border);
}

View File

@@ -2,6 +2,7 @@ import { renderHook } from '@testing-library/react';
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
import { useIsDarkMode } from 'hooks/useDarkMode';
import { generateColor } from 'lib/uPlotLib/utils/generateColor';
import { preparePieData } from 'pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/prepareData';
import { resolveSeriesLabelV5 } from 'pages/DashboardPageV2/DashboardContainer/Panels/utils/resolveSeriesLabel';
import type { PanelQueryData } from 'pages/DashboardPageV2/DashboardContainer/queryV5/types';
import { flattenTimeSeries } from 'pages/DashboardPageV2/DashboardContainer/queryV5/v5ResponseData';
@@ -29,18 +30,36 @@ jest.mock(
() => ({
flattenTimeSeries: jest.fn(),
getTimeSeriesResults: jest.fn(() => []),
getScalarResults: jest.fn(() => []),
}),
);
jest.mock(
'pages/DashboardPageV2/DashboardContainer/queryV5/prepareScalarTables',
() => ({ prepareScalarTables: jest.fn(() => []) }),
);
jest.mock(
'pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/prepareData',
() => ({ preparePieData: jest.fn(() => []) }),
);
const mockUseIsDarkMode = useIsDarkMode as unknown as jest.Mock;
const mockFlatten = flattenTimeSeries as unknown as jest.Mock;
const mockResolveLabel = resolveSeriesLabelV5 as unknown as jest.Mock;
const mockGenerateColor = generateColor as unknown as jest.Mock;
const mockPreparePie = preparePieData as unknown as jest.Mock;
const PANEL = {
kind: 'Panel',
spec: { plugin: { kind: 'signoz/TimeSeriesPanel', spec: {} }, queries: [] },
} as unknown as DashboardtypesPanelDTO;
const PIE_PANEL = {
kind: 'Panel',
spec: { plugin: { kind: 'signoz/PieChartPanel', spec: {} }, queries: [] },
} as unknown as DashboardtypesPanelDTO;
const HISTOGRAM_PANEL = {
kind: 'Panel',
spec: { plugin: { kind: 'signoz/HistogramPanel', spec: {} }, queries: [] },
} as unknown as DashboardtypesPanelDTO;
const DATA = { response: {}, legendMap: {} } as unknown as PanelQueryData;
// Each flattened series carries the label resolveSeriesLabelV5 should report.
@@ -88,6 +107,32 @@ describe('useLegendSeries', () => {
]);
});
it('resolves histogram panels via the time-series path', () => {
mockFlatten.mockReturnValue(seriesWithLabels(['a', 'b']));
const { result } = renderHook(() => useLegendSeries(HISTOGRAM_PANEL, DATA));
expect(result.current).toStrictEqual([
{ label: 'a', defaultColor: 'color:a' },
{ label: 'b', defaultColor: 'color:b' },
]);
// The pie path must not run for a histogram panel.
expect(mockPreparePie).not.toHaveBeenCalled();
});
it('resolves pie panels from their scalar slices, deduped by label', () => {
mockPreparePie.mockReturnValue([
{ label: 'x', color: 'c1' },
{ label: 'y', color: 'c2' },
{ label: 'x', color: 'c1' },
]);
const { result } = renderHook(() => useLegendSeries(PIE_PANEL, DATA));
expect(result.current).toStrictEqual([
{ label: 'x', defaultColor: 'c1' },
{ label: 'y', defaultColor: 'c2' },
]);
// The time-series path must not run for a pie panel.
expect(mockFlatten).not.toHaveBeenCalled();
});
it('uses the dark palette in dark mode and the light palette otherwise', () => {
mockFlatten.mockReturnValue(seriesWithLabels(['a']));

View File

@@ -1,30 +1,19 @@
import { useMemo } from 'react';
import { themeColors } from 'constants/theme';
import { useIsDarkMode } from 'hooks/useDarkMode';
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
import getLabelName from 'lib/getLabelName';
import { generateColor } from 'lib/uPlotLib/utils/generateColor';
import { getBuilderQueries } from 'pages/DashboardPageV2/DashboardContainer/Panels/utils/getBuilderQueries';
import { resolveSeriesLabelV5 } from 'pages/DashboardPageV2/DashboardContainer/Panels/utils/resolveSeriesLabel';
import type { PanelQueryData } from 'pages/DashboardPageV2/DashboardContainer/queryV5/types';
import {
flattenTimeSeries,
getTimeSeriesResults,
} from 'pages/DashboardPageV2/DashboardContainer/queryV5/v5ResponseData';
export interface LegendSeries {
/** Resolved display label — the key `legend.customColors` is indexed by. */
label: string;
/** The series' auto-assigned color, shown when no override is set. */
defaultColor: string;
}
import {
type LegendSeries,
resolvePieLegendSeries,
resolveTimeSeriesLegendSeries,
} from '../utils/legendSeries';
/**
* Resolves the panel's rendered series into `{ label, defaultColor }` pairs, using the
* exact label resolution the time-series renderer applies (`flattenTimeSeries` →
* `resolveSeriesLabelV5`) and the same `generateColor` default. The legend-colors control
* keys overrides by these labels, so they must match what the chart draws. Deduplicated,
* order-preserving; empty until data arrives or for kinds without flat time-series data.
* Resolves the panel's rendered series into `{ label, defaultColor }` pairs so the
* legend-colors control can key overrides by the exact labels the chart draws. Only the
* kinds that expose a colors control resolve series (Pie from its scalar slices, Time
* Series from its flat series); every other kind returns none.
*/
export function useLegendSeries(
panel: DashboardtypesPanelDTO,
@@ -33,27 +22,15 @@ export function useLegendSeries(
const isDarkMode = useIsDarkMode();
return useMemo(() => {
const palette = isDarkMode
? themeColors.chartcolors
: themeColors.lightModeColor;
const series = flattenTimeSeries(
getTimeSeriesResults(data?.response),
data.legendMap,
);
const builderQueries = getBuilderQueries(panel.spec.queries);
const byLabel = new Map<string, string>();
series.forEach((s) => {
const baseLabel = getLabelName(s.labels, s.queryName, s.legend);
const label = resolveSeriesLabelV5(s, builderQueries, baseLabel);
if (label && !byLabel.has(label)) {
byLabel.set(label, generateColor(label, palette));
}
});
return Array.from(byLabel, ([label, defaultColor]) => ({
label,
defaultColor,
}));
}, [panel.spec.queries, data.response, data.legendMap, isDarkMode]);
switch (panel.spec.plugin.kind) {
case 'signoz/PieChartPanel':
return resolvePieLegendSeries(data, isDarkMode);
case 'signoz/TimeSeriesPanel':
case 'signoz/BarChartPanel':
case 'signoz/HistogramPanel':
return resolveTimeSeriesLegendSeries(panel.spec.queries, data, isDarkMode);
default:
return [];
}
}, [panel.spec.plugin.kind, panel.spec.queries, data, isDarkMode]);
}

View File

@@ -0,0 +1,96 @@
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
import { themeColors } from 'constants/theme';
import getLabelName from 'lib/getLabelName';
import { generateColor } from 'lib/uPlotLib/utils/generateColor';
import { preparePieData } from 'pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/prepareData';
import { getBuilderQueries } from 'pages/DashboardPageV2/DashboardContainer/Panels/utils/getBuilderQueries';
import { resolveSeriesLabelV5 } from 'pages/DashboardPageV2/DashboardContainer/Panels/utils/resolveSeriesLabel';
import { prepareScalarTables } from 'pages/DashboardPageV2/DashboardContainer/queryV5/prepareScalarTables';
import type { PanelQueryData } from 'pages/DashboardPageV2/DashboardContainer/queryV5/types';
import {
flattenTimeSeries,
getScalarResults,
getTimeSeriesResults,
} from 'pages/DashboardPageV2/DashboardContainer/queryV5/v5ResponseData';
export interface LegendSeries {
/** Resolved display label — the key `legend.customColors` is indexed by. */
label: string;
/** The series' auto-assigned color, shown when no override is set. */
defaultColor: string;
}
type PanelQueries = DashboardtypesPanelDTO['spec']['queries'];
/**
* Dedupes `labels` (first-seen order, empties dropped) into `{ label, defaultColor }`
* pairs, resolving each unique label's color lazily via `colorFor` — so a repeated
* label never resolves a second color.
*/
function buildLegendSeries(
labels: readonly string[],
colorFor: (label: string, index: number) => string,
): LegendSeries[] {
const byLabel = new Map<string, string>();
labels.forEach((label, index) => {
if (label && !byLabel.has(label)) {
byLabel.set(label, colorFor(label, index));
}
});
return Array.from(byLabel, ([label, defaultColor]) => ({
label,
defaultColor,
}));
}
/**
* Pie is fed by scalar results, not time series. Reuse the exact slices the renderer
* draws (without overrides, so their colors are the defaults) so the color control keys
* overrides by the same labels the chart does.
*/
export function resolvePieLegendSeries(
data: PanelQueryData,
isDarkMode: boolean,
): LegendSeries[] {
const slices = preparePieData({
tables: prepareScalarTables({
results: getScalarResults(data.response),
legendMap: data.legendMap,
requestPayload: data.requestPayload,
}),
isDarkMode,
});
return buildLegendSeries(
slices.map((slice) => slice.label),
(_, index) => slices[index].color,
);
}
/**
* Time-series kinds: resolve each flattened series' label the way the renderer does
* (`getLabelName` → `resolveSeriesLabelV5`) and color it with `generateColor`.
*/
export function resolveTimeSeriesLegendSeries(
queries: PanelQueries,
data: PanelQueryData,
isDarkMode: boolean,
): LegendSeries[] {
const palette = isDarkMode
? themeColors.chartcolors
: themeColors.lightModeColor;
const builderQueries = getBuilderQueries(queries);
const series = flattenTimeSeries(
getTimeSeriesResults(data.response),
data.legendMap,
);
return buildLegendSeries(
series.map((s) =>
resolveSeriesLabelV5(
s,
builderQueries,
getLabelName(s.labels, s.queryName, s.legend),
),
),
(label) => generateColor(label, palette),
);
}

View File

@@ -1,5 +1,7 @@
import { CalendarRange, Clock, RotateCw } from '@signozhq/icons';
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
import { panelHasFixedTimePreference } from '../../../hooks/resolvePanelTimeWindow';
import {
selectViewPanelExtendWindow,
useViewPanelStore,
@@ -15,6 +17,8 @@ interface NoDataProps {
isFetching?: boolean;
/** When provided, renders a Retry button that re-runs the query. */
onRetry?: () => void;
/** Hides the global "Extend time range" action when this panel is locked to a fixed time preference. */
panel?: DashboardtypesPanelDTO;
'data-testid'?: string;
}
@@ -29,19 +33,30 @@ function NoData({
description = 'Nothing in the selected window. Try widening the range.',
isFetching = false,
onRetry,
panel,
'data-testid': testId = 'panel-no-data',
}: NoDataProps): JSX.Element {
const viewExtend = useViewPanelStore(selectViewPanelExtendWindow);
const globalExtend = useExtendTimeWindow();
const { canExtend, actionLabel, extend } = viewExtend ?? globalExtend;
// The View modal's local extender wins; the global one only applies to a panel that
// follows the ambient window (a fixed preference can't be widened by it).
const hasFixedTimePreference = panel
? panelHasFixedTimePreference(panel)
: false;
const activeExtend =
viewExtend ?? (hasFixedTimePreference ? undefined : globalExtend);
if (isFetching) {
return <PanelLoader />;
}
const extendAction: PanelMessageAction | undefined =
canExtend && actionLabel
? { label: actionLabel, onClick: extend, icon: <CalendarRange size={14} /> }
activeExtend?.canExtend && activeExtend.actionLabel
? {
label: activeExtend.actionLabel,
onClick: activeExtend.extend,
icon: <CalendarRange size={14} />,
}
: undefined;
const retryAction: PanelMessageAction | undefined = onRetry

View File

@@ -1,3 +1,7 @@
import {
DashboardtypesTimePreferenceDTO,
type DashboardtypesPanelDTO,
} from 'api/generated/services/sigNoz.schemas';
import { fireEvent, render, screen } from '@testing-library/react';
import { useViewPanelStore } from '../../../../store/useViewPanelStore';
@@ -24,6 +28,15 @@ function extender(over?: Partial<ExtendTimeWindow>): ExtendTimeWindow {
};
}
/** Minimal panel whose plugin spec carries the given time preference. */
function panelWith(
timePreference?: DashboardtypesTimePreferenceDTO,
): DashboardtypesPanelDTO {
return {
spec: { plugin: { spec: { visualization: { timePreference } } } },
} as unknown as DashboardtypesPanelDTO;
}
describe('NoData', () => {
beforeEach(() => {
mockUseExtendTimeWindow.mockReturnValue(inert);
@@ -119,4 +132,47 @@ describe('NoData', () => {
expect(screen.getByTestId('number-panel-no-data')).toBeInTheDocument();
});
it('hides the global extend action for a panel with a fixed time preference', () => {
const onRetry = jest.fn();
mockUseExtendTimeWindow.mockReturnValue(extender());
render(
<NoData
onRetry={onRetry}
panel={panelWith(DashboardtypesTimePreferenceDTO.last_6_hr)}
/>,
);
// Only Retry — extending the dashboard window can't widen a locked panel span.
const action = screen.getByTestId('panel-no-data-action');
expect(action).toHaveTextContent('Retry');
expect(
screen.queryByTestId('panel-no-data-secondary-action'),
).not.toBeInTheDocument();
});
it('still offers the global extend action for a panel that follows the global window', () => {
mockUseExtendTimeWindow.mockReturnValue(extender());
render(
<NoData panel={panelWith(DashboardtypesTimePreferenceDTO.global_time)} />,
);
expect(screen.getByTestId('panel-no-data-action')).toHaveTextContent(
'Extend time range',
);
});
it('keeps the View modal extender even when the panel has a fixed time preference', () => {
const storeExtend = jest.fn();
mockUseExtendTimeWindow.mockReturnValue(extender());
useViewPanelStore.setState({
viewPanelExtendWindow: extender({ extend: storeExtend }),
});
render(
<NoData panel={panelWith(DashboardtypesTimePreferenceDTO.last_6_hr)} />,
);
fireEvent.click(screen.getByTestId('panel-no-data-action'));
expect(storeExtend).toHaveBeenCalledTimes(1);
});
});

View File

@@ -193,7 +193,7 @@ function BarPanelRenderer({
className={PanelStyles.panelContainer}
>
{flatSeries.length === 0 && (
<NoData isFetching={isFetching} onRetry={refetch} />
<NoData isFetching={isFetching} onRetry={refetch} panel={panel} />
)}
{flatSeries.length > 0 &&
containerDimensions.width > 0 &&

View File

@@ -13,7 +13,7 @@ export const sections: SectionConfig[] = [
},
{ kind: SectionKind.Formatting, controls: { unit: true, decimals: true } },
{ kind: SectionKind.Axes, controls: { minMax: true, logScale: true } },
{ kind: SectionKind.Legend, controls: { position: true } },
{ kind: SectionKind.Legend, controls: { position: true, colors: true } },
{
kind: SectionKind.Thresholds,
controls: { variant: ThresholdVariant.LABEL },

View File

@@ -106,7 +106,7 @@ function HistogramPanelRenderer({
className={PanelStyles.panelContainer}
>
{flatSeries.length === 0 && (
<NoData isFetching={isFetching} onRetry={refetch} />
<NoData isFetching={isFetching} onRetry={refetch} panel={panel} />
)}
{flatSeries.length > 0 &&
containerDimensions.width > 0 &&

View File

@@ -9,7 +9,7 @@ export const sections: SectionConfig[] = [
},
{
kind: SectionKind.Legend,
controls: { position: true },
controls: { position: true, colors: true },
// Merging all queries collapses to one distribution with no legend.
isHidden: (spec): boolean =>
Boolean(

View File

@@ -143,7 +143,7 @@ function ListPanelRenderer({
className={PanelStyles.panelContainer}
>
{!table || dataSource.length === 0 ? (
<NoData isFetching={isFetching} onRetry={refetch} />
<NoData isFetching={isFetching} onRetry={refetch} panel={panel} />
) : (
<>
<div

View File

@@ -130,6 +130,7 @@ function NumberPanelRenderer({
data-testid="number-panel-no-data"
isFetching={isFetching}
onRetry={refetch}
panel={panel}
/>
) : (
<ValueDisplay

View File

@@ -95,7 +95,7 @@ function PiePanelRenderer({
return (
<div data-testid="pie-panel-renderer" className={PanelStyles.panelContainer}>
{slices.length === 0 ? (
<NoData isFetching={isFetching} onRetry={refetch} />
<NoData isFetching={isFetching} onRetry={refetch} panel={panel} />
) : (
<Pie
data={slices}

View File

@@ -1,13 +1,13 @@
import { SectionKind, type SectionConfig } from '../../types/sections';
// Pie has no axes, thresholds, or stacking — just value formatting and a legend.
// Legend `colors` is omitted: the pie legend is always interactive swatches.
// Pie has no axes, thresholds, or stacking — just value formatting and a legend
// (position + per-slice color overrides).
export const sections: SectionConfig[] = [
{
kind: SectionKind.Visualization,
controls: { switchPanelKind: true, timePreference: true },
},
{ kind: SectionKind.Formatting, controls: { unit: true, decimals: true } },
{ kind: SectionKind.Legend, controls: { position: true } },
{ kind: SectionKind.Legend, controls: { position: true, colors: true } },
{ kind: SectionKind.ContextLinks },
];

View File

@@ -160,7 +160,7 @@ function TablePanelRenderer({
className={PanelStyles.panelContainer}
>
{!table || dataSource.length === 0 ? (
<NoData isFetching={isFetching} onRetry={refetch} />
<NoData isFetching={isFetching} onRetry={refetch} panel={panel} />
) : (
<div className={styles.container}>
<Table

View File

@@ -194,7 +194,7 @@ function TimeSeriesPanelRenderer({
className={PanelStyles.panelContainer}
>
{flatSeries.length === 0 && (
<NoData isFetching={isFetching} onRetry={refetch} />
<NoData isFetching={isFetching} onRetry={refetch} panel={panel} />
)}
{flatSeries.length > 0 &&
containerDimensions.width > 0 &&

View File

@@ -1,11 +1,11 @@
import { useState } from 'react';
import type {
DashboardtypesPanelDTO,
DashboardtypesTimePreferenceDTO,
} from 'api/generated/services/sigNoz.schemas';
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
import ContextMenu from 'periscope/components/ContextMenu';
import { getPanelDefinition } from 'pages/DashboardPageV2/DashboardContainer/Panels/registry';
import { panelTimePreferenceLabel } from 'pages/DashboardPageV2/DashboardContainer/hooks/resolvePanelTimeWindow';
import {
getPanelTimePreference,
panelTimePreferenceLabel,
} from 'pages/DashboardPageV2/DashboardContainer/hooks/resolvePanelTimeWindow';
import { usePanelQuery } from 'pages/DashboardPageV2/DashboardContainer/hooks/usePanelQuery';
import type { DashboardSection } from '../../utils';
@@ -27,7 +27,7 @@ export interface PanelActionsConfig {
interface PanelProps {
panel: DashboardtypesPanelDTO;
panelId: string;
/** True once this panel's section enters the viewport — gates the fetch. */
/** True once this panel enters the viewport — gates the fetch (owned by SectionGridItem). */
isVisible?: boolean;
/** Move/delete actions — present only in editable sectioned mode. */
panelActions?: PanelActionsConfig;
@@ -43,15 +43,7 @@ function Panel({
isVisible,
panelActions,
}: PanelProps): JSX.Element {
// A per-panel time preference is surfaced as a header pill. `visualization` is
// common to every plugin-spec variant — localized cast reads it without
// narrowing on kind.
const timePreference = (
panel.spec.plugin.spec as
| { visualization?: { timePreference?: DashboardtypesTimePreferenceDTO } }
| undefined
)?.visualization?.timePreference;
const timeLabel = panelTimePreferenceLabel(timePreference);
const timeLabel = panelTimePreferenceLabel(getPanelTimePreference(panel));
const panelKind = panel.spec.plugin.kind;
const panelDefinition = getPanelDefinition(panelKind);

View File

@@ -89,6 +89,14 @@ function section(
const TWO_TITLED_SECTIONS = [section(0, 'Overview'), section(1, 'Latency')];
// Index 0 is the untitled root (free-flow) section; index 1 is a titled section.
const TITLED_WITH_ROOT = [section(0, undefined), section(1, 'Latency')];
// Untitled root plus two titled sections — exercises the multi-target submenu.
const ROOT_AND_TWO_TITLED = [
section(0, undefined),
section(1, 'A'),
section(2, 'B'),
];
// Just the free-flow root: an ungrouped board with no sections to move between.
const ONLY_ROOT = [section(0, undefined)];
// Minimal panel — only its presence gates "Create Alerts"; the query→URL
// translation it drives is covered by buildCreateAlertUrl's own tests.
@@ -111,7 +119,9 @@ const baseArgs = {
panelId: 'panel-1',
panel: mockPanel,
data: mockData,
panelActions: { currentLayoutIndex: 0, sections: TWO_TITLED_SECTIONS },
// Panel sits in a titled section with an untitled root present, so every
// action — including "Move to section" (→ Dashboard root) — is available.
panelActions: { currentLayoutIndex: 1, sections: TITLED_WITH_ROOT },
};
function itemKeys(result: ReturnType<typeof usePanelActionItems>): unknown[] {
@@ -210,7 +220,7 @@ describe('usePanelActionItems', () => {
]);
});
it('move is disabled when there is no other titled section to move to', () => {
it('hides "Move to section" when the only untitled section is not the root (index 0)', () => {
const { result } = renderHook(() =>
usePanelActionItems({
...baseArgs,
@@ -220,8 +230,8 @@ describe('usePanelActionItems', () => {
},
}),
);
const move = result.current.items.find((i) => 'key' in i && i.key === 'move');
expect(move).toMatchObject({ disabled: true });
// An untitled section only counts as the root at layoutIndex 0.
expect(itemKeys(result.current)).not.toContain('move');
});
it('edit opens the panel editor for this panel', () => {
@@ -233,14 +243,77 @@ describe('usePanelActionItems', () => {
expect(mockOpenEditor).toHaveBeenCalledWith('panel-1');
});
it('move targets call the mutation with from/to layout indexes', () => {
it('"Move to section" offers a single "Dashboard (root)" target', () => {
const { result } = renderHook(() => usePanelActionItems(baseArgs));
const move = result.current.items.find(
(i) => 'key' in i && i.key === 'move',
) as {
children: { key: string; onClick: () => void }[];
};
expect(move.children).toHaveLength(1);
expect(move.children.map((c) => c.key)).toStrictEqual(['move-to-root']);
});
it('the "Dashboard (root)" target moves the panel to the untitled root section', () => {
const { result } = renderHook(() => usePanelActionItems(baseArgs));
const move = result.current.items.find(
(i) => 'key' in i && i.key === 'move',
) as {
children: { onClick: () => void }[];
};
move.children[0].onClick();
expect(mockMovePanel).toHaveBeenCalledWith({
panelId: 'panel-1',
fromLayoutIndex: 1,
toLayoutIndex: 0,
});
});
it('an ungrouped panel (in the root) can move into each titled section', () => {
const { result } = renderHook(() =>
usePanelActionItems({
...baseArgs,
panelActions: { currentLayoutIndex: 0, sections: ROOT_AND_TWO_TITLED },
}),
);
const move = result.current.items.find(
(i) => 'key' in i && i.key === 'move',
) as { children: { key: string; label: string }[] };
expect(move.children.map((c) => c.key)).toStrictEqual(['move-1', 'move-2']);
expect(move.children.map((c) => c.label)).toStrictEqual(['A', 'B']);
});
it('a panel in a titled section can move to the root and the other titled sections', () => {
const { result } = renderHook(() =>
usePanelActionItems({
...baseArgs,
panelActions: { currentLayoutIndex: 1, sections: ROOT_AND_TWO_TITLED },
}),
);
const move = result.current.items.find(
(i) => 'key' in i && i.key === 'move',
) as { children: { key: string; label: string }[] };
// Root leads, then the other titled section — never the current one (A).
expect(move.children.map((c) => c.key)).toStrictEqual([
'move-to-root',
'move-2',
]);
expect(move.children.map((c) => c.label)).toStrictEqual([
'Dashboard (root)',
'B',
]);
});
it('moves between titled sections even when the board has no untitled root', () => {
const { result } = renderHook(() =>
usePanelActionItems({
...baseArgs,
panelActions: { currentLayoutIndex: 0, sections: TWO_TITLED_SECTIONS },
}),
);
const move = result.current.items.find(
(i) => 'key' in i && i.key === 'move',
) as { children: { key: string; onClick: () => void }[] };
expect(move.children.map((c) => c.key)).toStrictEqual(['move-1']);
move.children[0].onClick();
expect(mockMovePanel).toHaveBeenCalledWith({
panelId: 'panel-1',
@@ -249,47 +322,14 @@ describe('usePanelActionItems', () => {
});
});
it('offers "Move out of section" for a panel in a titled section when an untitled root exists', () => {
it('hides "Move to section" when the board has no sections (only the root)', () => {
const { result } = renderHook(() =>
usePanelActionItems({
...baseArgs,
panelActions: { currentLayoutIndex: 1, sections: TITLED_WITH_ROOT },
panelActions: { currentLayoutIndex: 0, sections: ONLY_ROOT },
}),
);
expect(itemKeys(result.current)).toContain('move-to-root');
});
it('"Move out of section" moves the panel to the untitled root section', () => {
const { result } = renderHook(() =>
usePanelActionItems({
...baseArgs,
panelActions: { currentLayoutIndex: 1, sections: TITLED_WITH_ROOT },
}),
);
const moveOut = result.current.items.find(
(i) => 'key' in i && i.key === 'move-to-root',
);
(moveOut as { onClick: () => void }).onClick();
expect(mockMovePanel).toHaveBeenCalledWith({
panelId: 'panel-1',
fromLayoutIndex: 1,
toLayoutIndex: 0,
});
});
it('hides "Move out of section" when the panel already sits in the root section', () => {
const { result } = renderHook(() =>
usePanelActionItems({
...baseArgs,
panelActions: { currentLayoutIndex: 0, sections: TITLED_WITH_ROOT },
}),
);
expect(itemKeys(result.current)).not.toContain('move-to-root');
});
it('hides "Move out of section" when every section is titled (no root)', () => {
const { result } = renderHook(() => usePanelActionItems(baseArgs));
expect(itemKeys(result.current)).not.toContain('move-to-root');
expect(itemKeys(result.current)).not.toContain('move');
});
it('delete defers to a confirmation: the item opens the dialog, confirm runs the mutation', async () => {
@@ -312,7 +352,7 @@ describe('usePanelActionItems', () => {
});
expect(mockDeletePanel).toHaveBeenCalledWith({
panelId: 'panel-1',
layoutIndex: 0,
layoutIndex: 1,
});
expect(result.current.deleteConfirm.open).toBe(false);
});
@@ -325,7 +365,7 @@ describe('usePanelActionItems', () => {
(clone as { onClick: () => void }).onClick();
expect(mockClonePanel).toHaveBeenCalledWith({
panelId: 'panel-1',
layoutIndex: 0,
layoutIndex: 1,
});
});

View File

@@ -5,6 +5,7 @@
padding: 8px 12px;
border-bottom: 1px solid var(--l2-border);
cursor: grab;
min-height: 32px;
}
.headerLeft {

View File

@@ -1,4 +1,4 @@
import { useMemo } from 'react';
import { Fragment, useMemo } from 'react';
import { Info, Loader } from '@signozhq/icons';
import { Typography } from '@signozhq/ui/typography';
import type {
@@ -74,6 +74,14 @@ function PanelHeader({
[warning],
);
/**
* Hide the entire header when there's no title, description, or status to show,
* and the actions menu is suppressed (editor preview).
*/
if (!name && !description && !errorDetail && !warningDetail && hideActions) {
return <Fragment />;
}
return (
<div className={cx(styles.header, 'panel-drag-handle')}>
<div className={styles.headerLeft}>

View File

@@ -1,9 +1,8 @@
@use '../../../../../../styles/scrollbar' as *;
.modal {
:global(.ant-modal-body) {
padding: 0px;
}
.dialog[data-width] {
max-width: 85%;
width: 85%;
}
// Truncate a long panel name so the header stays on one line; the wrapping tooltip

View File

@@ -1,7 +1,15 @@
import {
Dialog,
DialogCloseButton,
DialogContent,
DialogHeader,
DialogTitle,
} from '@signozhq/ui/dialog';
import { TooltipSimple } from '@signozhq/ui/tooltip';
import { Typography } from '@signozhq/ui/typography';
import { Modal } from 'antd';
import { ConfigProvider } from 'antd';
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
import { useRef } from 'react';
import ViewPanelModalContent from './ViewPanelModalContent';
import styles from './ViewPanelModal.module.scss';
@@ -25,27 +33,48 @@ function ViewPanelModal({
}: ViewPanelModalProps): JSX.Element {
const name = panel?.spec.display.name ?? '';
// Render antd popups into the dialog (not document.body) so they stay inside the
// modal's interactive, focus-trapped layer instead of being blocked by Radix.
const contentRef = useRef<HTMLDivElement>(null);
return (
<Modal
<Dialog
open={open}
onCancel={onClose}
footer={null}
centered
width="85%"
destroyOnClose
className={styles.modal}
title={
<TooltipSimple title={name} arrow>
<Typography.Text className={styles.title}>
{name} - (View mode)
</Typography.Text>
</TooltipSimple>
}
onOpenChange={(isOpen): void => {
if (!isOpen) {
onClose();
}
}}
>
{open && panel && panelId && (
<ViewPanelModalContent panel={panel} panelId={panelId} onClose={onClose} />
)}
</Modal>
<DialogContent
ref={contentRef}
position="center"
width="extra-wide"
className={styles.dialog}
>
<DialogHeader>
<DialogTitle>
<TooltipSimple title={name} arrow>
<Typography.Text className={styles.title}>
{name ? `${name} - (View mode)` : 'View mode'}
</Typography.Text>
</TooltipSimple>
</DialogTitle>
</DialogHeader>
<DialogCloseButton />
{open && panel && panelId && (
<ConfigProvider
getPopupContainer={(): HTMLElement => contentRef.current ?? document.body}
>
<ViewPanelModalContent
panel={panel}
panelId={panelId}
onClose={onClose}
/>
</ConfigProvider>
)}
</DialogContent>
</Dialog>
);
}

View File

@@ -3,6 +3,7 @@ import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schem
import { PanelMode } from 'container/DashboardContainer/visualization/panels/types';
import { DashboardCursorSync } from 'lib/uPlotV2/plugins/TooltipPlugin/types';
import ContextMenu from 'periscope/components/ContextMenu';
import ListColumnsEditor from 'pages/DashboardPageV2/DashboardContainer/PanelEditor/ListColumnsEditor/ListColumnsEditor';
import PanelEditorQueryBuilder from 'pages/DashboardPageV2/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder';
import PreviewPane from 'pages/DashboardPageV2/DashboardContainer/PanelEditor/PreviewPane/PreviewPane';
import type { DashboardPreference } from 'pages/DashboardPageV2/DashboardContainer/Panels/types/rendererProps';
@@ -44,6 +45,7 @@ function ViewPanelModalContent({
const {
draft,
setSpec,
panelDefinition,
signal,
queryType,
@@ -54,7 +56,17 @@ function ViewPanelModalContent({
buildSaveSpec,
applyDrilldownQuery,
} = useViewPanelMode({ panel, panelId, time: timeOverride });
const { data, isFetching, error, refetch, cancelQuery, pagination } = query;
const {
data,
isFetching,
isPreviousData,
error,
refetch,
cancelQuery,
pagination,
} = query;
const isListPanel = draft.spec.plugin.kind === 'signoz/ListPanel';
// Grid drill-down, but filter-by-value / breakout refine this view in place. Drills the draft
// so it reflects in-modal edits (and the click's time range follows the per-view window).
@@ -119,6 +131,15 @@ function ViewPanelModalContent({
isLoadingQueries={isFetching}
onStageRunQuery={runQuery}
onCancelQuery={cancelQuery}
footer={
isListPanel ? (
<ListColumnsEditor
spec={draft.spec}
onChangeSpec={setSpec}
signal={signal}
/>
) : undefined
}
/>
</div>
<div className={styles.body}>
@@ -128,6 +149,7 @@ function ViewPanelModalContent({
panelDefinition={panelDefinition}
data={data}
isFetching={isFetching}
isPreviousData={isPreviousData}
error={error}
refetch={refetch}
onDragSelect={onDragSelect}

View File

@@ -35,6 +35,8 @@ interface UseViewPanelModeArgs {
export interface UseViewPanelModeReturn {
/** Local editable copy of the panel — the preview renders this, not the saved panel. */
draft: DashboardtypesPanelDTO;
/** Update the draft's spec in place (e.g. the List columns editor). */
setSpec: (next: DashboardtypesPanelSpecDTO) => void;
/** Resolved renderer for the draft's current kind (registry always resolves a kind). */
panelDefinition: RenderablePanelDefinition;
/**
@@ -159,6 +161,7 @@ export function useViewPanelMode({
return {
draft,
setSpec,
panelDefinition,
signal,
queryType: currentQuery.queryType,

View File

@@ -1,9 +1,12 @@
import { FolderInput, FolderOutput } from '@signozhq/icons';
import { FolderInput } from '@signozhq/icons';
import type { MenuItem } from '@signozhq/ui/dropdown-menu';
import { findRootSection, type DashboardSection } from '../../../utils';
import type { MovePanelArgs } from '../hooks/useMovePanelToSection';
// Matches the root option label in the New Panel picker (SectionPicker).
const ROOT_LABEL = 'Dashboard (root)';
interface MoveItemsArgs {
sections: DashboardSection[];
currentLayoutIndex: number;
@@ -12,9 +15,11 @@ interface MoveItemsArgs {
}
/**
* The "Move to section" submenu plus a direct "Move out of section" to the
* untitled root, shown only when the panel sits in a titled section and a root
* section exists to receive it.
* "Move to section" submenu listing every section the panel can move to the
* dashboard root (untitled top level, labelled "Dashboard (root)") plus every
* titled section, minus the one the panel already sits in. Hidden entirely when
* there is nowhere to move: an ungrouped board with no titled sections, or a
* panel that is alone in the only section.
*/
export function buildMoveItems({
sections,
@@ -22,44 +27,38 @@ export function buildMoveItems({
panelId,
movePanel,
}: MoveItemsArgs): MenuItem[] {
const rootSection = findRootSection(sections);
// Sections are already in layout order, so the root (index 0, when present)
// naturally leads. Untitled non-root layouts are never a move target.
const targets = sections.filter(
(s) => s.title && s.layoutIndex !== currentLayoutIndex,
(section) =>
section.layoutIndex !== currentLayoutIndex &&
(section === rootSection || Boolean(section.title)),
);
const items: MenuItem[] = [
if (targets.length === 0) {
return [];
}
return [
{
key: 'move',
label: 'Move to section',
icon: <FolderInput size={14} />,
...(targets.length === 0
? { disabled: true }
: {
children: targets.map((s) => ({
key: `move-${s.layoutIndex}`,
label: s.title,
onClick: (): void =>
void movePanel({
panelId,
fromLayoutIndex: currentLayoutIndex,
toLayoutIndex: s.layoutIndex,
}),
})),
}),
children: targets.map((section) => {
const isRoot = section === rootSection;
return {
key: isRoot ? 'move-to-root' : `move-${section.layoutIndex}`,
label: isRoot ? ROOT_LABEL : (section.title as string),
onClick: (): void =>
void movePanel({
panelId,
fromLayoutIndex: currentLayoutIndex,
toLayoutIndex: section.layoutIndex,
}),
};
}),
},
];
const rootSection = findRootSection(sections);
if (rootSection && rootSection.layoutIndex !== currentLayoutIndex) {
items.push({
key: 'move-to-root',
label: 'Move out of section',
icon: <FolderOutput size={14} />,
onClick: (): void =>
void movePanel({
panelId,
fromLayoutIndex: currentLayoutIndex,
toLayoutIndex: rootSection.layoutIndex,
}),
});
}
return items;
}

View File

@@ -1,9 +1,7 @@
import { useCallback, useRef, useState } from 'react';
import { useCallback, useState } from 'react';
import { Plus } from '@signozhq/icons';
import { Button } from '@signozhq/ui/button';
import { useIntersectionObserver } from 'hooks/useIntersectionObserver';
import ConfirmDeleteDialog from '../../../components/ConfirmDeleteDialog/ConfirmDeleteDialog';
import DisabledControlTooltip from '../../../components/DisabledControlTooltip/DisabledControlTooltip';
import { DASHBOARD_LOCKED_REASON } from '../../../hooks/useDashboardEditGuard';
@@ -41,12 +39,6 @@ function Section({ section, sections, dragHandle }: SectionProps): JSX.Element {
targetLayoutIndex,
} = useCreatePanel();
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);
// Placeholder signal for lazy panel query-loading (consumed in a later PR):
// true once the section scrolls into (or near) the viewport.
const isVisible = useIntersectionObserver(containerRef, {
rootMargin: '200px',
});
const { open, toggle } = useToggleSectionCollapse({ sectionId: section.id });
@@ -77,17 +69,14 @@ function Section({ section, sections, dragHandle }: SectionProps): JSX.Element {
<SectionGrid
items={section.items}
layoutIndex={section.layoutIndex}
isVisible={isVisible}
sections={sections}
/>
);
if (!section.title) {
// Untitled section — just the grid (no header chrome), but still observed
// for the viewport signal.
// Untitled section — just the grid, no header chrome.
return (
<div
ref={containerRef}
data-testid={`dashboard-section-${section.id}`}
data-section-layout-index={section.layoutIndex}
>
@@ -98,7 +87,6 @@ function Section({ section, sections, dragHandle }: SectionProps): JSX.Element {
return (
<div
ref={containerRef}
className={styles.section}
data-testid={`dashboard-section-${section.id}`}
data-section-layout-index={section.layoutIndex}

View File

@@ -20,3 +20,9 @@
}
}
}
// Lazy-load observer boundary (SectionGridItem); fills the grid cell.
.panelWrapper {
height: 100%;
width: 100%;
}

View File

@@ -2,9 +2,9 @@ import { useMemo } from 'react';
import GridLayout, { WidthProvider, type Layout } from 'react-grid-layout';
import type { DashboardSection } from '../../../utils';
import Panel from '../../Panel/Panel';
import { useDashboardStore } from '../../../store/useDashboardStore';
import { usePersistLayout } from '../hooks/usePersistLayout';
import SectionGridItem from './SectionGridItem';
import styles from './SectionGrid.module.scss';
const ResponsiveGridLayout = WidthProvider(GridLayout);
@@ -12,8 +12,6 @@ const ResponsiveGridLayout = WidthProvider(GridLayout);
interface SectionGridProps {
items: DashboardSection['items'];
layoutIndex: number;
/** Forwarded to panels — true when the parent section is in the viewport. */
isVisible?: boolean;
/** All sections — layout context for the panel menu's move/delete actions. */
sections?: DashboardSection[];
}
@@ -21,7 +19,6 @@ interface SectionGridProps {
function SectionGrid({
items,
layoutIndex,
isVisible,
sections,
}: SectionGridProps): JSX.Element {
const isEditable = useDashboardStore((s) => s.isEditable);
@@ -61,10 +58,9 @@ function SectionGrid({
// panel with no content.
<div key={item.id}>
{item.panel && (
<Panel
<SectionGridItem
panel={item.panel}
panelId={item.id}
isVisible={isVisible}
panelActions={
isEditable
? {

View File

@@ -0,0 +1,47 @@
import { useRef } from 'react';
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
import { useIntersectionObserver } from 'hooks/useIntersectionObserver';
import Panel, { type PanelActionsConfig } from '../../Panel/Panel';
import styles from './SectionGrid.module.scss';
const VIEWPORT_OBSERVER_OPTIONS: IntersectionObserverInit = {
rootMargin: '200px',
};
interface SectionGridItemProps {
panel: DashboardtypesPanelDTO;
panelId: string;
panelActions?: PanelActionsConfig;
}
/**
* Lazy-loads a single panel: watches its own viewport intersection (latched) and
* passes it to the presentational Panel as `isVisible`, so a board of many panels
* only fetches what's on screen.
*/
function SectionGridItem({
panel,
panelId,
panelActions,
}: SectionGridItemProps): JSX.Element {
const containerRef = useRef<HTMLDivElement>(null);
const isVisible = useIntersectionObserver(
containerRef,
VIEWPORT_OBSERVER_OPTIONS,
true,
);
return (
<div ref={containerRef} className={styles.panelWrapper}>
<Panel
panel={panel}
panelId={panelId}
isVisible={isVisible}
panelActions={panelActions}
/>
</div>
);
}
export default SectionGridItem;

View File

@@ -1,4 +1,7 @@
import { DashboardtypesTimePreferenceDTO } from 'api/generated/services/sigNoz.schemas';
import {
DashboardtypesPanelDTO,
DashboardtypesTimePreferenceDTO,
} from 'api/generated/services/sigNoz.schemas';
/** Absolute time window in epoch milliseconds — the V5 request's native unit. */
export interface PanelTimeWindow {
@@ -65,6 +68,28 @@ const TIME_PREFERENCE_LABEL: Partial<
},
};
/** A panel's saved `visualization.timePreference`, or `undefined` when the kind has none. */
export function getPanelTimePreference(
panel: DashboardtypesPanelDTO,
): DashboardtypesTimePreferenceDTO | undefined {
const pluginSpec = panel.spec.plugin.spec;
if (pluginSpec && 'visualization' in pluginSpec) {
return pluginSpec.visualization?.timePreference;
}
return undefined;
}
/** True when the panel is locked to a fixed relative window, so it ignores the dashboard's ambient time. */
export function panelHasFixedTimePreference(
panel: DashboardtypesPanelDTO,
): boolean {
const timePreference = getPanelTimePreference(panel);
return (
timePreference !== undefined &&
timePreference !== DashboardtypesTimePreferenceDTO.global_time
);
}
export interface PanelTimePreferenceLabel {
/** Compact pill label, e.g. `6h`. */
short: string;