From ea3ddda63bb1e0bc0cbcfcd8ba47870ef2b67fd4 Mon Sep 17 00:00:00 2001 From: Iris Scholten Date: Thu, 17 May 2018 17:00:46 -0700 Subject: [PATCH] Handle enabled for KafkaConfig Co-authored-by: Brandon Farmer --- ui/src/kapacitor/components/AlertTabs.tsx | 36 +++--- .../components/config/KafkaConfig.tsx | 24 +++- .../components/config/KafkaConfigs.tsx | 120 ++++++++++++++++++ ui/src/types/kapacitor.ts | 1 + 4 files changed, 163 insertions(+), 18 deletions(-) create mode 100644 ui/src/kapacitor/components/config/KafkaConfigs.tsx diff --git a/ui/src/kapacitor/components/AlertTabs.tsx b/ui/src/kapacitor/components/AlertTabs.tsx index 26a6f885f3..01635e1bf6 100644 --- a/ui/src/kapacitor/components/AlertTabs.tsx +++ b/ui/src/kapacitor/components/AlertTabs.tsx @@ -271,7 +271,7 @@ class AlertTabs extends PureComponent { AlertTypes.kafka )} notify={this.props.notify} - isMultipleConfigsSupported={true} + isMultipleConfigsSupported={this.isMultipleConfigsSupported} onDelete={this.handleDeleteConfig(AlertTypes.kafka)} /> ) @@ -349,19 +349,6 @@ class AlertTabs extends PureComponent { /> ) case AlertTypes.slack: - const hasPagerDuty2: Section = get( - configSections, - AlertTypes.pagerduty2, - undefined - ) - const hasOpsGenie2: Section = get( - configSections, - AlertTypes.opsgenie2, - undefined - ) - // if kapacitor supports pagerduty2 and opsgenie2, its at least v1.5 - const isMultipleConfigsSupported: boolean = - !_.isUndefined(hasPagerDuty2) && !_.isUndefined(hasOpsGenie2) return ( { configSections, AlertTypes.slack )} - isMultipleConfigsSupported={isMultipleConfigsSupported} + isMultipleConfigsSupported={this.isMultipleConfigsSupported} /> ) @@ -442,6 +429,23 @@ class AlertTabs extends PureComponent { return _.get(sections, [section, 'elements', '0'], null) } + private get isMultipleConfigsSupported(): boolean { + const {configSections} = this.state + const hasPagerDuty2: Section = get( + configSections, + AlertTypes.pagerduty2, + undefined + ) + const hasOpsGenie2: Section = get( + configSections, + AlertTypes.opsgenie2, + undefined + ) + // if kapacitor supports pagerduty2 and opsgenie2, its at least v1.5 + return + !_.isUndefined(hasPagerDuty2) && !_.isUndefined(hasOpsGenie2) + } + private getSectionElements = ( sections: Sections, section: string @@ -450,7 +454,7 @@ class AlertTabs extends PureComponent { } private getConfigEnabled = (sections: Sections, section: string): boolean => { - if (section === AlertTypes.slack) { + if (section === AlertTypes.slack || section === AlertTypes.kafka) { const configElements: Section[] = get(sections, `${section}.elements`, []) const enabledConfigElements = configElements.filter(e => { const enabled: boolean = get(e, 'options.enabled', false) diff --git a/ui/src/kapacitor/components/config/KafkaConfig.tsx b/ui/src/kapacitor/components/config/KafkaConfig.tsx index 9de77058a8..5d481dffdf 100644 --- a/ui/src/kapacitor/components/config/KafkaConfig.tsx +++ b/ui/src/kapacitor/components/config/KafkaConfig.tsx @@ -1,4 +1,4 @@ -import React, {PureComponent, MouseEvent} from 'react' +import React, {PureComponent, MouseEvent, ChangeEvent} from 'react' import TagInput from 'src/shared/components/TagInput' import {ErrorHandling} from 'src/shared/decorators/errors' @@ -32,13 +32,14 @@ interface Props { ) => void enabled: boolean notify: (message: Notification | NotificationFunc) => void - id: number + id: string onDelete: (specificConfig: string) => void } interface State { currentBrokers: string[] testEnabled: boolean + enabled: boolean } @ErrorHandling @@ -61,6 +62,7 @@ class KafkaConfig extends PureComponent { this.state = { currentBrokers: brokers || [], testEnabled: this.props.enabled, + enabled: get(this.props, 'config.options.enabled', false), } } @@ -76,6 +78,7 @@ class KafkaConfig extends PureComponent { const sslCert = options['ssl-cert'] const sslKey = options['ssl-key'] const insecureSkipVerify = options['insecure-skip-verify'] + const {enabled} = this.state return (
@@ -191,6 +194,17 @@ class KafkaConfig extends PureComponent { +
+
+ + +
+
+
+ )} + + ) + } + private get configs(): Config[] { + return _.sortBy(this.state.configs, c => { + const id = get(c, 'options.id', '') + const {isNewConfig} = c + if (id === 'default') { + return '' + } + if (isNewConfig) { + return Infinity + } + return id + }) + } + + private get isAddingConfigsAllowed() { + const {isMultipleConfigsSupported} = this.props + const isAllConfigsPersisted = _.every(this.configs, c => !c.isNewConfig) + return isMultipleConfigsSupported && isAllConfigsPersisted + } + + private handleAddConfig = (): void => { + const {configs} = this.state + const newConfig: Config = { + options: { + id: '', + brokers: [], + timeout: '', + 'batch-size': 0, + 'batch-timeout': '', + 'use-ssl': false, + 'ssl-ca': '', + 'ssl-cert': '', + 'ssl-key': '', + 'insecure-skip-verify': false, + enabled: false, + }, + isNewConfig: true, + } + const updatedConfigs = [...configs, newConfig] + this.setState({configs: updatedConfigs}) + } +} + +export default KafkaConfigs diff --git a/ui/src/types/kapacitor.ts b/ui/src/types/kapacitor.ts index 8aa0067015..218a158827 100644 --- a/ui/src/types/kapacitor.ts +++ b/ui/src/types/kapacitor.ts @@ -315,6 +315,7 @@ export interface KafkaProperties { 'ssl-cert': string 'ssl-key': string 'insecure-skip-verify': boolean + enabled: boolean } export interface OpsGenieProperties {