Validate batch size to be a number on Kafka form submit

pull/3386/head
Jared Scheib 2018-05-04 17:49:32 -07:00
parent e3945ad0fa
commit e6bef3e525
3 changed files with 23 additions and 1 deletions

View File

@ -5,6 +5,8 @@ import {ErrorHandling} from 'src/shared/decorators/errors'
import {Notification, NotificationFunc} from 'src/types'
import {notifyInvalidBatchSizeValue} from 'src/shared/copy/notifications'
interface Properties {
brokers: string[]
timeout: string
@ -216,10 +218,16 @@ class KafkaConfig extends PureComponent<Props, State> {
private handleSubmit = async e => {
e.preventDefault()
const batchSize = parseInt(this.batchSize.value, 10)
if (isNaN(batchSize)) {
this.props.notify(notifyInvalidBatchSizeValue())
return
}
const properties = {
brokers: this.state.currentBrokers,
timeout: this.timeout.value,
'batch-size': parseInt(this.batchSize.value, 10),
'batch-size': batchSize,
'batch-timeout': this.batchTimeout.value,
'use-ssl': this.useSSL.checked,
'ssl-ca': this.sslCA.value,

View File

@ -536,6 +536,11 @@ export const notifyTestAlertFailed = (endpoint, errorMessage) => ({
}`,
})
export const notifyInvalidBatchSizeValue = () => ({
...defaultErrorNotification,
message: 'Batch Size cannot be empty.',
})
export const notifyKapacitorConnectionFailed = () => ({
...defaultErrorNotification,
message:

View File

@ -0,0 +1,9 @@
export interface Notification {
id?: string
type: string
icon: string
duration: number
message: string
}
export type NotificationFunc = () => Notification