Explore: Fixes issue with adhoc filters when coming from dashboards (#78339)

This commit is contained in:
Torkel Ödegaard
2023-11-20 20:22:01 +01:00
committed by GitHub
parent 2aeb96f422
commit d03b291eed
5 changed files with 18 additions and 5 deletions

View File

@@ -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<string | undefined> {
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<strin
return {
// interpolate the query using its datasource `interpolateVariablesInQueries` method if defined, othewise return the query as-is.
...(queryDs.interpolateVariablesInQueries?.([q], scopedVars ?? {})[0] || q),
...(queryDs.interpolateVariablesInQueries?.([q], scopedVars ?? {}, adhocFilters)[0] || q),
// But always set the datasource as it's required in Explore.
// NOTE: if for some reason the query has the "mixed" datasource, we omit the property;
// Upon initialization, Explore use its own logic to determine the datasource.