diff --git a/ui/src/sources/components/SourceForm.js b/ui/src/sources/components/SourceForm.js index 30429799f5..28464c3486 100644 --- a/ui/src/sources/components/SourceForm.js +++ b/ui/src/sources/components/SourceForm.js @@ -11,9 +11,6 @@ const { export const SourceForm = React.createClass({ propTypes: { - addFlashMessage: func.isRequired, - addSourceAction: func, - updateSourceAction: func, source: shape({}).isRequired, editMode: bool.isRequired, onInputChange: func.isRequired, diff --git a/ui/src/sources/containers/CreateSource.js b/ui/src/sources/containers/CreateSource.js index 5d7fa96163..d7a9277127 100644 --- a/ui/src/sources/containers/CreateSource.js +++ b/ui/src/sources/containers/CreateSource.js @@ -1,28 +1,34 @@ import React, {PropTypes} from 'react' import {withRouter} from 'react-router' -import {createSource} from 'shared/apis' import {connect} from 'react-redux' -import {insecureSkipVerifyText} from 'src/shared/copy/tooltipText' +import {createSource, updateSource} from 'shared/apis' +import SourceForm from 'src/sources/components/SourceForm' import {addSource as addSourceAction} from 'src/shared/actions/sources' +const { + func, + shape, + string, +} = PropTypes + export const CreateSource = React.createClass({ propTypes: { - router: PropTypes.shape({ - push: PropTypes.func.isRequired, + router: shape({ + push: func.isRequired, }).isRequired, - location: PropTypes.shape({ - query: PropTypes.shape({ - redirectPath: PropTypes.string, + location: shape({ + query: shape({ + redirectPath: string, }).isRequired, }).isRequired, - addSourceAction: PropTypes.func, + addSourceAction: func, + updateSourceAction: func, }, getInitialState() { return { - showSSL: false, - showMeta: false, + source: {}, } }, @@ -54,62 +60,117 @@ export const CreateSource = React.createClass({ return this.props.router.push(fixedPath) }, - onInputChange() { - const showSSL = !!this.sourceURL.value.startsWith("https") - this.setState(showSSL) + handleInputChange(e) { + const val = e.target.value + const name = e.target.name + this.setState((prevState) => { + const newSource = Object.assign({}, prevState.source, { + [name]: val, + }) + return Object.assign({}, prevState, {source: newSource}) + }) }, + handleBlurSourceURL(newSource) { + if (this.state.editMode) { + return + } + + if (!newSource.url) { + return + } + + // if there is a type on source it has already been created + if (newSource.type) { + return + } + + createSource(newSource).then(({data: sourceFromServer}) => { + this.props.addSourceAction(sourceFromServer) + this.setState({source: sourceFromServer}) + }).catch(({data: error}) => { + // dont want to flash this until they submit + this.setState({error: error.message}) + }) + }, + + handleSubmit(newSource) { + const {error} = this.state + + if (error) { + // useful error message + // return addFlashMessage({type: 'error', text: error}) + } + + updateSource(newSource).then(({data: sourceFromServer}) => { + this.props.updateSourceAction(sourceFromServer) + this.redirectToApp(newSource) + }).catch(() => { + // give a useful error message to the user + }) + }, + + //
+ //
+ //

Welcome to Chronograf

+ //
+ //
+ //

Connect to a New Source

+ //
+ // + //
+ //
+ //
+ // + // this.sourceURL = r} onChange={this.onInputChange} className="form-control" id="connect-string" defaultValue="http://localhost:8086"> + //
+ //
+ // + // this.sourceName = r} className="form-control" id="name" defaultValue="Influx 1"> + //
+ //
+ // + // this.sourceUser = r} className="form-control" id="username"> + //
+ //
+ // + // this.sourcePassword = r} className="form-control" id="password" type="password"> + //
+ //
+ //
+ // + // this.sourceTelegraf = r} className="form-control" id="telegraf" type="text" defaultValue="telegraf"> + //
+ // {this.state.showSSL ? + //
+ //
+ // this.sourceInsecureSkipVerify = r} /> + // + //
+ // + //
: null} + //
+ // + //
+ //
+ //
+ //
+ render() { + const {source} = this.state + return (
-
-
-

Welcome to Chronograf

-
-
-

Connect to a New Source

-
- -
-
-
- - this.sourceURL = r} onChange={this.onInputChange} className="form-control" id="connect-string" defaultValue="http://localhost:8086"> -
-
- - this.sourceName = r} className="form-control" id="name" defaultValue="Influx 1"> -
-
- - this.sourceUser = r} className="form-control" id="username"> -
-
- - this.sourcePassword = r} className="form-control" id="password" type="password"> -
-
-
- - this.sourceTelegraf = r} className="form-control" id="telegraf" type="text" defaultValue="telegraf"> -
- {this.state.showSSL ? -
-
- this.sourceInsecureSkipVerify = r} /> - -
- -
: null} -
- -
-
-
-
+
diff --git a/ui/src/sources/containers/SourcePage.js b/ui/src/sources/containers/SourcePage.js index 304303cf35..7900501203 100644 --- a/ui/src/sources/containers/SourcePage.js +++ b/ui/src/sources/containers/SourcePage.js @@ -105,7 +105,6 @@ export const SourcePage = React.createClass({ render() { const {source, editMode} = this.state - const {addFlashMessage} = this.props if (editMode && !source.id) { return
@@ -129,9 +128,6 @@ export const SourcePage = React.createClass({