diff --git a/public/app/features/datasources/NewDataSourcePage.tsx b/public/app/features/datasources/NewDataSourcePage.tsx index c6eaa893d97..1d926048b8c 100644 --- a/public/app/features/datasources/NewDataSourcePage.tsx +++ b/public/app/features/datasources/NewDataSourcePage.tsx @@ -1,8 +1,8 @@ import React, { PureComponent } from 'react'; import { connect } from 'react-redux'; import { hot } from 'react-hot-loader'; -import PageHeader from 'app/core/components/PageHeader/PageHeader'; -import { NavModel, Plugin } from 'app/types'; +import Page from 'app/core/components/Page/Page'; +import { NavModel, Plugin, StoreState } from 'app/types'; import { addDataSource, loadDataSourceTypes, setDataSourceTypeSearchQuery } from './state/actions'; import { getNavModel } from 'app/core/selectors/navModel'; import { getDataSourceTypes } from './state/selectors'; @@ -10,6 +10,7 @@ import { getDataSourceTypes } from './state/selectors'; export interface Props { navModel: NavModel; dataSourceTypes: Plugin[]; + isLoading: boolean; addDataSource: typeof addDataSource; loadDataSourceTypes: typeof loadDataSourceTypes; dataSourceTypeSearchQuery: string; @@ -21,58 +22,59 @@ class NewDataSourcePage extends PureComponent { this.props.loadDataSourceTypes(); } - onDataSourceTypeClicked = type => { - this.props.addDataSource(type); + onDataSourceTypeClicked = (plugin: Plugin) => { + this.props.addDataSource(plugin); }; - onSearchQueryChange = event => { + onSearchQueryChange = (event: React.ChangeEvent) => { this.props.setDataSourceTypeSearchQuery(event.target.value); }; render() { - const { navModel, dataSourceTypes, dataSourceTypeSearchQuery } = this.props; - + const { navModel, dataSourceTypes, dataSourceTypeSearchQuery, isLoading } = this.props; return ( -
- -
-

Choose data source type

-
- + + +
+

Choose data source type

+
+ +
+
+ {dataSourceTypes.map((plugin, index) => { + return ( +
this.onDataSourceTypeClicked(plugin)} + className="add-data-source-grid-item" + key={`${plugin.id}-${index}`} + > + + {plugin.name} +
+ ); + })} +
-
- {dataSourceTypes.map((type, index) => { - return ( -
this.onDataSourceTypeClicked(type)} - className="add-data-source-grid-item" - key={`${type.id}-${index}`} - > - - {type.name} -
- ); - })} -
-
-
+ + ); } } -function mapStateToProps(state) { +function mapStateToProps(state: StoreState) { return { navModel: getNavModel(state.navIndex, 'datasources'), dataSourceTypes: getDataSourceTypes(state.dataSources), + isLoading: state.dataSources.isLoadingDataSources }; } diff --git a/public/app/features/datasources/state/actions.ts b/public/app/features/datasources/state/actions.ts index 008dc9fe816..0fa260ffafa 100644 --- a/public/app/features/datasources/state/actions.ts +++ b/public/app/features/datasources/state/actions.ts @@ -12,6 +12,7 @@ import { Plugin, StoreState } from 'app/types'; export enum ActionTypes { LoadDataSources = 'LOAD_DATA_SOURCES', LoadDataSourceTypes = 'LOAD_DATA_SOURCE_TYPES', + LoadedDataSourceTypes = 'LOADED_DATA_SOURCE_TYPES', LoadDataSource = 'LOAD_DATA_SOURCE', LoadDataSourceMeta = 'LOAD_DATA_SOURCE_META', SetDataSourcesSearchQuery = 'SET_DATA_SOURCES_SEARCH_QUERY', @@ -38,6 +39,10 @@ interface SetDataSourcesLayoutModeAction { interface LoadDataSourceTypesAction { type: ActionTypes.LoadDataSourceTypes; +} + +interface LoadedDataSourceTypesAction { + type: ActionTypes.LoadedDataSourceTypes; payload: Plugin[]; } @@ -81,8 +86,12 @@ const dataSourceMetaLoaded = (dataSourceMeta: Plugin): LoadDataSourceMetaAction payload: dataSourceMeta, }); -const dataSourceTypesLoaded = (dataSourceTypes: Plugin[]): LoadDataSourceTypesAction => ({ +const dataSourceTypesLoad = (): LoadDataSourceTypesAction => ({ type: ActionTypes.LoadDataSourceTypes, +}); + +const dataSourceTypesLoaded = (dataSourceTypes: Plugin[]): LoadedDataSourceTypesAction => ({ + type: ActionTypes.LoadedDataSourceTypes, payload: dataSourceTypes, }); @@ -117,6 +126,7 @@ export type Action = | SetDataSourcesLayoutModeAction | UpdateLocationAction | LoadDataSourceTypesAction + | LoadedDataSourceTypesAction | SetDataSourceTypeSearchQueryAction | LoadDataSourceAction | UpdateNavIndexAction @@ -167,6 +177,7 @@ export function addDataSource(plugin: Plugin): ThunkResult { export function loadDataSourceTypes(): ThunkResult { return async dispatch => { + dispatch(dataSourceTypesLoad()); const result = await getBackendSrv().get('/api/plugins', { enabled: 1, type: 'datasource' }); dispatch(dataSourceTypesLoaded(result)); }; diff --git a/public/app/features/datasources/state/reducers.ts b/public/app/features/datasources/state/reducers.ts index 7be93f5a644..66151990aea 100644 --- a/public/app/features/datasources/state/reducers.ts +++ b/public/app/features/datasources/state/reducers.ts @@ -12,6 +12,7 @@ const initialState: DataSourcesState = { dataSourceTypes: [] as Plugin[], dataSourceTypeSearchQuery: '', hasFetched: false, + isLoadingDataSources: false, dataSourceMeta: {} as Plugin, }; @@ -30,7 +31,10 @@ export const dataSourcesReducer = (state = initialState, action: Action): DataSo return { ...state, layoutMode: action.payload }; case ActionTypes.LoadDataSourceTypes: - return { ...state, dataSourceTypes: action.payload }; + return { ...state, dataSourceTypes: [], isLoadingDataSources: true }; + + case ActionTypes.LoadedDataSourceTypes: + return { ...state, dataSourceTypes: action.payload, isLoadingDataSources: false }; case ActionTypes.SetDataSourceTypeSearchQuery: return { ...state, dataSourceTypeSearchQuery: action.payload }; diff --git a/public/app/types/datasources.ts b/public/app/types/datasources.ts index 729760b41ea..da81a3023b7 100644 --- a/public/app/types/datasources.ts +++ b/public/app/types/datasources.ts @@ -12,4 +12,5 @@ export interface DataSourcesState { dataSource: DataSourceSettings; dataSourceMeta: Plugin; hasFetched: boolean; + isLoadingDataSources: boolean; }