Add additional options to override for testing slack config

pull/3465/head
Iris Scholten 2018-05-15 14:56:11 -07:00
parent 7616e28b2e
commit 801cdc2992
5 changed files with 21 additions and 11 deletions

View File

@ -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<Props, State> {
private handleTestConfig = (section: string, options?: object) => async (
e: MouseEvent<HTMLButtonElement>,
specificConfig?: string
specificConfigOptions?: SpecificConfigOptions
): Promise<void> => {
e.preventDefault()
@ -522,7 +522,7 @@ class AlertTabs extends PureComponent<Props, State> {
this.props.kapacitor,
section,
options,
specificConfig
specificConfigOptions
)
if (data.success) {
this.props.notify(notifyTestAlertSent(section))

View File

@ -19,7 +19,10 @@ interface Props {
isNewConfigInSection: boolean,
specificConfig: string
) => void
onTest: (e: MouseEvent<HTMLButtonElement>, specificConfig: string) => void
onTest: (
e: MouseEvent<HTMLButtonElement>,
specificConfigOptions: Partial<SlackProperties>
) => void
onDelete: (specificConfig: string, workspaceID: string) => void
enabled: boolean
isNewConfig: boolean
@ -168,10 +171,10 @@ class SlackConfig extends PureComponent<Props, State> {
const {
onTest,
config: {
options: {workspace},
options: {workspace, channel},
},
} = this.props
onTest(e, workspace)
onTest(e, {workspace, channel})
}
private handleEnabledChange = (e: ChangeEvent<HTMLInputElement>) => {

View File

@ -21,7 +21,10 @@ interface Props {
specificConfig: string
) => void
onDelete: (specificConfig: string) => void
onTest: (e: MouseEvent<HTMLButtonElement>, specificConfig: string) => void
onTest: (
e: MouseEvent<HTMLButtonElement>,
specificConfigOptions: Partial<SlackProperties>
) => void
onEnabled: (specificConfig: string) => boolean
}

View File

@ -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)

View File

@ -401,3 +401,5 @@ export type ServiceProperties =
| TalkProperties
| TelegramProperties
| VictorOpsProperties
export type SpecificConfigOptions = Partial<SlackProperties>