Commit 7b218b71 by Zoltán Bedi Committed by GitHub

Explore: parse queryType from explore url (#26349)

* Explore: parse queryType from explore url

* Modify explore.ts parse logic
parent ba50e965
...@@ -65,7 +65,9 @@ describe('state functions', () => { ...@@ -65,7 +65,9 @@ describe('state functions', () => {
}); });
it('returns a valid Explore state from a compact URL parameter', () => { 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({ expect(parseUrlState(paramValue)).toMatchObject({
datasource: 'Local', datasource: 'Local',
queries: [{ expr: 'metric' }], queries: [{ expr: 'metric' }],
...@@ -75,6 +77,20 @@ describe('state functions', () => { ...@@ -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', () => { describe('serializeStateToUrlParam', () => {
......
...@@ -248,8 +248,7 @@ export function parseUrlState(initial: string | undefined): ExploreUrlState { ...@@ -248,8 +248,7 @@ export function parseUrlState(initial: string | undefined): ExploreUrlState {
}; };
const datasource = parsed[ParseUrlStateIndex.Datasource]; const datasource = parsed[ParseUrlStateIndex.Datasource];
const parsedSegments = parsed.slice(ParseUrlStateIndex.SegmentsStart); const parsedSegments = parsed.slice(ParseUrlStateIndex.SegmentsStart);
const metricProperties = ['expr', 'expression', 'target', 'datasource', 'query']; const queries = parsedSegments.filter(segment => !isSegment(segment, 'ui', 'originPanelId'));
const queries = parsedSegments.filter(segment => isSegment(segment, ...metricProperties));
const uiState = parsedSegments.filter(segment => isSegment(segment, 'ui'))[0]; const uiState = parsedSegments.filter(segment => isSegment(segment, 'ui'))[0];
const ui = uiState const ui = uiState
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment