Convert KapacitorRulesTable to working TypeScript

pull/3006/head
Jared Scheib 2018-03-16 19:23:28 -07:00
parent 07ba4e7590
commit 01931957ab
1 changed files with 66 additions and 56 deletions

View File

@ -1,8 +1,9 @@
import React from 'react' import React, {PureComponent, SFC, MouseEvent} from 'react'
import PropTypes from 'prop-types'
import {Link} from 'react-router' import {Link} from 'react-router'
import _ from 'lodash' import _ from 'lodash'
import {AlertRule, Source} from 'src/types'
import ConfirmButton from 'src/shared/components/ConfirmButton' import ConfirmButton from 'src/shared/components/ConfirmButton'
import {parseAlertNodeList} from 'src/shared/parsing/parseHandlersFromRule' import {parseAlertNodeList} from 'src/shared/parsing/parseHandlersFromRule'
import {TASKS_TABLE} from 'src/kapacitor/constants/tableSizing' import {TASKS_TABLE} from 'src/kapacitor/constants/tableSizing'
@ -15,7 +16,26 @@ const {
colActions, colActions,
} = TASKS_TABLE } = TASKS_TABLE
const KapacitorRulesTable = ({rules, source, onDelete, onChangeRuleStatus}) => interface KapacitorRulesTableProps {
rules: AlertRule[]
source: Source
onChangeRuleStatus: (rule: AlertRule) => void
onDelete: (rule: AlertRule) => void
}
interface RuleRowProps {
rule: AlertRule
source: Source
onChangeRuleStatus: (rule: AlertRule) => void
onDelete: (rule: AlertRule) => void
}
const KapacitorRulesTable: SFC<KapacitorRulesTableProps> = ({
rules,
source,
onChangeRuleStatus,
onDelete,
}) => (
<table className="table v-center table-highlight"> <table className="table v-center table-highlight">
<thead> <thead>
<tr> <tr>
@ -43,64 +63,54 @@ const KapacitorRulesTable = ({rules, source, onDelete, onChangeRuleStatus}) =>
})} })}
</tbody> </tbody>
</table> </table>
)
const handleDelete = (rule, onDelete) => onDelete(rule) const handleDelete = (rule, onDelete) => onDelete(rule)
const RuleRow = ({rule, source, onDelete, onChangeRuleStatus}) => class RuleRow extends PureComponent<RuleRowProps> {
<tr key={rule.id}> handleClickRuleStatusEnabled(_: MouseEvent<HTMLInputElement>) {
<td style={{minWidth: colName}}> return (rule: AlertRule) => this.props.onChangeRuleStatus(rule)
<Link to={`/sources/${source.id}/alert-rules/${rule.id}`}> }
{rule.name}
</Link>
</td>
<td style={{width: colTrigger, textTransform: 'capitalize'}}>
{rule.trigger}
</td>
<td style={{width: colMessage}}>
{rule.message}
</td>
<td style={{width: colAlerts}}>
{parseAlertNodeList(rule)}
</td>
<td style={{width: colEnabled}} className="text-center">
<div className="dark-checkbox">
<input
id={`kapacitor-rule-row-task-enabled ${rule.id}`}
className="form-control-static"
type="checkbox"
defaultChecked={rule.status === 'enabled'}
onClick={onChangeRuleStatus(rule)}
/>
<label htmlFor={`kapacitor-rule-row-task-enabled ${rule.id}`} />
</div>
</td>
<td style={{width: colActions}} className="text-right">
<ConfirmButton
text="Delete"
type="btn-danger"
size="btn-xs"
customClass="table--show-on-row-hover"
confirmAction={handleDelete(rule, onDelete)}
/>
</td>
</tr>
const {arrayOf, func, shape, string} = PropTypes render() {
const {rule, source, onDelete} = this.props
KapacitorRulesTable.propTypes = { return (
rules: arrayOf(shape()), <tr key={rule.id}>
onChangeRuleStatus: func, <td style={{minWidth: colName}}>
onDelete: func, <Link to={`/sources/${source.id}/alert-rules/${rule.id}`}>
source: shape({ {rule.name}
id: string.isRequired, </Link>
}).isRequired, </td>
} <td style={{width: colTrigger, textTransform: 'capitalize'}}>
{rule.trigger}
RuleRow.propTypes = { </td>
rule: shape(), <td style={{width: colMessage}}>{rule.message}</td>
source: shape(), <td style={{width: colAlerts}}>{parseAlertNodeList(rule)}</td>
onChangeRuleStatus: func, <td style={{width: colEnabled}} className="text-center">
onDelete: func, <div className="dark-checkbox">
<input
id={`kapacitor-rule-row-task-enabled ${rule.id}`}
className="form-control-static"
type="checkbox"
defaultChecked={rule.status === 'enabled'}
onClick={this.handleClickRuleStatusEnabled}
/>
<label htmlFor={`kapacitor-rule-row-task-enabled ${rule.id}`} />
</div>
</td>
<td style={{width: colActions}} className="text-right">
<ConfirmButton
text="Delete"
type="btn-danger"
size="btn-xs"
customClass="table--show-on-row-hover"
confirmAction={handleDelete(rule, onDelete)}
/>
</td>
</tr>
)
}
} }
export default KapacitorRulesTable export default KapacitorRulesTable