Add ability to create new slack node

pull/10616/head
Iris Scholten 2018-05-09 10:53:48 -07:00
parent 9665f420b1
commit e2c24f3dff
3 changed files with 28 additions and 23 deletions

View File

@ -233,7 +233,7 @@ class AlertTabs extends PureComponent<Props, State> {
renderComponent: () => ( renderComponent: () => (
<KafkaConfig <KafkaConfig
onSave={this.handleSaveConfig('kafka')} onSave={this.handleSaveConfig('kafka')}
config={this.getSection(configSections, 'kafka')} config={this.getSectionElement(configSections, 'kafka')}
onTest={this.handleTestConfig('kafka', { onTest={this.handleTestConfig('kafka', {
cluster: this.getProperty(configSections, 'kafka', 'id'), cluster: this.getProperty(configSections, 'kafka', 'id'),
})} })}
@ -327,18 +327,6 @@ class AlertTabs extends PureComponent<Props, State> {
/> />
), ),
}, },
// slack: {
// type: 'Slack',
// enabled: this.getEnabled(configSections, 'slack'),
// renderComponent: () => (
// <SlackConfig
// onSave={this.handleSaveConfig('slack')}
// config={this.getSectionElement(configSections, 'slack')}
// onTest={this.handleTestConfig('slack')}
// enabled={this.getEnabled(configSections, 'slack')}
// />
// ),
// },
smtp: { smtp: {
type: 'SMTP', type: 'SMTP',
enabled: this.getEnabled(configSections, 'smtp'), enabled: this.getEnabled(configSections, 'smtp'),
@ -491,16 +479,25 @@ class AlertTabs extends PureComponent<Props, State> {
} }
private handleSaveConfig = (section: string) => async ( private handleSaveConfig = (section: string) => async (
properties properties,
isNewConfigInSection?: boolean
): Promise<boolean> => { ): Promise<boolean> => {
if (section !== '') { if (section !== '') {
const propsToSend = this.sanitizeProperties(section, properties) const propsToSend = this.sanitizeProperties(section, properties)
try { try {
await updateKapacitorConfigSection( if (isNewConfigInSection) {
this.props.kapacitor, await addKapacitorConfigInSection(
section, this.props.kapacitor,
propsToSend section,
) propsToSend
)
} else {
await updateKapacitorConfigSection(
this.props.kapacitor,
section,
propsToSend
)
}
this.refreshKapacitorConfig(this.props.kapacitor) this.refreshKapacitorConfig(this.props.kapacitor)
this.props.notify(notifyAlertEndpointSaved(section)) this.props.notify(notifyAlertEndpointSaved(section))
return true return true

View File

@ -19,9 +19,10 @@ interface Config {
interface Props { interface Props {
config: Config config: Config
onSave: (properties: Properties) => void onSave: (properties: Properties, isNewConfigInSection: boolean) => void
onTest: (event: React.MouseEvent<HTMLButtonElement>) => void onTest: (event: React.MouseEvent<HTMLButtonElement>) => void
enabled: boolean enabled: boolean
isNewConfig: boolean
} }
interface State { interface State {
@ -33,6 +34,7 @@ interface State {
class SlackConfig extends PureComponent<Props, State> { class SlackConfig extends PureComponent<Props, State> {
private url: HTMLInputElement private url: HTMLInputElement
private channel: HTMLInputElement private channel: HTMLInputElement
private workspace: HTMLInputElement
constructor(props) { constructor(props) {
super(props) super(props)
@ -55,7 +57,7 @@ class SlackConfig extends PureComponent<Props, State> {
id="nickname" id="nickname"
type="text" type="text"
placeholder="Optional unless multiple Slack configurations exist" placeholder="Optional unless multiple Slack configurations exist"
// ref={r => (this.channel = r)} ref={r => (this.workspace = r)}
defaultValue={workspace} defaultValue={workspace}
onChange={this.disableTest} onChange={this.disableTest}
/> />
@ -132,13 +134,15 @@ class SlackConfig extends PureComponent<Props, State> {
} }
private handleSubmit = async e => { private handleSubmit = async e => {
const {isNewConfig} = this.props
e.preventDefault() e.preventDefault()
const properties = { const properties = {
url: this.url.value, url: this.url.value,
channel: this.channel.value, channel: this.channel.value,
enabled: this.state.enabled, enabled: this.state.enabled,
workspace: this.workspace.value,
} }
const success = await this.props.onSave(properties) const success = await this.props.onSave(properties, isNewConfig)
if (success) { if (success) {
this.setState({testEnabled: true}) this.setState({testEnabled: true})
} }

View File

@ -1,4 +1,6 @@
import React, {PureComponent} from 'react' import React, {PureComponent} from 'react'
import _ from 'lodash'
import {ErrorHandling} from 'src/shared/decorators/errors' import {ErrorHandling} from 'src/shared/decorators/errors'
import SlackConfig from 'src/kapacitor/components/config/SlackConfig' import SlackConfig from 'src/kapacitor/components/config/SlackConfig'
@ -17,7 +19,7 @@ interface Config {
interface Props { interface Props {
slackConfigs: any[] slackConfigs: any[]
config: Config config: Config
onSave: (properties: Properties) => void onSave: (properties: Properties, isNewConfigInSection: boolean) => void
onTest: (event: React.MouseEvent<HTMLButtonElement>) => void onTest: (event: React.MouseEvent<HTMLButtonElement>) => void
enabled: boolean enabled: boolean
} }
@ -47,6 +49,7 @@ class SlackConfigs extends PureComponent<Props, State> {
config={config} config={config}
onTest={onTest} onTest={onTest}
enabled={enabled} enabled={enabled}
isNewConfig={_.get(config, 'isNewConfig', false)}
/> />
))} ))}
<button className="btn btn-md btn-default" onClick={this.addConfig}> <button className="btn btn-md btn-default" onClick={this.addConfig}>
@ -67,6 +70,7 @@ class SlackConfigs extends PureComponent<Props, State> {
url: false, url: false,
channel: '', channel: '',
}, },
isNewConfig: true,
} }
this.setState({slackConfigs: [...configs, newConfig]}) this.setState({slackConfigs: [...configs, newConfig]})
} }