mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
filter out build in datasources. add unit test
This commit is contained in:
parent
b1a40992d3
commit
68c2d2631e
@ -158,7 +158,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
|
||||
if (!datasourceSrv) {
|
||||
throw new Error('No datasource service passed as props.');
|
||||
}
|
||||
const datasources = datasourceSrv.getAll();
|
||||
const datasources = datasourceSrv.getExternal();
|
||||
const exploreDatasources = datasources.map(ds => ({
|
||||
value: ds.name,
|
||||
label: ds.name,
|
||||
@ -574,6 +574,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
|
||||
'Table',
|
||||
{
|
||||
format: 'table',
|
||||
resultFormat: 'table',
|
||||
instant: true,
|
||||
valueWithRefId: true,
|
||||
},
|
||||
@ -585,6 +586,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
|
||||
'Graph',
|
||||
{
|
||||
format: 'time_series',
|
||||
resultFormat: 'time_series',
|
||||
instant: false,
|
||||
},
|
||||
makeTimeSeriesList
|
||||
|
@ -78,6 +78,11 @@ export class DatasourceSrv {
|
||||
return Object.keys(datasources).map(name => datasources[name]);
|
||||
}
|
||||
|
||||
getExternal() {
|
||||
const datasources = this.getAll().filter(ds => !ds.meta.builtIn);
|
||||
return _.sortBy(datasources, ['name']);
|
||||
}
|
||||
|
||||
getAnnotationSources() {
|
||||
const sources = [];
|
||||
|
||||
|
@ -18,6 +18,32 @@ const templateSrv = {
|
||||
describe('datasource_srv', () => {
|
||||
const _datasourceSrv = new DatasourceSrv({}, {}, {}, templateSrv);
|
||||
|
||||
describe('when loading external datasources', () => {
|
||||
beforeEach(() => {
|
||||
config.datasources = {
|
||||
buildInDs: {
|
||||
name: 'buildIn',
|
||||
meta: { builtIn: true },
|
||||
},
|
||||
nonBuildIn: {
|
||||
name: 'external1',
|
||||
meta: { builtIn: false },
|
||||
},
|
||||
nonExplore: {
|
||||
name: 'external2',
|
||||
meta: {},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should return list of explore sources', () => {
|
||||
const externalSources = _datasourceSrv.getExternal();
|
||||
expect(externalSources.length).toBe(2);
|
||||
expect(externalSources[0].name).toBe('external1');
|
||||
expect(externalSources[1].name).toBe('external2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when loading metric sources', () => {
|
||||
let metricSources;
|
||||
const unsortedDatasources = {
|
||||
|
Loading…
Reference in New Issue
Block a user