Display TICKscript on rules index
parent
879a16f9fb
commit
a8ac8bb9c6
|
@ -5,6 +5,7 @@ import NoKapacitorError from 'shared/components/NoKapacitorError'
|
||||||
import SourceIndicator from 'shared/components/SourceIndicator'
|
import SourceIndicator from 'shared/components/SourceIndicator'
|
||||||
import KapacitorRulesTable from 'src/kapacitor/components/KapacitorRulesTable'
|
import KapacitorRulesTable from 'src/kapacitor/components/KapacitorRulesTable'
|
||||||
import FancyScrollbar from 'shared/components/FancyScrollbar'
|
import FancyScrollbar from 'shared/components/FancyScrollbar'
|
||||||
|
import TICKscriptOverlay from 'src/kapacitor/components/TICKscriptOverlay'
|
||||||
|
|
||||||
const KapacitorRules = ({
|
const KapacitorRules = ({
|
||||||
source,
|
source,
|
||||||
|
@ -12,7 +13,10 @@ const KapacitorRules = ({
|
||||||
hasKapacitor,
|
hasKapacitor,
|
||||||
loading,
|
loading,
|
||||||
onDelete,
|
onDelete,
|
||||||
|
tickscript,
|
||||||
onChangeRuleStatus,
|
onChangeRuleStatus,
|
||||||
|
onReadTickscript,
|
||||||
|
onCloseTickscript,
|
||||||
}) => {
|
}) => {
|
||||||
if (!hasKapacitor) {
|
if (!hasKapacitor) {
|
||||||
return (
|
return (
|
||||||
|
@ -33,7 +37,12 @@ const KapacitorRules = ({
|
||||||
? '1 Alert Rule'
|
? '1 Alert Rule'
|
||||||
: `${rules.length} Alert Rules`
|
: `${rules.length} Alert Rules`
|
||||||
return (
|
return (
|
||||||
<PageContents source={source}>
|
<PageContents
|
||||||
|
source={source}
|
||||||
|
tickscript={tickscript}
|
||||||
|
onReadTickscript={onReadTickscript}
|
||||||
|
onCloseTickscript={onCloseTickscript}
|
||||||
|
>
|
||||||
<div className="panel-heading u-flex u-ai-center u-jc-space-between">
|
<div className="panel-heading u-flex u-ai-center u-jc-space-between">
|
||||||
<h2 className="panel-title">{tableHeader}</h2>
|
<h2 className="panel-title">{tableHeader}</h2>
|
||||||
<Link
|
<Link
|
||||||
|
@ -47,14 +56,15 @@ const KapacitorRules = ({
|
||||||
source={source}
|
source={source}
|
||||||
rules={rules}
|
rules={rules}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
|
onReadTickscript={onReadTickscript}
|
||||||
onChangeRuleStatus={onChangeRuleStatus}
|
onChangeRuleStatus={onChangeRuleStatus}
|
||||||
/>
|
/>
|
||||||
</PageContents>
|
</PageContents>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const PageContents = ({children, source}) =>
|
const PageContents = ({children, source, tickscript, onCloseTickscript}) => (
|
||||||
<div className="page">
|
<div>
|
||||||
<div className="page-header">
|
<div className="page-header">
|
||||||
<div className="page-header__container">
|
<div className="page-header__container">
|
||||||
<div className="page-header__left">
|
<div className="page-header__left">
|
||||||
|
@ -76,9 +86,16 @@ const PageContents = ({children, source}) =>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</FancyScrollbar>
|
</FancyScrollbar>
|
||||||
|
{tickscript
|
||||||
|
? <TICKscriptOverlay
|
||||||
|
tickscript={tickscript}
|
||||||
|
onClose={onCloseTickscript}
|
||||||
|
/>
|
||||||
|
: null}
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
const {arrayOf, bool, func, shape, node} = PropTypes
|
const {arrayOf, bool, func, node, shape, string} = PropTypes
|
||||||
|
|
||||||
KapacitorRules.propTypes = {
|
KapacitorRules.propTypes = {
|
||||||
source: shape(),
|
source: shape(),
|
||||||
|
@ -87,11 +104,16 @@ KapacitorRules.propTypes = {
|
||||||
loading: bool,
|
loading: bool,
|
||||||
onChangeRuleStatus: func,
|
onChangeRuleStatus: func,
|
||||||
onDelete: func,
|
onDelete: func,
|
||||||
|
tickscript: string,
|
||||||
|
onReadTickscript: func,
|
||||||
|
onCloseTickscript: func,
|
||||||
}
|
}
|
||||||
|
|
||||||
PageContents.propTypes = {
|
PageContents.propTypes = {
|
||||||
children: node,
|
children: node,
|
||||||
source: shape(),
|
source: shape(),
|
||||||
|
tickscript: string,
|
||||||
|
onCloseTickscript: func,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default KapacitorRules
|
export default KapacitorRules
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
import React, {PropTypes} from 'react'
|
import React, {PropTypes} from 'react'
|
||||||
import {Link} from 'react-router'
|
import {Link} from 'react-router'
|
||||||
|
|
||||||
const KapacitorRulesTable = ({rules, source, onDelete, onChangeRuleStatus}) =>
|
const KapacitorRulesTable = ({
|
||||||
|
rules,
|
||||||
|
source,
|
||||||
|
onDelete,
|
||||||
|
onReadTickscript,
|
||||||
|
onChangeRuleStatus,
|
||||||
|
}) => (
|
||||||
<div className="panel-body">
|
<div className="panel-body">
|
||||||
<table className="table v-center">
|
<table className="table v-center">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -23,14 +29,16 @@ const KapacitorRulesTable = ({rules, source, onDelete, onChangeRuleStatus}) =>
|
||||||
source={source}
|
source={source}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
onChangeRuleStatus={onChangeRuleStatus}
|
onChangeRuleStatus={onChangeRuleStatus}
|
||||||
|
onRead={onReadTickscript}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
const RuleRow = ({rule, source, onDelete, onChangeRuleStatus}) =>
|
const RuleRow = ({rule, source, onRead, onDelete, onChangeRuleStatus}) => (
|
||||||
<tr key={rule.id}>
|
<tr key={rule.id}>
|
||||||
<td className="monotype">
|
<td className="monotype">
|
||||||
<RuleTitle rule={rule} source={source} />
|
<RuleTitle rule={rule} source={source} />
|
||||||
|
@ -50,12 +58,16 @@ const RuleRow = ({rule, source, onDelete, onChangeRuleStatus}) =>
|
||||||
<label htmlFor={`kapacitor-enabled ${rule.id}`} />
|
<label htmlFor={`kapacitor-enabled ${rule.id}`} />
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="text-right">
|
<td className="text-right" style={{display: 'flex'}}>
|
||||||
|
<button className="btn btn-info btn-xs" onClick={() => onRead(rule)}>
|
||||||
|
View TICKscript
|
||||||
|
</button>
|
||||||
<button className="btn btn-danger btn-xs" onClick={() => onDelete(rule)}>
|
<button className="btn btn-danger btn-xs" onClick={() => onDelete(rule)}>
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
)
|
||||||
|
|
||||||
const RuleTitle = ({rule: {id, name, query}, source}) => {
|
const RuleTitle = ({rule: {id, name, query}, source}) => {
|
||||||
// no queryConfig means the rule was manually created outside of Chronograf
|
// no queryConfig means the rule was manually created outside of Chronograf
|
||||||
|
@ -75,6 +87,7 @@ KapacitorRulesTable.propTypes = {
|
||||||
source: shape({
|
source: shape({
|
||||||
id: string.isRequired,
|
id: string.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
onReadTickscript: func,
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleRow.propTypes = {
|
RuleRow.propTypes = {
|
||||||
|
@ -82,6 +95,7 @@ RuleRow.propTypes = {
|
||||||
source: shape(),
|
source: shape(),
|
||||||
onChangeRuleStatus: func,
|
onChangeRuleStatus: func,
|
||||||
onDelete: func,
|
onDelete: func,
|
||||||
|
onRead: func,
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleTitle.propTypes = {
|
RuleTitle.propTypes = {
|
||||||
|
@ -90,7 +104,7 @@ RuleTitle.propTypes = {
|
||||||
query: shape(),
|
query: shape(),
|
||||||
links: shape({
|
links: shape({
|
||||||
self: string.isRequired,
|
self: string.isRequired,
|
||||||
}).isRequired,
|
}),
|
||||||
}),
|
}),
|
||||||
source: shape({
|
source: shape({
|
||||||
id: string.isRequired,
|
id: string.isRequired,
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
import React, {PropTypes} from 'react'
|
||||||
|
import OverlayTechnologies from 'shared/components/OverlayTechnologies'
|
||||||
|
|
||||||
|
const style = {
|
||||||
|
padding: '8px',
|
||||||
|
borderRadius: '4px',
|
||||||
|
backgroundColor: '#202028',
|
||||||
|
margin: '0 15%',
|
||||||
|
top: '16px',
|
||||||
|
position: 'relative',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
height: 'calc(100% - 76px)',
|
||||||
|
}
|
||||||
|
|
||||||
|
const TICKscriptOverlay = ({tickscript, onClose}) => (
|
||||||
|
<OverlayTechnologies>
|
||||||
|
<div style={style}>
|
||||||
|
<div style={{display: 'flex', justifyContent: 'space-around'}}>
|
||||||
|
<h2>Generated TICKscript</h2>
|
||||||
|
<span
|
||||||
|
style={{cursor: 'pointer'}}
|
||||||
|
className="icon remove"
|
||||||
|
onClick={onClose}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<pre
|
||||||
|
style={{
|
||||||
|
border: '1px solid white',
|
||||||
|
borderRadius: '4px',
|
||||||
|
overflow: 'auto',
|
||||||
|
whiteSpace: 'pre',
|
||||||
|
color: '#4ed8a0',
|
||||||
|
fontSize: '14px',
|
||||||
|
width: '95%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{tickscript}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
</OverlayTechnologies>
|
||||||
|
)
|
||||||
|
|
||||||
|
const {string, func} = PropTypes
|
||||||
|
|
||||||
|
TICKscriptOverlay.propTypes = {
|
||||||
|
tickscript: string,
|
||||||
|
onClose: func.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TICKscriptOverlay
|
|
@ -11,10 +11,13 @@ class KapacitorRulesPage extends Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
hasKapacitor: false,
|
hasKapacitor: false,
|
||||||
loading: true,
|
loading: true,
|
||||||
|
tickscript: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleDeleteRule = ::this.handleDeleteRule
|
this.handleDeleteRule = ::this.handleDeleteRule
|
||||||
this.handleRuleStatus = ::this.handleRuleStatus
|
this.handleRuleStatus = ::this.handleRuleStatus
|
||||||
|
this.handleReadTickscript = ::this.handleReadTickscript
|
||||||
|
this.handleCloseTickscript = ::this.handleCloseTickscript
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -39,19 +42,32 @@ class KapacitorRulesPage extends Component {
|
||||||
actions.updateRuleStatusSuccess(rule.id, status)
|
actions.updateRuleStatusSuccess(rule.id, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleReadTickscript({tickscript}) {
|
||||||
|
this.setState({tickscript})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleCloseTickscript() {
|
||||||
|
this.setState({tickscript: null})
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {source, rules} = this.props
|
const {source, rules} = this.props
|
||||||
const {hasKapacitor, loading} = this.state
|
const {hasKapacitor, loading, tickscript} = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KapacitorRules
|
<div>
|
||||||
source={source}
|
<KapacitorRules
|
||||||
rules={rules}
|
source={source}
|
||||||
hasKapacitor={hasKapacitor}
|
rules={rules}
|
||||||
loading={loading}
|
hasKapacitor={hasKapacitor}
|
||||||
onDelete={this.handleDeleteRule}
|
loading={loading}
|
||||||
onChangeRuleStatus={this.handleRuleStatus}
|
onDelete={this.handleDeleteRule}
|
||||||
/>
|
onChangeRuleStatus={this.handleRuleStatus}
|
||||||
|
onReadTickscript={this.handleReadTickscript}
|
||||||
|
tickscript={tickscript}
|
||||||
|
onCloseTickscript={this.handleCloseTickscript}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue