|
@@ -1,10 +1,12 @@
|
|
|
import { ThunkAction } from 'redux-thunk';
|
|
import { ThunkAction } from 'redux-thunk';
|
|
|
-import { DataSource, Plugin, StoreState } from 'app/types';
|
|
|
|
|
-import { getBackendSrv } from '../../../core/services/backend_srv';
|
|
|
|
|
-import { LayoutMode } from '../../../core/components/LayoutSelector/LayoutSelector';
|
|
|
|
|
-import { updateLocation, updateNavIndex, UpdateNavIndexAction } from '../../../core/actions';
|
|
|
|
|
-import { UpdateLocationAction } from '../../../core/actions/location';
|
|
|
|
|
|
|
+import config from '../../../core/config';
|
|
|
|
|
+import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
|
+import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
|
|
|
|
+import { LayoutMode } from 'app/core/components/LayoutSelector/LayoutSelector';
|
|
|
|
|
+import { updateLocation, updateNavIndex, UpdateNavIndexAction } from 'app/core/actions';
|
|
|
|
|
+import { UpdateLocationAction } from 'app/core/actions/location';
|
|
|
import { buildNavModel } from './navModel';
|
|
import { buildNavModel } from './navModel';
|
|
|
|
|
+import { DataSource, Plugin, StoreState } from 'app/types';
|
|
|
|
|
|
|
|
export enum ActionTypes {
|
|
export enum ActionTypes {
|
|
|
LoadDataSources = 'LOAD_DATA_SOURCES',
|
|
LoadDataSources = 'LOAD_DATA_SOURCES',
|
|
@@ -14,43 +16,49 @@ export enum ActionTypes {
|
|
|
SetDataSourcesSearchQuery = 'SET_DATA_SOURCES_SEARCH_QUERY',
|
|
SetDataSourcesSearchQuery = 'SET_DATA_SOURCES_SEARCH_QUERY',
|
|
|
SetDataSourcesLayoutMode = 'SET_DATA_SOURCES_LAYOUT_MODE',
|
|
SetDataSourcesLayoutMode = 'SET_DATA_SOURCES_LAYOUT_MODE',
|
|
|
SetDataSourceTypeSearchQuery = 'SET_DATA_SOURCE_TYPE_SEARCH_QUERY',
|
|
SetDataSourceTypeSearchQuery = 'SET_DATA_SOURCE_TYPE_SEARCH_QUERY',
|
|
|
|
|
+ SetDataSourceName = 'SET_DATA_SOURCE_NAME',
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface LoadDataSourcesAction {
|
|
|
|
|
|
|
+interface LoadDataSourcesAction {
|
|
|
type: ActionTypes.LoadDataSources;
|
|
type: ActionTypes.LoadDataSources;
|
|
|
payload: DataSource[];
|
|
payload: DataSource[];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface SetDataSourcesSearchQueryAction {
|
|
|
|
|
|
|
+interface SetDataSourcesSearchQueryAction {
|
|
|
type: ActionTypes.SetDataSourcesSearchQuery;
|
|
type: ActionTypes.SetDataSourcesSearchQuery;
|
|
|
payload: string;
|
|
payload: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface SetDataSourcesLayoutModeAction {
|
|
|
|
|
|
|
+interface SetDataSourcesLayoutModeAction {
|
|
|
type: ActionTypes.SetDataSourcesLayoutMode;
|
|
type: ActionTypes.SetDataSourcesLayoutMode;
|
|
|
payload: LayoutMode;
|
|
payload: LayoutMode;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface LoadDataSourceTypesAction {
|
|
|
|
|
|
|
+interface LoadDataSourceTypesAction {
|
|
|
type: ActionTypes.LoadDataSourceTypes;
|
|
type: ActionTypes.LoadDataSourceTypes;
|
|
|
payload: Plugin[];
|
|
payload: Plugin[];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface SetDataSourceTypeSearchQueryAction {
|
|
|
|
|
|
|
+interface SetDataSourceTypeSearchQueryAction {
|
|
|
type: ActionTypes.SetDataSourceTypeSearchQuery;
|
|
type: ActionTypes.SetDataSourceTypeSearchQuery;
|
|
|
payload: string;
|
|
payload: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface LoadDataSourceAction {
|
|
|
|
|
|
|
+interface LoadDataSourceAction {
|
|
|
type: ActionTypes.LoadDataSource;
|
|
type: ActionTypes.LoadDataSource;
|
|
|
payload: DataSource;
|
|
payload: DataSource;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface LoadDataSourceMetaAction {
|
|
|
|
|
|
|
+interface LoadDataSourceMetaAction {
|
|
|
type: ActionTypes.LoadDataSourceMeta;
|
|
type: ActionTypes.LoadDataSourceMeta;
|
|
|
payload: Plugin;
|
|
payload: Plugin;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+interface SetDataSourceNameAction {
|
|
|
|
|
+ type: ActionTypes.SetDataSourceName;
|
|
|
|
|
+ payload: string;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const dataSourcesLoaded = (dataSources: DataSource[]): LoadDataSourcesAction => ({
|
|
const dataSourcesLoaded = (dataSources: DataSource[]): LoadDataSourcesAction => ({
|
|
|
type: ActionTypes.LoadDataSources,
|
|
type: ActionTypes.LoadDataSources,
|
|
|
payload: dataSources,
|
|
payload: dataSources,
|
|
@@ -86,6 +94,11 @@ export const setDataSourceTypeSearchQuery = (query: string): SetDataSourceTypeSe
|
|
|
payload: query,
|
|
payload: query,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+export const setDataSourceName = (name: string) => ({
|
|
|
|
|
+ type: ActionTypes.SetDataSourceName,
|
|
|
|
|
+ payload: name,
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
export type Action =
|
|
export type Action =
|
|
|
| LoadDataSourcesAction
|
|
| LoadDataSourcesAction
|
|
|
| SetDataSourcesSearchQueryAction
|
|
| SetDataSourcesSearchQueryAction
|
|
@@ -95,7 +108,8 @@ export type Action =
|
|
|
| SetDataSourceTypeSearchQueryAction
|
|
| SetDataSourceTypeSearchQueryAction
|
|
|
| LoadDataSourceAction
|
|
| LoadDataSourceAction
|
|
|
| UpdateNavIndexAction
|
|
| UpdateNavIndexAction
|
|
|
- | LoadDataSourceMetaAction;
|
|
|
|
|
|
|
+ | LoadDataSourceMetaAction
|
|
|
|
|
+ | SetDataSourceNameAction;
|
|
|
|
|
|
|
|
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
|
|
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
|
|
|
|
|
|
|
@@ -145,6 +159,23 @@ export function loadDataSourceTypes(): ThunkResult<void> {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+export function updateDataSource(dataSource: DataSource): ThunkResult<void> {
|
|
|
|
|
+ return async dispatch => {
|
|
|
|
|
+ await getBackendSrv().put(`/api/datasources/${dataSource.id}`, dataSource);
|
|
|
|
|
+ await updateFrontendSettings();
|
|
|
|
|
+ return dispatch(loadDataSource(dataSource.id));
|
|
|
|
|
+ };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export function deleteDataSource(): ThunkResult<void> {
|
|
|
|
|
+ return async (dispatch, getStore) => {
|
|
|
|
|
+ const dataSource = getStore().dataSources.dataSource;
|
|
|
|
|
+
|
|
|
|
|
+ await getBackendSrv().delete(`/api/datasources/${dataSource.id}`);
|
|
|
|
|
+ dispatch(updateLocation({ path: '/datasources' }));
|
|
|
|
|
+ };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export function nameExits(dataSources, name) {
|
|
export function nameExits(dataSources, name) {
|
|
|
return (
|
|
return (
|
|
|
dataSources.filter(dataSource => {
|
|
dataSources.filter(dataSource => {
|
|
@@ -173,6 +204,16 @@ export function findNewName(dataSources, name) {
|
|
|
return name;
|
|
return name;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function updateFrontendSettings() {
|
|
|
|
|
+ return getBackendSrv()
|
|
|
|
|
+ .get('/api/frontend/settings')
|
|
|
|
|
+ .then(settings => {
|
|
|
|
|
+ config.datasources = settings.datasources;
|
|
|
|
|
+ config.defaultDatasource = settings.defaultDatasource;
|
|
|
|
|
+ getDatasourceSrv().init();
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function nameHasSuffix(name) {
|
|
function nameHasSuffix(name) {
|
|
|
return name.endsWith('-', name.length - 1);
|
|
return name.endsWith('-', name.length - 1);
|
|
|
}
|
|
}
|