Panel JSON inspect for schema v2 (#103191)
This commit is contained in:
@@ -3843,6 +3843,9 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "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 <Trans /> or use t()", "0"]
|
||||
],
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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<InspectJsonTabState> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user