Adding reload to datasourceSrv (#44217)

This commit is contained in:
Timur Olzhabayev
2022-01-24 10:45:05 +01:00
committed by GitHub
parent 732c2ebb37
commit c3f69cc4d9
8 changed files with 55 additions and 15 deletions

View File

@@ -8,8 +8,6 @@ import { importDataSourcePlugin } from 'app/features/plugins/plugin_loader';
import { getPluginSettings } from 'app/features/plugins/pluginSettings';
import { DataSourcePluginCategory, ThunkDispatch, ThunkResult } from 'app/types';
import config from '../../../core/config';
import { buildCategories } from './buildCategories';
import { buildNavModel } from './navModel';
import {
@@ -218,7 +216,7 @@ export function addDataSource(plugin: DataSourcePluginMeta): ThunkResult<void> {
}
const result = await getBackendSrv().post('/api/datasources', newInstance);
await updateFrontendSettings();
await getDatasourceSrv().reload();
locationService.push(`/datasources/edit/${result.datasource.uid}`);
};
}
@@ -235,7 +233,7 @@ export function loadDataSourcePlugins(): ThunkResult<void> {
export function updateDataSource(dataSource: DataSourceSettings): ThunkResult<void> {
return async (dispatch) => {
await getBackendSrv().put(`/api/datasources/${dataSource.id}`, dataSource); // by UID not yet supported
await updateFrontendSettings();
await getDatasourceSrv().reload();
return dispatch(loadDataSource(dataSource.uid));
};
}
@@ -245,7 +243,7 @@ export function deleteDataSource(): ThunkResult<void> {
const dataSource = getStore().dataSources.dataSource;
await getBackendSrv().delete(`/api/datasources/${dataSource.id}`);
await updateFrontendSettings();
await getDatasourceSrv().reload();
locationService.push('/datasources');
};
@@ -283,16 +281,6 @@ export function findNewName(dataSources: ItemWithName[], name: string) {
return name;
}
function updateFrontendSettings() {
return getBackendSrv()
.get('/api/frontend/settings')
.then((settings: any) => {
config.datasources = settings.datasources;
config.defaultDatasource = settings.defaultDatasource;
getDatasourceSrv().init(config.datasources, settings.defaultDatasource);
});
}
function nameHasSuffix(name: string) {
return name.endsWith('-', name.length - 1);
}