From 8433d81dc04572b87f019fcab09132e28a033098 Mon Sep 17 00:00:00 2001 From: Chintan Sudani <46838508+techchintan@users.noreply.github.com> Date: Wed, 14 Jun 2023 12:53:50 +0530 Subject: [PATCH] fix: alert name required message & button disabled (#2896) * fix: alert name required message & button disabled * fix: tooltip message issue * fix: button disabled issue while create alert * chore: requiredMessage is updated --------- Co-authored-by: Palash Gupta --- .../container/FormAlertRules/BasicInfo.tsx | 15 ++++++++++--- .../src/container/FormAlertRules/index.tsx | 21 +++++-------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/frontend/src/container/FormAlertRules/BasicInfo.tsx b/frontend/src/container/FormAlertRules/BasicInfo.tsx index f4d99126ec..595e6facd6 100644 --- a/frontend/src/container/FormAlertRules/BasicInfo.tsx +++ b/frontend/src/container/FormAlertRules/BasicInfo.tsx @@ -1,6 +1,7 @@ import { Form, Select } from 'antd'; import { useTranslation } from 'react-i18next'; import { AlertDef, Labels } from 'types/api/alerts/def'; +import { requireErrorMessage } from 'utils/form/requireErrorMessage'; import ChannelSelect from './ChannelSelect'; import LabelSelect from './labels'; @@ -54,7 +55,15 @@ function BasicInfo({ alertDef, setAlertDef }: BasicInfoProps): JSX.Element { - + { setAlertDef({ @@ -97,10 +106,10 @@ function BasicInfo({ alertDef, setAlertDef }: BasicInfoProps): JSX.Element { { + onSelectChannels={(preferredChannels): void => { setAlertDef({ ...alertDef, - preferredChannels: s, + preferredChannels, }); }} /> diff --git a/frontend/src/container/FormAlertRules/index.tsx b/frontend/src/container/FormAlertRules/index.tsx index f131fe60ba..9eec5ad9d0 100644 --- a/frontend/src/container/FormAlertRules/index.tsx +++ b/frontend/src/container/FormAlertRules/index.tsx @@ -201,10 +201,6 @@ function FormAlertRules({ const isFormValid = useCallback((): boolean => { if (!alertDef.alert || alertDef.alert === '') { - notifications.error({ - message: 'Error', - description: t('alertname_required'), - }); return false; } @@ -217,14 +213,7 @@ function FormAlertRules({ } return validateQBParams(); - }, [ - t, - validateQBParams, - validateChQueryParams, - alertDef, - validatePromParams, - notifications, - ]); + }, [validateQBParams, validateChQueryParams, alertDef, validatePromParams]); const preparePostData = (): AlertDef => { const postableAlert: AlertDef = { @@ -328,9 +317,7 @@ function FormAlertRules({ title: t('confirm_save_title'), centered: true, content, - onOk() { - saveRule(); - }, + onOk: saveRule, }); }, [t, saveRule, currentQuery]); @@ -407,6 +394,8 @@ function FormAlertRules({ const isNewRule = ruleId === 0; + const isAlertNameMissing = !formInstance.getFieldValue('alert'); + const isAlertAvialableToSave = isAlertAvialable && isNewRule && @@ -448,7 +437,7 @@ function FormAlertRules({ type="primary" onClick={onSaveHandler} icon={} - disabled={isAlertAvialableToSave} + disabled={isAlertNameMissing || isAlertAvialableToSave} > {isNewRule ? t('button_createrule') : t('button_savechanges')}