mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
added actions
This commit is contained in:
parent
52232f98b9
commit
6dc3e0399d
1
.gitignore
vendored
1
.gitignore
vendored
@ -75,3 +75,4 @@ debug.test
|
||||
/devenv/bulk_alerting_dashboards/*.json
|
||||
|
||||
/scripts/build/release_publisher/release_publisher
|
||||
*.patch
|
||||
|
@ -1,11 +1,14 @@
|
||||
import { ThunkAction } from 'redux-thunk';
|
||||
import { DataSource, Plugin, StoreState } from 'app/types';
|
||||
import { getBackendSrv } from '../../../core/services/backend_srv';
|
||||
import { getDatasourceSrv } from '../../plugins/datasource_srv';
|
||||
import { LayoutMode } from '../../../core/components/LayoutSelector/LayoutSelector';
|
||||
import { updateLocation, updateNavIndex, UpdateNavIndexAction } from '../../../core/actions';
|
||||
import { UpdateLocationAction } from '../../../core/actions/location';
|
||||
import { buildNavModel } from './navModel';
|
||||
|
||||
import config from '../../../core/config';
|
||||
|
||||
export enum ActionTypes {
|
||||
LoadDataSources = 'LOAD_DATA_SOURCES',
|
||||
LoadDataSourceTypes = 'LOAD_DATA_SOURCE_TYPES',
|
||||
@ -159,7 +162,14 @@ export function loadDataSourceTypes(): ThunkResult<void> {
|
||||
|
||||
export function updateDataSource(dataSource: DataSource): ThunkResult<void> {
|
||||
return async dispatch => {
|
||||
await getBackendSrv().put(`/api/datasources/${dataSource.id}`, dataSource);
|
||||
await getBackendSrv()
|
||||
.put(`/api/datasources/${dataSource.id}`, dataSource)
|
||||
.then(response => {
|
||||
updateFrontendSettings().then(() => {
|
||||
testDataSource(response.name);
|
||||
});
|
||||
});
|
||||
|
||||
dispatch(loadDataSource(dataSource.id));
|
||||
};
|
||||
}
|
||||
@ -201,6 +211,49 @@ export function findNewName(dataSources, name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
function updateFrontendSettings() {
|
||||
return getBackendSrv()
|
||||
.get('/api/frontend/settings')
|
||||
.then(settings => {
|
||||
config.datasources = settings.datasources;
|
||||
config.defaultDatasource = settings.defaultDatasource;
|
||||
getDatasourceSrv().init();
|
||||
});
|
||||
}
|
||||
|
||||
function testDataSource(name) {
|
||||
getDatasourceSrv()
|
||||
.get(name)
|
||||
.then(dataSource => {
|
||||
if (!dataSource.testDatasource) {
|
||||
return;
|
||||
}
|
||||
|
||||
const testing = { done: false, status: 'error', message: '' };
|
||||
|
||||
// make test call in no backend cache context
|
||||
getBackendSrv()
|
||||
.withNoBackendCache(() => {
|
||||
return dataSource
|
||||
.testDatasource()
|
||||
.then(result => {
|
||||
testing.message = result.message;
|
||||
testing.status = result.status;
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.statusText) {
|
||||
testing.message = 'HTTP Error ' + err.statusText;
|
||||
} else {
|
||||
testing.message = err.message;
|
||||
}
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
testing.done = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function nameHasSuffix(name) {
|
||||
return name.endsWith('-', name.length - 1);
|
||||
}
|
||||
|
@ -88,4 +88,5 @@ export interface DataQueryOptions {
|
||||
|
||||
export interface DataSourceApi {
|
||||
query(options: DataQueryOptions): Promise<DataQueryResponse>;
|
||||
testDatasource(): Promise<any>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user