Create SourceStep component and pass ref to connect to wizard actions
Co-authored-by: Daniel Campbell <metalwhirlwind@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com>pull/4129/head
parent
a1758abc97
commit
ea6efe8aa6
|
@ -29,7 +29,7 @@ class WizardTextInput extends PureComponent<Props, State> {
|
||||||
isDisabled: false,
|
isDisabled: false,
|
||||||
isValid: () => ({
|
isValid: () => ({
|
||||||
status: true,
|
status: true,
|
||||||
reason: 'this is the reason your input is bad',
|
reason: '',
|
||||||
}),
|
}),
|
||||||
valueModifier: x => x,
|
valueModifier: x => x,
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
|
@ -59,12 +59,10 @@ class WizardTextInput extends PureComponent<Props, State> {
|
||||||
if (validation.status === false) {
|
if (validation.status === false) {
|
||||||
inputClass = 'form-volcano'
|
inputClass = 'form-volcano'
|
||||||
errorText = validation.reason
|
errorText = validation.reason
|
||||||
console.log('false')
|
|
||||||
}
|
}
|
||||||
console.log(value)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="form-group col-xs-12 wizard-input">
|
<div className="form-group col-xs-6 wizard-input">
|
||||||
<label htmlFor={label}>{label}</label>
|
<label htmlFor={label}>{label}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import React, {PureComponent} from 'react'
|
import React, {PureComponent} from 'react'
|
||||||
import WizardOverlay from 'src/reusable_ui/components/wizard/WizardOverlay'
|
|
||||||
import WizardStep from 'src/reusable_ui/components/wizard/WizardStep'
|
|
||||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
|
|
||||||
|
import WizardOverlay from 'src/reusable_ui/components/wizard/WizardOverlay'
|
||||||
|
import WizardStep from 'src/reusable_ui/components/wizard/WizardStep'
|
||||||
|
import SourceStep from 'src/sources/components/SourceStep'
|
||||||
|
import {DEFAULT_SOURCE} from 'src/shared/constants'
|
||||||
|
import {Source} from 'src/types'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isVisible: boolean
|
isVisible: boolean
|
||||||
|
@ -11,6 +14,7 @@ interface Props {
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
completion: object
|
completion: object
|
||||||
|
source: Partial<Source>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ErrorHandling
|
@ErrorHandling
|
||||||
|
@ -19,10 +23,13 @@ class ConnectionWizard extends PureComponent<Props, State> {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
completion: [false, false, false],
|
completion: [false, false, false],
|
||||||
|
source: DEFAULT_SOURCE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public render() {
|
public render() {
|
||||||
const {isVisible, toggleVisibility} = this.props
|
const {isVisible, toggleVisibility} = this.props
|
||||||
|
const {source} = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WizardOverlay
|
<WizardOverlay
|
||||||
visible={isVisible}
|
visible={isVisible}
|
||||||
|
@ -35,12 +42,14 @@ class ConnectionWizard extends PureComponent<Props, State> {
|
||||||
title="Add a New InfluxDB Connection"
|
title="Add a New InfluxDB Connection"
|
||||||
tipText=""
|
tipText=""
|
||||||
isComplete={this.isSourceComplete}
|
isComplete={this.isSourceComplete}
|
||||||
onNext={this.handleFirstNext}
|
onNext={this.handleSourceNext}
|
||||||
onPrevious={this.handleFirstPrev}
|
nextLabel="Create Source"
|
||||||
nextLabel="Continue"
|
|
||||||
previousLabel="Cancel"
|
previousLabel="Cancel"
|
||||||
>
|
>
|
||||||
first children
|
<SourceStep
|
||||||
|
isComplete={this.isSourceComplete}
|
||||||
|
ref={c => (this.sourceStepRef = c && c.getWrappedInstance())}
|
||||||
|
/>
|
||||||
</WizardStep>
|
</WizardStep>
|
||||||
<WizardStep
|
<WizardStep
|
||||||
title="Add a Kapacitor Connection"
|
title="Add a Kapacitor Connection"
|
||||||
|
@ -62,47 +71,47 @@ class ConnectionWizard extends PureComponent<Props, State> {
|
||||||
nextLabel="Complete Connection"
|
nextLabel="Complete Connection"
|
||||||
previousLabel="Go Back"
|
previousLabel="Go Back"
|
||||||
>
|
>
|
||||||
some third children
|
Dashboards boxes here
|
||||||
</WizardStep>
|
</WizardStep>
|
||||||
</WizardOverlay>
|
</WizardOverlay>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
private handleSourceNext = () => {
|
||||||
|
this.sourceStepRef.next()
|
||||||
|
}
|
||||||
|
|
||||||
private isSourceComplete = () => {
|
private isSourceComplete = () => {
|
||||||
const {completion} = this.state
|
const {completion} = this.state
|
||||||
return completion[0]
|
return completion[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
private isKapacitorComplete = () => {
|
private isKapacitorComplete = () => {
|
||||||
const {completion} = this.state
|
const {completion} = this.state
|
||||||
return completion[1]
|
return completion[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
private isDashboardSelectionComplete = () => {
|
private isDashboardSelectionComplete = () => {
|
||||||
const {completion} = this.state
|
const {completion} = this.state
|
||||||
return completion[2]
|
return completion[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private handleFirstNext = () => {
|
private handleFirstNext = () => {
|
||||||
const {completion} = this.state
|
const {completion} = this.state
|
||||||
completion[0] = true
|
completion[0] = true
|
||||||
this.setState({
|
this.setState({
|
||||||
completion
|
completion,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
private handleSecondNext = () => {
|
private handleSecondNext = () => {
|
||||||
const {completion} = this.state
|
const {completion} = this.state
|
||||||
completion[1] = true
|
completion[1] = true
|
||||||
this.setState({
|
this.setState({
|
||||||
completion
|
completion,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
private handleThirdNext = () => {
|
private handleThirdNext = () => {
|
||||||
const {completion} = this.state
|
const {completion} = this.state
|
||||||
completion[2] = true
|
completion[2] = true
|
||||||
this.setState({
|
this.setState({
|
||||||
completion
|
completion,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<Props, State> {
|
||||||
|
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 (
|
||||||
|
<>
|
||||||
|
<WizardTextInput
|
||||||
|
value={source.url}
|
||||||
|
label="Connection URL"
|
||||||
|
onChange={this.onChangeInput('url')}
|
||||||
|
/>
|
||||||
|
<WizardTextInput
|
||||||
|
value={source.name}
|
||||||
|
label="Connection Name"
|
||||||
|
onChange={this.onChangeInput('name')}
|
||||||
|
/>
|
||||||
|
<WizardTextInput
|
||||||
|
value={source.username}
|
||||||
|
label="Username"
|
||||||
|
onChange={this.onChangeInput('username')}
|
||||||
|
/>
|
||||||
|
<WizardTextInput
|
||||||
|
value={source.password}
|
||||||
|
label="Password"
|
||||||
|
onChange={this.onChangeInput('password')}
|
||||||
|
/>
|
||||||
|
<WizardTextInput
|
||||||
|
value={source.telegraf}
|
||||||
|
label="Telegraf Database Name"
|
||||||
|
onChange={this.onChangeInput('telegraf')}
|
||||||
|
/>
|
||||||
|
<WizardTextInput
|
||||||
|
value={source.defaultRP}
|
||||||
|
label="Default Retention Policy"
|
||||||
|
onChange={this.onChangeInput('defaultRP')}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in New Issue