Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(dashboards-v2): new panel reads clean on open, not dirty (#12297)

Abhi kumar3e35d1ef6483
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/__tests__/PanelEditorContainer.test.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/__tests__/PanelEditorContainer.test.tsx
index 12603f278f..1d5243109c 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/__tests__/PanelEditorContainer.test.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/__tests__/PanelEditorContainer.test.tsx
@@ -174,11 +174,13 @@ const baseProps = {
function setup(
panel: DashboardtypesPanelDTO,
overrides?: Partial<React.ComponentProps<typeof PanelEditorContainer>>,
- draftOverrides?: { isSpecDirty?: boolean },
+ draftOverrides?: { isSpecDirty?: boolean; draft?: DashboardtypesPanelDTO },
): void {
+ // The live draft can diverge from the seed `panel`; default to the seed.
+ const draftPanel = draftOverrides?.draft ?? panel;
mockUseDraft.mockReturnValue({
- draft: panel,
- spec: panel.spec,
+ draft: draftPanel,
+ spec: draftPanel.spec,
setSpec: mockSetSpec,
isSpecDirty: draftOverrides?.isSpecDirty ?? false,
});
@@ -271,6 +273,23 @@ describe('PanelEditorContainer composition', () => {
);
});
+ it('keeps a query-less new panel clean after the staged-query sync seeds its draft (regression)', () => {
+ // Staged-query sync populated the draft with the seed; dirty must read the seed
+ // `panel` (query-less), not the draft, else an untouched new panel reads dirty.
+ const committedDraft = makePanel('signoz/TimeSeriesPanel', [
+ { spec: { plugin: { kind: 'signoz/CompositeQuery', spec: {} } } },
+ ]);
+ setup(
+ makePanel('signoz/TimeSeriesPanel'),
+ { isNew: true },
+ { draft: committedDraft },
+ );
+
+ expect(mockHeaderProps).toHaveBeenCalledWith(
+ expect.objectContaining({ isDirty: false }),
+ );
+ });
+
it('marks a new panel that already has a query saveable (e.g. list auto-runs one)', () => {
const seededQuery = {
spec: { plugin: { kind: 'signoz/BuilderQuery', spec: { signal: 'logs' } } },
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/hooks/__tests__/usePanelEditorQuerySync.integration.test.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/hooks/__tests__/usePanelEditorQuerySync.integration.test.tsx
index 9ea84b443b..bbe357cfca 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/hooks/__tests__/usePanelEditorQuerySync.integration.test.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/hooks/__tests__/usePanelEditorQuerySync.integration.test.tsx
@@ -2,6 +2,7 @@ import { renderHook, waitFor } from '@testing-library/react';
import type {
DashboardtypesPanelDTO,
DashboardtypesQueryDTO,
+ TelemetrytypesSignalDTO,
} from 'api/generated/services/sigNoz.schemas';
import { QueryParams } from 'constants/query';
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
@@ -89,6 +90,33 @@ describe('usePanelEditorQuerySync (real query builder)', () => {
expect(result.current.isQueryDirty).toBe(false);
});
+ it.each([
+ [DataSource.METRICS, PANEL_TYPES.TIME_SERIES],
+ [DataSource.LOGS, PANEL_TYPES.TIME_SERIES],
+ [DataSource.TRACES, PANEL_TYPES.TIME_SERIES],
+ [DataSource.LOGS, PANEL_TYPES.LIST],
+ ])(
+ 'a NEW %s panel (%s, no savedQueries) is NOT query-dirty on mount',
+ async (ds, pt) => {
+ const { result } = renderHook(
+ () =>
+ usePanelEditorQuerySync({
+ draft: makePanel([]),
+ panelType: pt,
+ setSpec: jest.fn(),
+ refetch: jest.fn(),
+ alwaysSerializeQuery: true,
+ signal: ds as unknown as TelemetrytypesSignalDTO,
+ // savedQueries omitted — new panel.
+ }),
+ { wrapper: AllTheProviders },
+ );
+
+ await waitFor(() => expect(result.current.isQueryDirty).toBe(false));
+ expect(result.current.isQueryDirty).toBe(false);
+ },
+ );
+
it('an untouched panel with a minimal/older stored query is NOT dirty (drift fix)', async () => {
// An older saved query carries only a few fields; the builder re-emits many more
// (source, stepInterval, filter, spaceAggregation, …). Comparing raw would read
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/index.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/index.tsx
index cf4763329b..ea866a002c 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/index.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/index.tsx
@@ -159,11 +159,12 @@ function PanelEditorContainer({
return section?.controls;
}, [panelDefinition]);
- // A new panel is savable once it has a query to run — List auto-seeds one; other
- // kinds open query-less, so there's nothing to save until the user builds one.
+ // New panels are savable once seeded with a query (List auto-seeds one). Read the
+ // seed `panel`, not the live `draft` — the staged-query sync commits the seed into
+ // the draft on open, which would falsely dirty an untouched query-less new panel.
const isDirty = useMemo(
- () => isSpecDirty || isQueryDirty || (isNew && draft.spec.queries.length > 0),
- [isSpecDirty, isQueryDirty, isNew, draft.spec.queries.length],
+ () => isSpecDirty || isQueryDirty || (isNew && panel.spec.queries.length > 0),
+ [isSpecDirty, isQueryDirty, isNew, panel.spec.queries.length],
);
const isListPanel = panelKind === 'signoz/ListPanel';