mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScenes: Fix missing query options in library panels (#94808)
Fix missing query options in library panels
This commit is contained in:
parent
388023a172
commit
d608668335
@ -13,6 +13,7 @@ import { activateFullSceneTree } from '../utils/test-utils';
|
||||
import { DashboardGridItem } from './DashboardGridItem';
|
||||
import { DashboardScene } from './DashboardScene';
|
||||
import { LibraryPanelBehavior } from './LibraryPanelBehavior';
|
||||
import { PanelTimeRange } from './PanelTimeRange';
|
||||
import { DefaultGridLayoutManager } from './layout-default/DefaultGridLayoutManager';
|
||||
|
||||
setPluginImportUtils({
|
||||
@ -81,6 +82,31 @@ describe('LibraryPanelBehavior', () => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set panel timeRange if panel has query options set', async () => {
|
||||
const { gridItem } = await buildTestSceneWithLibraryPanel();
|
||||
|
||||
const behavior = gridItem.state.body.state.$behaviors![0] as LibraryPanelBehavior;
|
||||
expect(behavior).toBeDefined();
|
||||
expect(gridItem.state.body.state.$timeRange).toBeUndefined();
|
||||
|
||||
const panel = vizPanelToPanel(gridItem.state.body.clone({ $behaviors: undefined }));
|
||||
panel.timeFrom = '2h';
|
||||
panel.timeShift = '3h';
|
||||
|
||||
const libraryPanelState = {
|
||||
name: 'LibraryPanel B',
|
||||
title: 'LibraryPanel B title',
|
||||
uid: '222',
|
||||
type: 'table',
|
||||
version: 2,
|
||||
model: panel,
|
||||
};
|
||||
|
||||
behavior.setPanelFromLibPanel(libraryPanelState);
|
||||
|
||||
expect(gridItem.state.body.state.$timeRange).toBeInstanceOf(PanelTimeRange);
|
||||
});
|
||||
|
||||
it('should not update panel if version is the same', async () => {
|
||||
const { gridItem } = await buildTestSceneWithLibraryPanel();
|
||||
|
||||
|
@ -9,6 +9,7 @@ import { getLibraryPanel } from 'app/features/library-panels/state/api';
|
||||
import { createPanelDataProvider } from '../utils/createPanelDataProvider';
|
||||
|
||||
import { DashboardGridItem } from './DashboardGridItem';
|
||||
import { PanelTimeRange } from './PanelTimeRange';
|
||||
|
||||
export interface LibraryPanelBehaviorState extends SceneObjectState {
|
||||
// Library panels use title from dashboard JSON's panel model, not from library panel definition, hence we pass it.
|
||||
@ -58,6 +59,14 @@ export class LibraryPanelBehavior extends SceneObjectBase<LibraryPanelBehaviorSt
|
||||
$data: createPanelDataProvider(libPanelModel),
|
||||
};
|
||||
|
||||
if (libPanelModel.timeFrom || libPanelModel.timeShift) {
|
||||
vizPanelState.$timeRange = new PanelTimeRange({
|
||||
timeFrom: libPanelModel.timeFrom,
|
||||
timeShift: libPanelModel.timeShift,
|
||||
hideTimeOverride: libPanelModel.hideTimeOverride,
|
||||
});
|
||||
}
|
||||
|
||||
vizPanel.setState(vizPanelState);
|
||||
vizPanel.changePluginType(libPanelModel.type, vizPanelState.options, vizPanelState.fieldConfig);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user