Bug: Fix DatasourceSrv getList with aliases (#77027)

This commit is contained in:
Andres Martinez Gotor 2023-10-26 09:30:24 +02:00 committed by GitHub
parent c514bad472
commit 314bea935f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import { some } from 'lodash';
import {
AppEvents,
DataSourceApi,
@ -222,7 +224,10 @@ export class DatasourceSrv implements DataSourceService {
if (filters.alerting && !x.meta.alerting) {
return false;
}
if (filters.pluginId && x.meta.id !== filters.pluginId) {
if (
filters.pluginId &&
!(x.meta.id === filters.pluginId || some(x.meta.aliasIDs, (id) => id === filters.pluginId))
) {
return false;
}
if (filters.filter && !filters.filter(x)) {

View File

@ -129,6 +129,11 @@ describe('datasource_srv', () => {
uid: 'no-query',
meta: { id: 'no-query' },
},
TestData: {
type: 'grafana-testdata-datasource',
name: 'TestData',
meta: { metrics: true, id: 'grafana-testdata-datasource', aliasIDs: ['testdata'] },
},
};
describe('Given a list of data sources', () => {
@ -273,7 +278,7 @@ describe('datasource_srv', () => {
describe('when getting external metric sources', () => {
it('should return list of explore sources', () => {
const externalSources = dataSourceSrv.getExternal();
expect(externalSources.length).toBe(7);
expect(externalSources.length).toBe(8);
});
});
@ -307,6 +312,12 @@ describe('datasource_srv', () => {
expect(list.length).toBe(1);
});
it('Can get get list and filter by an alias', () => {
const list = dataSourceSrv.getList({ pluginId: 'testdata' });
expect(list[0].name).toBe('TestData');
expect(list.length).toBe(1);
});
it('Can get list of data sources with metrics: true, builtIn: true, mixed: true', () => {
expect(dataSourceSrv.getList({ metrics: true, dashboard: true, mixed: true })).toMatchInlineSnapshot(`
[
@ -344,6 +355,18 @@ describe('datasource_srv', () => {
"type": "test-db",
"uid": "uid-code-mmm",
},
{
"meta": {
"aliasIDs": [
"testdata",
],
"id": "grafana-testdata-datasource",
"metrics": true,
},
"name": "TestData",
"type": "grafana-testdata-datasource",
"uid": "TestData",
},
{
"meta": {
"metrics": true,