diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 07bb33f6cf9..9a77f8ca438 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -3,6 +3,7 @@ import { Unsubscribable } from 'rxjs'; import { v4 as uuidv4 } from 'uuid'; import { + AdHocVariableFilter, CoreApp, DataQuery, DataQueryRequest, @@ -49,6 +50,7 @@ export interface GetExploreUrlArguments { dsRef: DataSourceRef | null | undefined; timeRange: TimeRange; scopedVars: ScopedVars | undefined; + adhocFilters?: AdHocVariableFilter[]; } export function generateExploreId() { @@ -59,7 +61,7 @@ export function generateExploreId() { * Returns an Explore-URL that contains a panel's queries and the dashboard time range. */ export async function getExploreUrl(args: GetExploreUrlArguments): Promise { - const { queries, dsRef, timeRange, scopedVars } = args; + const { queries, dsRef, timeRange, scopedVars, adhocFilters } = args; const interpolatedQueries = ( await Promise.allSettled( queries @@ -72,7 +74,7 @@ export async function getExploreUrl(args: GetExploreUrlArguments): Promise ({ + ...jest.requireActual('@grafana/runtime'), + getDataSourceSrv: () => ({ + getInstanceSettings: jest.fn().mockReturnValue({}), + }), +})); + const getNavigateToExploreContext = async (openInNewWindow?: (url: string) => void) => { const url = '/explore'; const panel: Partial = { @@ -53,6 +60,7 @@ describe('navigateToExplore', () => { queries: panel.targets, timeRange, dsRef: panel.datasource, + adhocFilters: [], }); }); }); @@ -73,6 +81,7 @@ describe('navigateToExplore', () => { queries: panel.targets, timeRange, dsRef: panel.datasource, + adhocFilters: [], }); }); diff --git a/public/app/features/explore/state/main.ts b/public/app/features/explore/state/main.ts index fe582cf53ed..64f63323293 100644 --- a/public/app/features/explore/state/main.ts +++ b/public/app/features/explore/state/main.ts @@ -5,6 +5,7 @@ import { SplitOpenOptions, TimeRange, EventBusSrv } from '@grafana/data'; import { locationService } from '@grafana/runtime'; import { generateExploreId, GetExploreUrlArguments } from 'app/core/utils/explore'; import { PanelModel } from 'app/features/dashboard/state'; +import { getTemplateSrv } from 'app/features/templating/template_srv'; import { CorrelationEditorDetailsUpdate, ExploreItemState, ExploreState } from 'app/types/explore'; import { RichHistoryResults } from '../../../core/history/RichHistoryStorage'; @@ -131,6 +132,7 @@ export const navigateToExplore = ( dsRef: panel.datasource, scopedVars: panel.scopedVars, timeRange, + adhocFilters: getTemplateSrv().getAdhocFilters(panel.datasource?.uid ?? '', true), }); if (openInNewWindow && path) { diff --git a/public/app/features/query/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts index 8ba3e9c91f6..6f7d85c7db4 100644 --- a/public/app/features/query/state/PanelQueryRunner.ts +++ b/public/app/features/query/state/PanelQueryRunner.ts @@ -303,7 +303,7 @@ export class PanelQueryRunner { request.interval = norm.interval; request.intervalMs = norm.intervalMs; - request.filters = this.templateSrv.getAdhocFilters(ds.name); + request.filters = this.templateSrv.getAdhocFilters(ds.name, true); this.lastRequest = request; diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index 4722938134d..a255e9384ae 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -123,7 +123,7 @@ export class TemplateSrv implements BaseTemplateSrv { * Use filters property on the request (DataQueryRequest) or if this is called from * interpolateVariablesInQueries or applyTemplateVariables it is passed as a new argument **/ - getAdhocFilters(datasourceName: string): AdHocVariableFilter[] { + getAdhocFilters(datasourceName: string, skipDeprecationWarning?: boolean): AdHocVariableFilter[] { let filters: any = []; let ds = getDataSourceSrv().getInstanceSettings(datasourceName); @@ -131,7 +131,7 @@ export class TemplateSrv implements BaseTemplateSrv { return []; } - if (!this._adhocFiltersDeprecationWarningLogged.get(ds.type)) { + if (!skipDeprecationWarning && !this._adhocFiltersDeprecationWarningLogged.get(ds.type)) { if (process.env.NODE_ENV !== 'test') { deprecationWarning( `DataSource ${ds.type}`,