mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
Dashboards: Filter out expressions when going to Explore (#64654)
* Filter out expressions when going from dashboard to explore * Move expression UID constant to types
This commit is contained in:
parent
caf98101e7
commit
c363a81806
@ -197,7 +197,10 @@ describe('getExploreUrl', () => {
|
||||
const args = {
|
||||
panel: {
|
||||
getSavedId: () => 1,
|
||||
targets: [{ refId: 'A', expr: 'query1', legendFormat: 'legendFormat1' }],
|
||||
targets: [
|
||||
{ refId: 'A', expr: 'query1', legendFormat: 'legendFormat1' },
|
||||
{ refId: 'B', expr: 'query2', datasource: { type: '__expr__', uid: '__expr__' } },
|
||||
],
|
||||
},
|
||||
datasourceSrv: {
|
||||
get() {
|
||||
@ -215,6 +218,9 @@ describe('getExploreUrl', () => {
|
||||
it('should omit legendFormat in explore url', () => {
|
||||
expect(getExploreUrl(args).then((data) => expect(data).not.toMatch(/legendFormat1/g)));
|
||||
});
|
||||
it('should omit expression target in explore url', () => {
|
||||
expect(getExploreUrl(args).then((data) => expect(data).not.toMatch(/__expr__/g)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateHistory()', () => {
|
||||
|
@ -30,6 +30,7 @@ import { RefreshPicker } from '@grafana/ui';
|
||||
import store from 'app/core/store';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { PanelModel } from 'app/features/dashboard/state';
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/types';
|
||||
import { ExploreId, QueryOptions, QueryTransaction } from 'app/types/explore';
|
||||
|
||||
import { config } from '../config';
|
||||
@ -67,8 +68,12 @@ export async function getExploreUrl(args: GetExploreUrlArguments): Promise<strin
|
||||
|
||||
/** In Explore, we don't have legend formatter and we don't want to keep
|
||||
* legend formatting as we can't change it
|
||||
*
|
||||
* We also don't have expressions, so filter those out
|
||||
*/
|
||||
let exploreTargets: DataQuery[] = panel.targets.map((t) => omit(t, 'legendFormat'));
|
||||
let exploreTargets: DataQuery[] = panel.targets
|
||||
.map((t) => omit(t, 'legendFormat'))
|
||||
.filter((t) => t.datasource?.uid !== ExpressionDatasourceUID);
|
||||
let url: string | undefined;
|
||||
// if the mixed datasource is not enabled for explore, choose only one datasource
|
||||
if (
|
||||
|
@ -1,10 +1,7 @@
|
||||
import { getDefaultRelativeTimeRange, RelativeTimeRange } from '@grafana/data';
|
||||
import { getDataSourceSrv } from '@grafana/runtime/src/services/__mocks__/dataSourceSrv';
|
||||
import {
|
||||
dataSource as expressionDatasource,
|
||||
ExpressionDatasourceUID,
|
||||
} from 'app/features/expressions/ExpressionDatasource';
|
||||
import { ExpressionQuery, ExpressionQueryType } from 'app/features/expressions/types';
|
||||
import { dataSource as expressionDatasource } from 'app/features/expressions/ExpressionDatasource';
|
||||
import { ExpressionQuery, ExpressionQueryType, ExpressionDatasourceUID } from 'app/features/expressions/types';
|
||||
import { defaultCondition } from 'app/features/expressions/utils/expressionTypes';
|
||||
import { AlertQuery } from 'app/types/unified-alerting-dto';
|
||||
|
||||
|
@ -3,12 +3,9 @@ import { createAction, createReducer } from '@reduxjs/toolkit';
|
||||
import { DataQuery, getDefaultRelativeTimeRange, RelativeTimeRange } from '@grafana/data';
|
||||
import { getNextRefIdChar } from 'app/core/utils/query';
|
||||
import { findDataSourceFromExpressionRecursive } from 'app/features/alerting/utils/dataSourceFromExpression';
|
||||
import {
|
||||
dataSource as expressionDatasource,
|
||||
ExpressionDatasourceUID,
|
||||
} from 'app/features/expressions/ExpressionDatasource';
|
||||
import { dataSource as expressionDatasource } from 'app/features/expressions/ExpressionDatasource';
|
||||
import { isExpressionQuery } from 'app/features/expressions/guards';
|
||||
import { ExpressionQuery, ExpressionQueryType } from 'app/features/expressions/types';
|
||||
import { ExpressionQuery, ExpressionQueryType, ExpressionDatasourceUID } from 'app/features/expressions/types';
|
||||
import { defaultCondition } from 'app/features/expressions/utils/expressionTypes';
|
||||
import { AlertQuery } from 'app/types/unified-alerting-dto';
|
||||
|
||||
|
@ -4,7 +4,7 @@ import React, { useMemo } from 'react';
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { getDataSourceSrv } from '@grafana/runtime';
|
||||
import { useStyles2 } from '@grafana/ui';
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/ExpressionDatasource';
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/types';
|
||||
import { CombinedRule, RulesSource } from 'app/types/unified-alerting';
|
||||
|
||||
import { isCloudRulesSource } from '../../utils/datasource';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { DataSourceJsonData, PluginMeta } from '@grafana/data';
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/ExpressionDatasource';
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/types';
|
||||
import { CombinedRule } from 'app/types/unified-alerting';
|
||||
import { GrafanaAlertStateDecision } from 'app/types/unified-alerting-dto';
|
||||
|
||||
|
@ -12,8 +12,7 @@ import { getDataSourceSrv } from '@grafana/runtime';
|
||||
import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend';
|
||||
import { getNextRefIdChar } from 'app/core/utils/query';
|
||||
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/ExpressionDatasource';
|
||||
import { ExpressionQuery, ExpressionQueryType } from 'app/features/expressions/types';
|
||||
import { ExpressionQuery, ExpressionQueryType, ExpressionDatasourceUID } from 'app/features/expressions/types';
|
||||
import { PromQuery } from 'app/plugins/datasource/prometheus/types';
|
||||
import { RuleWithLocation } from 'app/types/unified-alerting';
|
||||
import {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/ExpressionDatasource';
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/types';
|
||||
import { AlertQuery } from 'app/types/unified-alerting-dto';
|
||||
|
||||
export const hasCyclicalReferences = (queries: AlertQuery[]) => {
|
||||
|
@ -12,7 +12,7 @@ import { DataSourceWithBackend, getDataSourceSrv, getTemplateSrv } from '@grafan
|
||||
import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend';
|
||||
|
||||
import { ExpressionQueryEditor } from './ExpressionQueryEditor';
|
||||
import { ExpressionQuery, ExpressionQueryType } from './types';
|
||||
import { ExpressionDatasourceUID, ExpressionQuery, ExpressionQueryType } from './types';
|
||||
|
||||
/**
|
||||
* This is a singleton instance that just pretends to be a DataSource
|
||||
@ -60,11 +60,6 @@ export class ExpressionDatasourceApi extends DataSourceWithBackend<ExpressionQue
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MATCHES a constant in DataSourceWithBackend
|
||||
*/
|
||||
export const ExpressionDatasourceUID = '__expr__';
|
||||
|
||||
export const instanceSettings: DataSourceInstanceSettings = {
|
||||
id: -100,
|
||||
uid: ExpressionDatasourceUID,
|
||||
|
@ -2,6 +2,11 @@ import { DataQuery, ReducerID, SelectableValue } from '@grafana/data';
|
||||
|
||||
import { EvalFunction } from '../alerting/state/alertDef';
|
||||
|
||||
/**
|
||||
* MATCHES a constant in DataSourceWithBackend
|
||||
*/
|
||||
export const ExpressionDatasourceUID = '__expr__';
|
||||
|
||||
export enum ExpressionQueryType {
|
||||
math = 'math',
|
||||
reduce = 'reduce',
|
||||
|
@ -20,9 +20,9 @@ import appEvents from 'app/core/app_events';
|
||||
import config from 'app/core/config';
|
||||
import {
|
||||
dataSource as expressionDatasource,
|
||||
ExpressionDatasourceUID,
|
||||
instanceSettings as expressionInstanceSettings,
|
||||
} from 'app/features/expressions/ExpressionDatasource';
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/types';
|
||||
|
||||
import { importDataSourcePlugin } from './plugin_loader';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user