mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Reporting: Disable lazy loading for panels (#98065)
This commit is contained in:
@@ -51,6 +51,7 @@ import {
|
|||||||
QueryVariableKind,
|
QueryVariableKind,
|
||||||
TextVariableKind,
|
TextVariableKind,
|
||||||
} from '@grafana/schema/src/schema/dashboard/v2alpha0/dashboard.gen';
|
} from '@grafana/schema/src/schema/dashboard/v2alpha0/dashboard.gen';
|
||||||
|
import { contextSrv } from 'app/core/core';
|
||||||
import {
|
import {
|
||||||
AnnoKeyCreatedBy,
|
AnnoKeyCreatedBy,
|
||||||
AnnoKeyDashboardNotFound,
|
AnnoKeyDashboardNotFound,
|
||||||
@@ -170,7 +171,7 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
|
|||||||
version: parseInt(metadata.resourceVersion, 10),
|
version: parseInt(metadata.resourceVersion, 10),
|
||||||
body: new DefaultGridLayoutManager({
|
body: new DefaultGridLayoutManager({
|
||||||
grid: new SceneGridLayout({
|
grid: new SceneGridLayout({
|
||||||
isLazy: dashboard.preload ? false : true,
|
isLazy: !(dashboard.preload || contextSrv.user.authenticatedBy === 'render'),
|
||||||
children: createSceneGridLayoutForItems(dashboard),
|
children: createSceneGridLayoutForItems(dashboard),
|
||||||
$behaviors: [trackIfEmpty],
|
$behaviors: [trackIfEmpty],
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
RowPanel,
|
RowPanel,
|
||||||
VariableType,
|
VariableType,
|
||||||
} from '@grafana/schema';
|
} from '@grafana/schema';
|
||||||
|
import { contextSrv } from 'app/core/core';
|
||||||
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
||||||
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
||||||
import { createPanelSaveModel } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures';
|
import { createPanelSaveModel } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures';
|
||||||
@@ -168,6 +169,35 @@ describe('transformSaveModelToScene', () => {
|
|||||||
const scene = createDashboardSceneFromDashboardModel(oldModel, dash);
|
const scene = createDashboardSceneFromDashboardModel(oldModel, dash);
|
||||||
expect(scene.state.$variables?.state.variables).toBeDefined();
|
expect(scene.state.$variables?.state.variables).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not return lazy loaded panels when user is image renderer', () => {
|
||||||
|
contextSrv.user.authenticatedBy = 'render';
|
||||||
|
|
||||||
|
const panel1 = createPanelSaveModel({
|
||||||
|
title: 'test1',
|
||||||
|
gridPos: { x: 0, y: 1, w: 12, h: 8 },
|
||||||
|
}) as Panel;
|
||||||
|
|
||||||
|
const panel2 = createPanelSaveModel({
|
||||||
|
title: 'test2',
|
||||||
|
gridPos: { x: 0, y: 10, w: 12, h: 8 },
|
||||||
|
}) as Panel;
|
||||||
|
|
||||||
|
const dashboard = {
|
||||||
|
...defaultDashboard,
|
||||||
|
title: 'Test dashboard',
|
||||||
|
uid: 'test-uid',
|
||||||
|
panels: [panel1, panel2],
|
||||||
|
};
|
||||||
|
|
||||||
|
const oldModel = new DashboardModel(dashboard);
|
||||||
|
|
||||||
|
const scene = createDashboardSceneFromDashboardModel(oldModel, dashboard);
|
||||||
|
const layout = scene.state.body as DefaultGridLayoutManager;
|
||||||
|
const body = layout.state.grid;
|
||||||
|
|
||||||
|
expect(body.state.isLazy).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When creating a new dashboard', () => {
|
describe('When creating a new dashboard', () => {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
UserActionEvent,
|
UserActionEvent,
|
||||||
SceneObjectState,
|
SceneObjectState,
|
||||||
} from '@grafana/scenes';
|
} from '@grafana/scenes';
|
||||||
|
import { contextSrv } from 'app/core/core';
|
||||||
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
||||||
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
||||||
import { DashboardDTO, DashboardDataDTO } from 'app/types';
|
import { DashboardDTO, DashboardDataDTO } from 'app/types';
|
||||||
@@ -256,7 +257,7 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel,
|
|||||||
version: oldModel.version,
|
version: oldModel.version,
|
||||||
body: new DefaultGridLayoutManager({
|
body: new DefaultGridLayoutManager({
|
||||||
grid: new SceneGridLayout({
|
grid: new SceneGridLayout({
|
||||||
isLazy: dto.preload ? false : true,
|
isLazy: !(dto.preload || contextSrv.user.authenticatedBy === 'render'),
|
||||||
children: createSceneObjectsForPanels(oldModel.panels),
|
children: createSceneObjectsForPanels(oldModel.panels),
|
||||||
$behaviors: [trackIfEmpty],
|
$behaviors: [trackIfEmpty],
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user