[v.10.4.x] Explore: lookup datasource by name when present in legacy URLs (#87773)
[v.10.2.x] Explore: lookup datasource by name when present in legacy URLs
Backport 867d36fe59 from #85222
This commit is contained in:
@@ -138,7 +138,14 @@ describe('useStateSync', () => {
|
|||||||
const { location, waitForNextUpdate, store } = setup({
|
const { location, waitForNextUpdate, store } = setup({
|
||||||
queryParams: {
|
queryParams: {
|
||||||
panes: JSON.stringify({
|
panes: JSON.stringify({
|
||||||
one: { datasource: 'loki-uid', queries: [{ datasource: { name: 'loki', uid: 'loki-uid' }, refId: '1+2' }] },
|
one: {
|
||||||
|
datasource: 'loki-uid',
|
||||||
|
queries: [
|
||||||
|
{ datasource: { name: 'loki', uid: 'loki-uid' }, refId: '1+2' },
|
||||||
|
{ datasource: 'loki-uid', refId: '3' },
|
||||||
|
{ datasource: 'loki', refId: '4' },
|
||||||
|
],
|
||||||
|
},
|
||||||
two: { datasource: 'elastic-uid', queries: [{ datasource: { name: 'elastic', uid: 'elastic-uid' } }] },
|
two: { datasource: 'elastic-uid', queries: [{ datasource: { name: 'elastic', uid: 'elastic-uid' } }] },
|
||||||
}),
|
}),
|
||||||
schemaVersion: 1,
|
schemaVersion: 1,
|
||||||
@@ -182,9 +189,16 @@ describe('useStateSync', () => {
|
|||||||
if (panes) {
|
if (panes) {
|
||||||
// check if the URL is properly encoded when finishing rendering the hook. (this would be '1 2' otherwise)
|
// check if the URL is properly encoded when finishing rendering the hook. (this would be '1 2' otherwise)
|
||||||
expect(JSON.parse(panes)['one'].queries[0].refId).toBe('1+2');
|
expect(JSON.parse(panes)['one'].queries[0].refId).toBe('1+2');
|
||||||
|
expect(JSON.parse(panes)['one'].queries[0].datasource?.uid).toBe('loki-uid');
|
||||||
|
|
||||||
// we expect panes in the state to be in the same order as the ones in the URL
|
// we expect panes in the state to be in the same order as the ones in the URL
|
||||||
expect(Object.keys(store.getState().explore.panes)).toStrictEqual(Object.keys(JSON.parse(panes)));
|
expect(Object.keys(store.getState().explore.panes)).toStrictEqual(Object.keys(JSON.parse(panes)));
|
||||||
|
|
||||||
|
// check that the datasources for the queries resolved correctly when set to a name or uid
|
||||||
|
expect(JSON.parse(panes)['one'].queries[1].refId).toBe('3');
|
||||||
|
expect(JSON.parse(panes)['one'].queries[1].datasource?.uid).toBe('loki-uid');
|
||||||
|
expect(JSON.parse(panes)['one'].queries[2].refId).toBe('4');
|
||||||
|
expect(JSON.parse(panes)['one'].queries[2].datasource?.uid).toBe('loki-uid');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ function getQueryFilter(datasource?: DataSourceApi) {
|
|||||||
}
|
}
|
||||||
// Due to legacy URLs, `datasource` in queries may be a string. This logic should probably be in the migration
|
// Due to legacy URLs, `datasource` in queries may be a string. This logic should probably be in the migration
|
||||||
if (typeof q.datasource === 'string') {
|
if (typeof q.datasource === 'string') {
|
||||||
return q.datasource === datasource?.uid;
|
return q.datasource === datasource?.uid || q.datasource === datasource?.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return q.datasource.uid === datasource?.uid;
|
return q.datasource.uid === datasource?.uid;
|
||||||
|
|||||||
Reference in New Issue
Block a user