Skip to content

Commit

Permalink
Dashboard scenes: Fix min interval not saving (#86962)
Browse files Browse the repository at this point in the history
* Fix min interval not saving

* Add tests

* Fix test

(cherry picked from commit fdc1023)
  • Loading branch information
oscarkilhed authored and grafana-delivery-bot[bot] committed Apr 29, 2024
1 parent 452be5b commit 49b6825
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Expand Up @@ -417,6 +417,20 @@ describe('transformSaveModelToScene', () => {
expect(vizPanel.state.hoverHeader).toEqual(true);
});

it('should initalize the VizPanel with min interval set', () => {
const panel = {
title: '',
type: 'test-plugin',
gridPos: { x: 0, y: 0, w: 12, h: 8 },
interval: '20m',
};

const { vizPanel } = buildGridItemForTest(panel);

const queryRunner = getQueryRunnerFor(vizPanel);
expect(queryRunner?.state.minInterval).toBe('20m');
});

it('should set PanelTimeRange when timeFrom or timeShift is present', () => {
const panel = {
type: 'test-plugin',
Expand Down
Expand Up @@ -259,6 +259,13 @@ describe('transformSceneToSaveModel', () => {
expect(saveModel.transparent).toBe(true);
});

it('interval', () => {
const gridItem = buildGridItemFromPanelSchema({ interval: '20m' });
const saveModel = gridItemToPanel(gridItem);

expect(saveModel.interval).toBe('20m');
});

it('With angular options', () => {
const gridItem = buildGridItemFromPanelSchema({});
const vizPanel = gridItem.state.body as VizPanel;
Expand Down
Expand Up @@ -281,7 +281,7 @@ function vizPanelDataToPanel(

const panel: Pick<
Panel,
'datasource' | 'targets' | 'maxDataPoints' | 'transformations' | 'cacheTimeout' | 'queryCachingTTL'
'datasource' | 'targets' | 'maxDataPoints' | 'transformations' | 'cacheTimeout' | 'queryCachingTTL' | 'interval'
> = {};
const queryRunner = getQueryRunnerFor(vizPanel);

Expand All @@ -297,6 +297,9 @@ function vizPanelDataToPanel(
if (queryRunner.state.queryCachingTTL) {
panel.queryCachingTTL = queryRunner.state.queryCachingTTL;
}
if (queryRunner.state.minInterval) {
panel.interval = queryRunner.state.minInterval;
}
}

if (dataProvider instanceof SceneDataTransformer) {
Expand Down
Expand Up @@ -24,6 +24,7 @@ export function createPanelDataProvider(panel: PanelModel): SceneDataProvider |
maxDataPointsFromWidth: true,
cacheTimeout: panel.cacheTimeout,
queryCachingTTL: panel.queryCachingTTL,
minInterval: panel.interval ?? undefined,
dataLayerFilter: {
panelId: panel.id,
},
Expand Down

0 comments on commit 49b6825

Please sign in to comment.