Explore: Remove legend formatting when switching from panel to Explore (#25848)

* Remove legend formatting when switching from panel to explore

* Add test coverage
This commit is contained in:
Ivana Huckova 2020-06-30 16:14:27 +02:00 committed by GitHub
parent 75a714aa51
commit 6c7a452726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -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}`;

View File

@ -70,7 +70,11 @@ export interface GetExploreUrlArguments {
export async function getExploreUrl(args: GetExploreUrlArguments): Promise<string | undefined> {
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