From 6c7a45272674e7971e410e9bbd84d404d0df3c41 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Tue, 30 Jun 2020 16:14:27 +0200 Subject: [PATCH] Explore: Remove legend formatting when switching from panel to Explore (#25848) * Remove legend formatting when switching from panel to explore * Add test coverage --- public/app/core/utils/explore.test.ts | 28 +++++++++++++++++++++++++++ public/app/core/utils/explore.ts | 6 +++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/public/app/core/utils/explore.test.ts b/public/app/core/utils/explore.test.ts index 97f6a59b22d..6a82c1e9e70 100644 --- a/public/app/core/utils/explore.test.ts +++ b/public/app/core/utils/explore.test.ts @@ -11,6 +11,8 @@ import { sortLogsResult, SortOrder, updateHistory, + getExploreUrl, + GetExploreUrlArguments, } from './explore'; import store from 'app/core/store'; import { @@ -174,6 +176,32 @@ describe('state functions', () => { }); }); +describe('getExploreUrl', () => { + const args = ({ + panel: { + getSavedId: () => 1, + }, + panelTargets: [{ refId: 'A', expr: 'query1', legendFormat: 'legendFormat1' }], + panelDatasource: { + name: 'testDataSource', + meta: { + id: '1', + }, + }, + datasourceSrv: { + get: jest.fn(), + getDataSourceById: jest.fn(), + }, + timeSrv: { + timeRangeForUrl: () => '1', + }, + } as unknown) as GetExploreUrlArguments; + + it('should omit legendFormat in explore url', () => { + expect(getExploreUrl(args).then(data => expect(data).not.toMatch(/legendFormat1/g))); + }); +}); + describe('updateHistory()', () => { const datasourceId = 'myDatasource'; const key = `grafana.explore.history.${datasourceId}`; diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 05eaca48541..2cb03cf8d5e 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -70,7 +70,11 @@ export interface GetExploreUrlArguments { export async function getExploreUrl(args: GetExploreUrlArguments): Promise { const { panel, panelTargets, panelDatasource, datasourceSrv, timeSrv } = args; let exploreDatasource = panelDatasource; - let exploreTargets: DataQuery[] = panelTargets; + + /** In Explore, we don't have legend formatter and we don't want to keep + * legend formatting as we can't change it + */ + let exploreTargets: DataQuery[] = panelTargets.map(t => _.omit(t, 'legendFormat')); let url: string | undefined; // Mixed datasources need to choose only one datasource