diff --git a/.betterer.results b/.betterer.results index 7e131e53451..3171ea37f0c 100644 --- a/.betterer.results +++ b/.betterer.results @@ -3843,6 +3843,9 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings. Wrap text with ", "0"], [0, 0, 0, "No untranslated strings. Wrap text with ", "1"] ], + "public/app/features/migrate-to-cloud/onprem/useNotifyOnSuccess.tsx:5381": [ + [0, 0, 0, "Do not use any type assertions.", "0"] + ], "public/app/features/notifications/StoredNotifications.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"] ], diff --git a/public/app/features/dashboard-scene/inspect/InspectJsonTab.test.tsx b/public/app/features/dashboard-scene/inspect/InspectJsonTab.test.tsx index b49a61cd1b8..5605a573146 100644 --- a/public/app/features/dashboard-scene/inspect/InspectJsonTab.test.tsx +++ b/public/app/features/dashboard-scene/inspect/InspectJsonTab.test.tsx @@ -71,6 +71,24 @@ jest.mock('@grafana/runtime', () => ({ getInstanceSettings: jest.fn().mockResolvedValue({ uid: 'ds1' }), }; }, + config: { + ...jest.requireActual('@grafana/runtime').config, + bootData: { + ...jest.requireActual('@grafana/runtime').config.bootData, + settings: { + ...jest.requireActual('@grafana/runtime').config.bootData.settings, + defaultDatasource: 'ds1', + datasources: { + ds1: { + name: 'ds-uid', + meta: { + id: 'grafana', + }, + }, + }, + }, + }, + }, })); const runRequestMock = jest.fn().mockReturnValue( @@ -170,6 +188,16 @@ describe('InspectJsonTab', () => { expect(tab.state.onClose).toHaveBeenCalled(); }); + + it('Can show panel json for V2 dashboard specification', async () => { + const { tab } = await buildTestSceneWithV2Spec(); + + const obj = JSON.parse(tab.state.jsonText); + expect(obj.kind).toEqual('Panel'); + expect(obj.spec.id).toEqual(12); + expect(obj.spec.data.kind).toEqual('QueryGroup'); + expect(tab.isEditable()).toBe(false); + }); }); function buildTestPanel() { @@ -275,3 +303,29 @@ async function buildTestSceneWithLibraryPanel() { return { scene, tab, panel }; } + +async function buildTestSceneWithV2Spec() { + const panel = buildTestPanel(); + const scene = new DashboardScene( + { + title: 'hello', + uid: 'dash-1', + meta: { + canEdit: true, + }, + body: DefaultGridLayoutManager.fromVizPanels([panel]), + }, + 'v2' + ); + + activateFullSceneTree(scene); + + await new Promise((r) => setTimeout(r, 1)); + + const tab = new InspectJsonTab({ + panelRef: panel.getRef(), + onClose: jest.fn(), + }); + + return { scene, tab, panel }; +} diff --git a/public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx b/public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx index 25a5f754738..31d5fe17415 100644 --- a/public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx +++ b/public/app/features/dashboard-scene/inspect/InspectJsonTab.tsx @@ -18,6 +18,7 @@ import { import { LibraryPanel } from '@grafana/schema/'; import { Button, CodeEditor, Field, Select, useStyles2 } from '@grafana/ui'; import { t, Trans } from 'app/core/internationalization'; +import { isDashboardV2Spec } from 'app/features/dashboard/api/utils'; import { getPanelDataFrames } from 'app/features/dashboard/components/HelpWizard/utils'; import { PanelModel } from 'app/features/dashboard/state/PanelModel'; import { getPanelInspectorStyles2 } from 'app/features/inspector/styles'; @@ -28,6 +29,7 @@ import { reportPanelInspectInteraction } from 'app/features/search/page/reportin import { DashboardGridItem } from '../scene/layout-default/DashboardGridItem'; import { buildGridItemForPanel } from '../serialization/transformSaveModelToScene'; import { gridItemToPanel, vizPanelToPanel } from '../serialization/transformSceneToSaveModel'; +import { vizPanelToSchemaV2 } from '../serialization/transformSceneToSaveModelSchemaV2'; import { getDashboardSceneFor, getLibraryPanelBehavior, @@ -150,6 +152,11 @@ export class InspectJsonTab extends SceneObjectBase { return false; } + // V2 dashboard panels are not editable from the inspect + if (isDashboardV2Spec(getDashboardSceneFor(panel).getSaveModel())) { + return false; + } + // Only support normal grid items for now and not repeated items if (panel.parent instanceof DashboardGridItem && panel.parent.isRepeated()) { return false; @@ -218,8 +225,13 @@ function getJsonText(show: ShowContent, panel: VizPanel): string { break; } - if (gridItem instanceof DashboardGridItem) { - objToStringify = gridItemToPanel(gridItem); + if (isDashboardV2Spec(getDashboardSceneFor(panel).getSaveModel())) { + objToStringify = vizPanelToSchemaV2(panel); + break; + } else { + if (gridItem instanceof DashboardGridItem) { + objToStringify = gridItemToPanel(gridItem); + } } break;