From 801cdc299252e8d4cce76eeacf3f7317a668c1fb Mon Sep 17 00:00:00 2001 From: Iris Scholten Date: Tue, 15 May 2018 14:56:11 -0700 Subject: [PATCH] Add additional options to override for testing slack config --- ui/src/kapacitor/components/AlertTabs.tsx | 6 +++--- ui/src/kapacitor/components/config/SlackConfig.tsx | 9 ++++++--- ui/src/kapacitor/components/config/SlackConfigs.tsx | 5 ++++- ui/src/shared/apis/index.js | 10 ++++++---- ui/src/types/kapacitor.ts | 2 ++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ui/src/kapacitor/components/AlertTabs.tsx b/ui/src/kapacitor/components/AlertTabs.tsx index b73dba300..df7af573c 100644 --- a/ui/src/kapacitor/components/AlertTabs.tsx +++ b/ui/src/kapacitor/components/AlertTabs.tsx @@ -48,7 +48,7 @@ import DeprecationWarning from 'src/admin/components/DeprecationWarning' import {ErrorHandling} from 'src/shared/decorators/errors' import {Source, Kapacitor} from 'src/types' -import {ServiceProperties} from 'src/types/kapacitor' +import {ServiceProperties, SpecificConfigOptions} from 'src/types/kapacitor' import SlackConfigs from 'src/kapacitor/components/config/SlackConfigs' import { AlertDisplayText, @@ -513,7 +513,7 @@ class AlertTabs extends PureComponent { private handleTestConfig = (section: string, options?: object) => async ( e: MouseEvent, - specificConfig?: string + specificConfigOptions?: SpecificConfigOptions ): Promise => { e.preventDefault() @@ -522,7 +522,7 @@ class AlertTabs extends PureComponent { this.props.kapacitor, section, options, - specificConfig + specificConfigOptions ) if (data.success) { this.props.notify(notifyTestAlertSent(section)) diff --git a/ui/src/kapacitor/components/config/SlackConfig.tsx b/ui/src/kapacitor/components/config/SlackConfig.tsx index 6a655daa7..d3508bac6 100644 --- a/ui/src/kapacitor/components/config/SlackConfig.tsx +++ b/ui/src/kapacitor/components/config/SlackConfig.tsx @@ -19,7 +19,10 @@ interface Props { isNewConfigInSection: boolean, specificConfig: string ) => void - onTest: (e: MouseEvent, specificConfig: string) => void + onTest: ( + e: MouseEvent, + specificConfigOptions: Partial + ) => void onDelete: (specificConfig: string, workspaceID: string) => void enabled: boolean isNewConfig: boolean @@ -168,10 +171,10 @@ class SlackConfig extends PureComponent { const { onTest, config: { - options: {workspace}, + options: {workspace, channel}, }, } = this.props - onTest(e, workspace) + onTest(e, {workspace, channel}) } private handleEnabledChange = (e: ChangeEvent) => { diff --git a/ui/src/kapacitor/components/config/SlackConfigs.tsx b/ui/src/kapacitor/components/config/SlackConfigs.tsx index 8924e4069..5659f89f5 100644 --- a/ui/src/kapacitor/components/config/SlackConfigs.tsx +++ b/ui/src/kapacitor/components/config/SlackConfigs.tsx @@ -21,7 +21,10 @@ interface Props { specificConfig: string ) => void onDelete: (specificConfig: string) => void - onTest: (e: MouseEvent, specificConfig: string) => void + onTest: ( + e: MouseEvent, + specificConfigOptions: Partial + ) => void onEnabled: (specificConfig: string) => boolean } diff --git a/ui/src/shared/apis/index.js b/ui/src/shared/apis/index.js index 676c25ff1..31663aff6 100644 --- a/ui/src/shared/apis/index.js +++ b/ui/src/shared/apis/index.js @@ -224,7 +224,7 @@ export const testAlertOutput = async ( kapacitor, outputName, options, - specificConfig + specificConfigOptions ) => { try { const { @@ -232,9 +232,11 @@ export const testAlertOutput = async ( } = await kapacitorProxy(kapacitor, 'GET', '/kapacitor/v1/service-tests') const service = services.find(s => s.name === outputName) - let body = options - if (outputName === AlertTypes.slack) { - body = {workspace: specificConfig} + let body = {} + if (options) { + body = options + } else if (outputName === AlertTypes.slack) { + body = specificConfigOptions } return kapacitorProxy(kapacitor, 'POST', service.link.href, body) diff --git a/ui/src/types/kapacitor.ts b/ui/src/types/kapacitor.ts index 1f3398d77..f92bd8e2c 100644 --- a/ui/src/types/kapacitor.ts +++ b/ui/src/types/kapacitor.ts @@ -401,3 +401,5 @@ export type ServiceProperties = | TalkProperties | TelegramProperties | VictorOpsProperties + +export type SpecificConfigOptions = Partial