mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Bug: Fix DatasourceSrv getList with aliases (#77027)
This commit is contained in:
parent
c514bad472
commit
314bea935f
@ -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)) {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user