-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce skeleton to create task through proxy
- Loading branch information
Showing
5 changed files
with
145 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
import React, {Component} from 'react' | ||
import React, {PropTypes, Component} from 'react' | ||
import CodeMirror from 'react-codemirror' | ||
import 'src/external/codemirror' | ||
|
||
class TickscriptEditor extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
code: '', | ||
} | ||
} | ||
|
||
updateCode(code) { | ||
this.setState({code}) | ||
updateCode(script) { | ||
this.props.onChangeScript(script) | ||
} | ||
|
||
render() { | ||
const {code} = this.state | ||
const {script} = this.props | ||
|
||
const options = { | ||
lineNumbers: true, | ||
theme: 'material', | ||
} | ||
|
||
return ( | ||
<CodeMirror value={code} onChange={::this.updateCode} options={options} /> | ||
<CodeMirror | ||
value={script} | ||
onChange={::this.updateCode} | ||
options={options} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
const {func, string} = PropTypes | ||
|
||
TickscriptEditor.propTypes = { | ||
onChangeScript: func, | ||
script: string, | ||
} | ||
|
||
export default TickscriptEditor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,98 @@ | ||
import React, {PropTypes, Component} from 'react' | ||
import {connect} from 'react-redux' | ||
import {bindActionCreators} from 'redux' | ||
|
||
import Tickscript from 'src/kapacitor/components/Tickscript' | ||
import * as kapactiorActionCreators from 'src/kapacitor/actions/view' | ||
import {getActiveKapacitor} from 'src/shared/apis' | ||
import {errorThrown as errorAction} from 'shared/actions/errors' | ||
|
||
class TickscriptPage extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
kapacitor: {}, | ||
task: { | ||
id: 'testing', | ||
status: 'enabled', | ||
script: '', | ||
dbsrps: [ | ||
{ | ||
db: '_internal', | ||
rp: 'monitor', | ||
}, | ||
], | ||
type: 'stream', | ||
}, | ||
validation: '', | ||
} | ||
} | ||
|
||
handleSave() { | ||
console.log('save me!') // eslint-disable-line no-console | ||
async componentDidMount() { | ||
const {source, errorThrown} = this.props | ||
const kapacitor = await getActiveKapacitor(source) | ||
|
||
if (!kapacitor) { | ||
errorThrown('We could not find a configured Kapacitor for this source') | ||
} | ||
|
||
this.setState({kapacitor}) | ||
} | ||
|
||
async handleSave() { | ||
const {kapacitor, task} = this.state | ||
const {source, router, kapactiorActions: {createTask}} = this.props | ||
|
||
const response = await createTask(kapacitor, task) | ||
if (response && response.error) { | ||
return this.setState({validation: response.error}) | ||
} | ||
|
||
router.push(`/sources/${source.id}/alert-rules`) | ||
} | ||
|
||
handleChangeScript(script) { | ||
this.setState({task: {...this.state.task, script}}) | ||
} | ||
|
||
render() { | ||
const {source} = this.props | ||
const {task, validation} = this.state | ||
|
||
return <Tickscript onSave={this.handleSave} source={source} /> | ||
return ( | ||
<Tickscript | ||
task={task} | ||
source={source} | ||
onSave={::this.handleSave} | ||
onChangeScript={::this.handleChangeScript} | ||
validation={validation} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
const {shape, string} = PropTypes | ||
const {func, shape, string} = PropTypes | ||
|
||
TickscriptPage.propTypes = { | ||
source: shape({ | ||
name: string, | ||
}), | ||
errorThrown: func.isRequired, | ||
kapactiorActions: shape({ | ||
createTask: func.isRequired, | ||
}), | ||
router: shape({ | ||
push: func.isRequired, | ||
}).isRequired, | ||
} | ||
|
||
export default TickscriptPage | ||
const mapStateToProps = () => { | ||
return {} | ||
} | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
errorThrown: bindActionCreators(errorAction, dispatch), | ||
kapactiorActions: bindActionCreators(kapactiorActionCreators, dispatch), | ||
}) | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(TickscriptPage) |