Dashboard: Fix cache timeout persistence (#42204)

* user essentials mob! 🔱

* user essentials mob! 🔱

* user essentials mob! 🔱

* WIP: Mob session work 🚧🔱

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
Co-authored-by: joshhunt <josh@trtr.co>
Co-authored-by: kay delaney <kay@grafana.com>
This commit is contained in:
Hugo Häggmark 2021-11-24 14:24:33 +01:00 committed by GitHub
parent b3e417f768
commit 67a1052334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 4 deletions

View File

@ -487,7 +487,7 @@ export interface DataQueryRequest<TQuery extends DataQuery = DataQuery> {
timezone: string;
app: CoreApp | string;
cacheTimeout?: string;
cacheTimeout?: string | null;
rangeRaw?: RawTimeRange;
timeInfo?: string; // The query time description (blue text in the upper right)
panelId?: number;

View File

@ -4,6 +4,7 @@ import { PanelModel } from '../../state';
import { getLocationSrv } from '@grafana/runtime';
import { QueryGroupDataSource, QueryGroupOptions } from 'app/types';
import { DataQuery } from '@grafana/data';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
interface Props {
/** Current panel */
@ -27,7 +28,10 @@ export class PanelEditorQueries extends PureComponent<Props> {
default: true,
};
const datasourceSettings = getDatasourceSrv().getInstanceSettings(dataSource.uid);
return {
cacheTimeout: datasourceSettings?.meta.queryOptions?.cacheTimeout ? panel.cacheTimeout : undefined,
dataSource,
queries: panel.targets,
maxDataPoints: panel.maxDataPoints,

View File

@ -3,7 +3,7 @@ import { Provider } from 'react-redux';
import { render, screen } from '@testing-library/react';
import { Props, UnthemedDashboardPage } from './DashboardPage';
import { Router } from 'react-router-dom';
import { locationService } from '@grafana/runtime';
import { locationService, setDataSourceSrv } from '@grafana/runtime';
import { DashboardModel } from '../state';
import { configureStore } from '../../../store/configureStore';
import { mockToolkitActionCreator } from 'test/core/redux/mocks';
@ -208,6 +208,12 @@ describe('DashboardPage', () => {
});
dashboardPageScenario('When going into edit mode', (ctx) => {
setDataSourceSrv({
get: jest.fn().mockResolvedValue({}),
getInstanceSettings: jest.fn().mockReturnValue({ meta: {} }),
getList: jest.fn(),
});
ctx.setup(() => {
ctx.mount({
dashboard: getTestDashboard(),

View File

@ -171,7 +171,7 @@ export class PanelModel implements DataConfigSource, IPanelModel {
isInView = false;
configRev = 0; // increments when configs change
hasRefreshed?: boolean;
cacheTimeout?: any;
cacheTimeout?: string | null;
cachedPluginOptions: Record<string, PanelOptionsCache> = {};
legend?: { show: boolean; sort?: string; sortDesc?: boolean };
plugin?: PanelPlugin;
@ -449,6 +449,7 @@ export class PanelModel implements DataConfigSource, IPanelModel {
uid: dataSource.uid,
type: dataSource.type,
};
this.cacheTimeout = options.cacheTimeout;
this.timeFrom = options.timeRange?.from;
this.timeShift = options.timeRange?.shift;
this.hideTimeOverride = options.timeRange?.hide;

View File

@ -51,7 +51,7 @@ export interface QueryRunnerOptions<
maxDataPoints: number;
minInterval: string | undefined | null;
scopedVars?: ScopedVars;
cacheTimeout?: string;
cacheTimeout?: string | null;
transformations?: DataTransformerConfig[];
}