From ea6efe8aa62290994b7a930415edb8b5ad4da376 Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Tue, 31 Jul 2018 14:22:20 -0700 Subject: [PATCH] Create SourceStep component and pass ref to connect to wizard actions Co-authored-by: Daniel Campbell Co-authored-by: Deniz Kusefoglu --- .../components/wizard/WizardTextInput.tsx | 6 +- .../sources/components/ConnectionWizard.tsx | 35 ++++--- ui/src/sources/components/SourceStep.tsx | 94 +++++++++++++++++++ 3 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 ui/src/sources/components/SourceStep.tsx diff --git a/ui/src/reusable_ui/components/wizard/WizardTextInput.tsx b/ui/src/reusable_ui/components/wizard/WizardTextInput.tsx index 6d9087ae1..5ce58c4ad 100644 --- a/ui/src/reusable_ui/components/wizard/WizardTextInput.tsx +++ b/ui/src/reusable_ui/components/wizard/WizardTextInput.tsx @@ -29,7 +29,7 @@ class WizardTextInput extends PureComponent { isDisabled: false, isValid: () => ({ status: true, - reason: 'this is the reason your input is bad', + reason: '', }), valueModifier: x => x, autoFocus: false, @@ -59,12 +59,10 @@ class WizardTextInput extends PureComponent { if (validation.status === false) { inputClass = 'form-volcano' errorText = validation.reason - console.log('false') } - console.log(value) return ( -
+
} @ErrorHandling @@ -19,10 +23,13 @@ class ConnectionWizard extends PureComponent { super(props) this.state = { completion: [false, false, false], + source: DEFAULT_SOURCE, } } public render() { const {isVisible, toggleVisibility} = this.props + const {source} = this.state + return ( { title="Add a New InfluxDB Connection" tipText="" isComplete={this.isSourceComplete} - onNext={this.handleFirstNext} - onPrevious={this.handleFirstPrev} - nextLabel="Continue" + onNext={this.handleSourceNext} + nextLabel="Create Source" previousLabel="Cancel" > - first children + (this.sourceStepRef = c && c.getWrappedInstance())} + /> { nextLabel="Complete Connection" previousLabel="Go Back" > - some third children + Dashboards boxes here ) } + private handleSourceNext = () => { + this.sourceStepRef.next() + } private isSourceComplete = () => { const {completion} = this.state return completion[0] } - private isKapacitorComplete = () => { const {completion} = this.state return completion[1] } - private isDashboardSelectionComplete = () => { const {completion} = this.state return completion[2] } - private handleFirstNext = () => { const {completion} = this.state completion[0] = true this.setState({ - completion + completion, }) } private handleSecondNext = () => { const {completion} = this.state completion[1] = true this.setState({ - completion + completion, }) } private handleThirdNext = () => { const {completion} = this.state completion[2] = true this.setState({ - completion + completion, }) } diff --git a/ui/src/sources/components/SourceStep.tsx b/ui/src/sources/components/SourceStep.tsx new file mode 100644 index 000000000..9b6d06bfc --- /dev/null +++ b/ui/src/sources/components/SourceStep.tsx @@ -0,0 +1,94 @@ +import React, {PureComponent} from 'react' +import {connect} from 'react-redux' + +import {ErrorHandling} from 'src/shared/decorators/errors' +import {createSource, updateSource} from 'src/shared/apis' + +import WizardTextInput from 'src/reusable_ui/components/wizard/WizardTextInput' +import { + addSource as addSourceAction, + AddSource, +} from 'src/shared/actions/sources' +import {Source} from 'src/types' + +interface Props {} + +interface State { + source: object +} + +@ErrorHandling +class SourceStep extends PureComponent { + constructor(props: Props) { + super(props) + this.state = { + source: { + url: '', + name: '', + username: '', + password: '', + telegraf: '', + defaultRP: '', + }, + } + } + public render() { + const {handleInputChange} = this.props + const {source} = this.state + + return ( + <> + + + + + + + + ) + } + + private onChangeInput = (key: string) => (value: string) => { + const {source} = this.state + this.setState({source: {...source, [key]: value}}) + } + + private next = () => { + const {source} = this.state + console.log('creating source', source) + // const sourceFromServer = await createSource(source) + // this.props.addSource(sourceFromServer) + // console.log(source.name) + } +} + +const mdtp = { + addSource: addSourceAction, +} + +export default connect(null, mdtp, null, {withRef: true})(SourceStep) +// export default SourceStep