From 44f2041cf3e543e5ac1d4f3b881cbd49b83cc876 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Wed, 3 Oct 2018 09:56:15 +0200 Subject: [PATCH] added data source type type --- .../datasources/NewDataSourcePage.tsx | 44 ++++++++++++------- .../app/features/datasources/state/actions.ts | 32 ++++++++++++-- .../features/datasources/state/reducers.ts | 6 ++- public/app/types/datasources.ts | 6 +++ public/app/types/index.ts | 3 +- 5 files changed, 71 insertions(+), 20 deletions(-) diff --git a/public/app/features/datasources/NewDataSourcePage.tsx b/public/app/features/datasources/NewDataSourcePage.tsx index 3024ffdddf4..6ef46480e6d 100644 --- a/public/app/features/datasources/NewDataSourcePage.tsx +++ b/public/app/features/datasources/NewDataSourcePage.tsx @@ -3,33 +3,34 @@ import { connect } from 'react-redux'; import { hot } from 'react-hot-loader'; import Select from 'react-select'; import PageHeader from 'app/core/components/PageHeader/PageHeader'; -import { NavModel } from 'app/types'; -import { addDataSource } from './state/actions'; +import { DataSourceType, NavModel } from 'app/types'; +import { addDataSource, loadDataSourceTypes } from './state/actions'; +import { updateLocation } from '../../core/actions'; import { getNavModel } from 'app/core/selectors/navModel'; export interface Props { navModel: NavModel; + dataSourceTypes: DataSourceType[]; addDataSource: typeof addDataSource; + loadDataSourceTypes: typeof loadDataSourceTypes; + updateLocation: typeof updateLocation; } export interface State { name: string; type: { value: string; label: string }; - dataSourceOptions: Array<{ value: string; label: string }>; } class NewDataSourcePage extends PureComponent { state = { name: '', type: null, - dataSourceOptions: [ - { value: 'prometheus', label: 'Prometheus' }, - { value: 'graphite', label: 'Graphite' }, - { value: 'mysql', label: 'MySql' }, - { value: 'influxdb', label: 'InfluxDB' }, - ], }; + componentDidMount() { + this.props.loadDataSourceTypes(); + } + onChangeName = event => { this.setState({ name: event.target.value, @@ -42,12 +43,18 @@ class NewDataSourcePage extends PureComponent { }); }; - submitForm = () => { + submitForm = event => { + event.preventDefault(); + if (!this.isFieldsEmpty()) { - // post + this.props.addDataSource(this.state.name, this.state.type.value); } }; + goBack = () => { + this.props.updateLocation({ path: '/datasources' }); + }; + isFieldsEmpty = () => { const { name, type } = this.state; @@ -61,8 +68,8 @@ class NewDataSourcePage extends PureComponent { }; render() { - const { navModel } = this.props; - const { dataSourceOptions, name, type } = this.state; + const { navModel, dataSourceTypes } = this.props; + const { name, type } = this.state; return (
@@ -83,7 +90,9 @@ class NewDataSourcePage extends PureComponent {
Type