From e6bef3e5254396f7251f533db4359ef9c7b691d1 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Fri, 4 May 2018 17:49:32 -0700 Subject: [PATCH] Validate batch size to be a number on Kafka form submit --- ui/src/kapacitor/components/config/KafkaConfig.tsx | 10 +++++++++- ui/src/shared/copy/notifications.js | 5 +++++ ui/src/types/notifications.ts | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 ui/src/types/notifications.ts diff --git a/ui/src/kapacitor/components/config/KafkaConfig.tsx b/ui/src/kapacitor/components/config/KafkaConfig.tsx index d3dfc1f05..afb27209d 100644 --- a/ui/src/kapacitor/components/config/KafkaConfig.tsx +++ b/ui/src/kapacitor/components/config/KafkaConfig.tsx @@ -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 { 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, diff --git a/ui/src/shared/copy/notifications.js b/ui/src/shared/copy/notifications.js index e175a152c..26d88f596 100644 --- a/ui/src/shared/copy/notifications.js +++ b/ui/src/shared/copy/notifications.js @@ -536,6 +536,11 @@ export const notifyTestAlertFailed = (endpoint, errorMessage) => ({ }`, }) +export const notifyInvalidBatchSizeValue = () => ({ + ...defaultErrorNotification, + message: 'Batch Size cannot be empty.', +}) + export const notifyKapacitorConnectionFailed = () => ({ ...defaultErrorNotification, message: diff --git a/ui/src/types/notifications.ts b/ui/src/types/notifications.ts new file mode 100644 index 000000000..789e88924 --- /dev/null +++ b/ui/src/types/notifications.ts @@ -0,0 +1,9 @@ +export interface Notification { + id?: string + type: string + icon: string + duration: number + message: string +} + +export type NotificationFunc = () => Notification