Convert KapacitorPage to TypeScript
parent
49b9d44e5a
commit
c11b2fdd6c
|
@ -1,18 +1,48 @@
|
||||||
import React, {Component, PropTypes} from 'react'
|
import React, {PureComponent} from 'react'
|
||||||
import {withRouter} from 'react-router'
|
import {withRouter} from 'react-router'
|
||||||
|
|
||||||
|
import {Source} from 'src/types'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getKapacitor,
|
getKapacitor,
|
||||||
createKapacitor,
|
createKapacitor,
|
||||||
updateKapacitor,
|
updateKapacitor,
|
||||||
pingKapacitor,
|
pingKapacitor,
|
||||||
} from 'shared/apis'
|
} from 'src/shared/apis'
|
||||||
|
|
||||||
import KapacitorForm from '../components/KapacitorForm'
|
import KapacitorForm from '../components/KapacitorForm'
|
||||||
|
|
||||||
const defaultName = 'My Kapacitor'
|
const defaultName = 'My Kapacitor'
|
||||||
const kapacitorPort = '9092'
|
const kapacitorPort = '9092'
|
||||||
|
|
||||||
class KapacitorPage extends Component {
|
type FlashMessage = {type: string; text: string}
|
||||||
|
|
||||||
|
interface Kapacitor {
|
||||||
|
url: string
|
||||||
|
name: string
|
||||||
|
username: string
|
||||||
|
password: string
|
||||||
|
active: boolean
|
||||||
|
links: {
|
||||||
|
self: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
source: Source
|
||||||
|
addFlashMessage: (message: FlashMessage) => void
|
||||||
|
kapacitor: Kapacitor
|
||||||
|
router: {push: (url: string) => void}
|
||||||
|
location: {pathname: string; hash: string}
|
||||||
|
params: {id: string; hash: string}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
kapacitor: Kapacitor
|
||||||
|
exists: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
class KapacitorPage extends PureComponent<Props, State> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -21,6 +51,10 @@ class KapacitorPage extends Component {
|
||||||
name: defaultName,
|
name: defaultName,
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
|
active: false,
|
||||||
|
links: {
|
||||||
|
self: '',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
exists: false,
|
exists: false,
|
||||||
}
|
}
|
||||||
|
@ -127,6 +161,10 @@ class KapacitorPage extends Component {
|
||||||
name: defaultName,
|
name: defaultName,
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
|
active: false,
|
||||||
|
links: {
|
||||||
|
self: '',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({kapacitor: {...defaultState}})
|
this.setState({kapacitor: {...defaultState}})
|
||||||
|
@ -143,38 +181,21 @@ class KapacitorPage extends Component {
|
||||||
const {source, addFlashMessage, location, params} = this.props
|
const {source, addFlashMessage, location, params} = this.props
|
||||||
const hash = (location && location.hash) || (params && params.hash) || ''
|
const hash = (location && location.hash) || (params && params.hash) || ''
|
||||||
const {kapacitor, exists} = this.state
|
const {kapacitor, exists} = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KapacitorForm
|
<KapacitorForm
|
||||||
|
hash={hash}
|
||||||
|
source={source}
|
||||||
|
exists={exists}
|
||||||
|
kapacitor={kapacitor}
|
||||||
onSubmit={this.handleSubmit}
|
onSubmit={this.handleSubmit}
|
||||||
onInputChange={this.handleInputChange}
|
addFlashMessage={addFlashMessage}
|
||||||
onChangeUrl={this.handleChangeUrl}
|
onChangeUrl={this.handleChangeUrl}
|
||||||
onReset={this.handleResetToDefaults}
|
onReset={this.handleResetToDefaults}
|
||||||
kapacitor={kapacitor}
|
onInputChange={this.handleInputChange}
|
||||||
source={source}
|
|
||||||
addFlashMessage={addFlashMessage}
|
|
||||||
exists={exists}
|
|
||||||
hash={hash}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {array, func, shape, string} = PropTypes
|
|
||||||
|
|
||||||
KapacitorPage.propTypes = {
|
|
||||||
addFlashMessage: func,
|
|
||||||
params: shape({
|
|
||||||
id: string,
|
|
||||||
}).isRequired,
|
|
||||||
router: shape({
|
|
||||||
push: func.isRequired,
|
|
||||||
}).isRequired,
|
|
||||||
source: shape({
|
|
||||||
id: string.isRequired,
|
|
||||||
url: string.isRequired,
|
|
||||||
kapacitors: array,
|
|
||||||
}),
|
|
||||||
location: shape({pathname: string, hash: string}).isRequired,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default withRouter(KapacitorPage)
|
export default withRouter(KapacitorPage)
|
|
@ -1,4 +1,4 @@
|
||||||
import {Query} from './query'
|
import {Query} from './query'
|
||||||
import {Source} from './sources'
|
import {Source, Kapacitor} from './sources'
|
||||||
|
|
||||||
export {Query, Source}
|
export {Query, Source, Kapacitor}
|
||||||
|
|
Loading…
Reference in New Issue