diff --git a/ui/src/kapacitor/components/AlertTabs.tsx b/ui/src/kapacitor/components/AlertTabs.tsx index 9b22be822d..1fe8569fc8 100644 --- a/ui/src/kapacitor/components/AlertTabs.tsx +++ b/ui/src/kapacitor/components/AlertTabs.tsx @@ -233,7 +233,7 @@ class AlertTabs extends PureComponent { renderComponent: () => ( { /> ), }, - // slack: { - // type: 'Slack', - // enabled: this.getEnabled(configSections, 'slack'), - // renderComponent: () => ( - // - // ), - // }, smtp: { type: 'SMTP', enabled: this.getEnabled(configSections, 'smtp'), @@ -491,16 +479,25 @@ class AlertTabs extends PureComponent { } private handleSaveConfig = (section: string) => async ( - properties + properties, + isNewConfigInSection?: boolean ): Promise => { if (section !== '') { const propsToSend = this.sanitizeProperties(section, properties) try { - await updateKapacitorConfigSection( - this.props.kapacitor, - section, - propsToSend - ) + if (isNewConfigInSection) { + await addKapacitorConfigInSection( + this.props.kapacitor, + section, + propsToSend + ) + } else { + await updateKapacitorConfigSection( + this.props.kapacitor, + section, + propsToSend + ) + } this.refreshKapacitorConfig(this.props.kapacitor) this.props.notify(notifyAlertEndpointSaved(section)) return true diff --git a/ui/src/kapacitor/components/config/SlackConfig.tsx b/ui/src/kapacitor/components/config/SlackConfig.tsx index efc6064dcb..439865b1cb 100644 --- a/ui/src/kapacitor/components/config/SlackConfig.tsx +++ b/ui/src/kapacitor/components/config/SlackConfig.tsx @@ -19,9 +19,10 @@ interface Config { interface Props { config: Config - onSave: (properties: Properties) => void + onSave: (properties: Properties, isNewConfigInSection: boolean) => void onTest: (event: React.MouseEvent) => void enabled: boolean + isNewConfig: boolean } interface State { @@ -33,6 +34,7 @@ interface State { class SlackConfig extends PureComponent { private url: HTMLInputElement private channel: HTMLInputElement + private workspace: HTMLInputElement constructor(props) { super(props) @@ -55,7 +57,7 @@ class SlackConfig extends PureComponent { id="nickname" type="text" placeholder="Optional unless multiple Slack configurations exist" - // ref={r => (this.channel = r)} + ref={r => (this.workspace = r)} defaultValue={workspace} onChange={this.disableTest} /> @@ -132,13 +134,15 @@ class SlackConfig extends PureComponent { } private handleSubmit = async e => { + const {isNewConfig} = this.props e.preventDefault() const properties = { url: this.url.value, channel: this.channel.value, 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) { this.setState({testEnabled: true}) } diff --git a/ui/src/kapacitor/components/config/SlackConfigs.tsx b/ui/src/kapacitor/components/config/SlackConfigs.tsx index 973b25b3e8..ddea3e5bf5 100644 --- a/ui/src/kapacitor/components/config/SlackConfigs.tsx +++ b/ui/src/kapacitor/components/config/SlackConfigs.tsx @@ -1,4 +1,6 @@ import React, {PureComponent} from 'react' +import _ from 'lodash' + import {ErrorHandling} from 'src/shared/decorators/errors' import SlackConfig from 'src/kapacitor/components/config/SlackConfig' @@ -17,7 +19,7 @@ interface Config { interface Props { slackConfigs: any[] config: Config - onSave: (properties: Properties) => void + onSave: (properties: Properties, isNewConfigInSection: boolean) => void onTest: (event: React.MouseEvent) => void enabled: boolean } @@ -47,6 +49,7 @@ class SlackConfigs extends PureComponent { config={config} onTest={onTest} enabled={enabled} + isNewConfig={_.get(config, 'isNewConfig', false)} /> ))}