Explore: Change datasourceName usage to datasourceUID or datasourceRef where appropriate (#52479)

* First pass at using datasource UID when appropriate

* Fix tests

* be more lenient with lookup to accomodate different URLs

* Make test setup get mock work like real datasource get

* Fix the typing issue and remaining tests

* Fix PR feedback
This commit is contained in:
Kristina
2022-07-25 13:05:57 -05:00
committed by GitHub
parent cb35729553
commit 0e13ee345d
17 changed files with 71 additions and 58 deletions

View File

@@ -606,6 +606,7 @@ describe('getLinksSupplier', () => {
getTimeRangeForUrl: (() => {}) as any,
});
const datasourceUid = '1234';
const f0 = new MutableDataFrame({
name: 'A',
fields: [
@@ -619,7 +620,7 @@ describe('getLinksSupplier', () => {
url: '',
title: '',
internal: {
datasourceUid: '0',
datasourceUid: datasourceUid,
datasourceName: 'testDS',
query: '12345',
},
@@ -640,12 +641,12 @@ describe('getLinksSupplier', () => {
);
const links = supplier({ valueRowIndex: 0 });
const encodeURIParams = `{"datasource":"${datasourceUid}","queries":["12345"],"panelsState":{}}`;
expect(links.length).toBe(1);
expect(links[0]).toEqual(
expect.objectContaining({
title: 'testDS',
href: `/explore?left=${encodeURIComponent('{"datasource":"testDS","queries":["12345"],"panelsState":{}}')}`,
href: `/explore?left=${encodeURIComponent(encodeURIParams)}`,
onClick: undefined,
})
);

View File

@@ -44,7 +44,7 @@ export interface DataLink<T extends DataQuery = any> {
export interface InternalDataLink<T extends DataQuery = any> {
query: T;
datasourceUid: string;
datasourceName: string;
datasourceName: string; // used as a title if `DataLink.title` is empty
panelsState?: ExplorePanelsState;
}

View File

@@ -33,7 +33,7 @@ describe('mapInternalLinkToExplore', () => {
expect.objectContaining({
title: 'dsName',
href: `/explore?left=${encodeURIComponent(
'{"datasource":"dsName","queries":[{"query":"12344"}],"panelsState":{}}'
'{"datasource":"uid","queries":[{"query":"12344"}],"panelsState":{}}'
)}`,
onClick: undefined,
})
@@ -76,7 +76,7 @@ describe('mapInternalLinkToExplore', () => {
expect.objectContaining({
title: 'dsName',
href: `/explore?left=${encodeURIComponent(
'{"datasource":"dsName","queries":[{"query":"12344"}],"panelsState":{"trace":{"spanId":"abcdef"}}}'
'{"datasource":"uid","queries":[{"query":"12344"}],"panelsState":{"trace":{"spanId":"abcdef"}}}'
)}`,
onClick: undefined,
})

View File

@@ -51,7 +51,7 @@ export function mapInternalLinkToExplore(options: LinkToExploreOptions): LinkMod
title: replaceVariables(title, scopedVars),
// In this case this is meant to be internal link (opens split view by default) the href will also points
// to explore but this way you can open it in new tab.
href: generateInternalHref(internalLink.datasourceName, interpolatedQuery, range, interpolatedPanelsState),
href: generateInternalHref(internalLink.datasourceUid, interpolatedQuery, range, interpolatedPanelsState),
onClick: onClickFn
? () => {
onClickFn({
@@ -71,7 +71,7 @@ export function mapInternalLinkToExplore(options: LinkToExploreOptions): LinkMod
* Generates href for internal derived field link.
*/
function generateInternalHref<T extends DataQuery = any>(
datasourceName: string,
datasourceUid: string,
query: T,
range: TimeRange,
panelsState?: ExplorePanelsState
@@ -80,7 +80,7 @@ function generateInternalHref<T extends DataQuery = any>(
`/explore?left=${encodeURIComponent(
serializeStateToUrlParam({
range: range.raw,
datasource: datasourceName,
datasource: datasourceUid,
queries: [query],
panelsState: panelsState,
})