mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(datasources): add option to avoid adding '-- Grafana --' DS (#90175)
* fix(datasources): add option to avoid adding '-- Grafana --' DS Currently the `getList` method of `DatasourceSrv` adds the '-- Grafana --' datasource in the majority of situations, unless a few of the other filters are set, all of which affect the results in other ways. This is the case even if the `filter` function is passed. This causes the `DataSourcePicker` component to include the '-- Grafana --' datasource in cases it's unsupported, such as in Grafana ML where we only support specific datasource types. This commit adds a new optional `grafana` field to the filter interface. If explicitly set to `false`, the '-- Grafana --' datasource will not be added to the list of datasources returned. This should be backwards compatible and should allow developers to prevent that datasource from appearing in the `DataSourcePicker`. Relates to https://github.com/grafana/machine-learning/issues/4578. * Use filter func to see if we should add '-- Grafana --', instead
This commit is contained in:
parent
a0de3ef867
commit
4791d91408
@ -299,7 +299,7 @@ export class DatasourceSrv implements DataSourceService {
|
||||
|
||||
if (!filters.tracing) {
|
||||
const grafanaInstanceSettings = this.getInstanceSettings('-- Grafana --');
|
||||
if (grafanaInstanceSettings) {
|
||||
if (grafanaInstanceSettings && filters.filter?.(grafanaInstanceSettings) !== false) {
|
||||
base.push(grafanaInstanceSettings);
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +297,11 @@ describe('datasource_srv', () => {
|
||||
expect(list[2].name).toBe('${datasource}');
|
||||
});
|
||||
|
||||
it('Should filter out the -- Grafana -- datasource', () => {
|
||||
const list = dataSourceSrv.getList({ filter: (x) => x.name !== '-- Grafana --' });
|
||||
expect(list.find((x) => x.name === '-- Grafana --')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('Can get list of data sources with tracing: true', () => {
|
||||
const list = dataSourceSrv.getList({ tracing: true });
|
||||
expect(list[0].name).toBe('Jaeger');
|
||||
|
Loading…
Reference in New Issue
Block a user