Explore: parse queryType from explore url (#26349)

* Explore: parse queryType from explore url

* Modify explore.ts parse logic
This commit is contained in:
Zoltán Bedi 2020-07-22 16:36:53 +02:00 committed by GitHub
parent ba50e96544
commit 7b218b7198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -65,7 +65,9 @@ describe('state functions', () => {
});
it('returns a valid Explore state from a compact URL parameter', () => {
const paramValue = '%5B"now-1h","now","Local","5m",%7B"expr":"metric"%7D,"ui"%5D';
// ["now-1h","now","Local",{"expr":"metric"},{"ui":[true,true,true,"none"]}]
const paramValue =
'%5B"now-1h","now","Local",%7B"expr":"metric"%7D,%7B%22ui%22:%5Btrue,true,true,%22none%22%5D%7D%5D';
expect(parseUrlState(paramValue)).toMatchObject({
datasource: 'Local',
queries: [{ expr: 'metric' }],
@ -75,6 +77,20 @@ describe('state functions', () => {
},
});
});
it('should return queries if queryType is present in the url', () => {
// ["now-1h","now","x-ray-datasource",{"queryType":"getTraceSummaries"},{"ui":[true,true,true,"none"]}]
const paramValue =
'%5B"now-1h","now","x-ray-datasource",%7B"queryType":"getTraceSummaries"%7D,%7B%22ui%22:%5Btrue,true,true,%22none%22%5D%7D%5D';
expect(parseUrlState(paramValue)).toMatchObject({
datasource: 'x-ray-datasource',
queries: [{ queryType: 'getTraceSummaries' }],
range: {
from: 'now-1h',
to: 'now',
},
});
});
});
describe('serializeStateToUrlParam', () => {

View File

@ -248,8 +248,7 @@ export function parseUrlState(initial: string | undefined): ExploreUrlState {
};
const datasource = parsed[ParseUrlStateIndex.Datasource];
const parsedSegments = parsed.slice(ParseUrlStateIndex.SegmentsStart);
const metricProperties = ['expr', 'expression', 'target', 'datasource', 'query'];
const queries = parsedSegments.filter(segment => isSegment(segment, ...metricProperties));
const queries = parsedSegments.filter(segment => !isSegment(segment, 'ui', 'originPanelId'));
const uiState = parsedSegments.filter(segment => isSegment(segment, 'ui'))[0];
const ui = uiState