From 175286d69521ab98a6e66fba986b0bee71c7f286 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 18 Jan 2023 15:04:18 -0800 Subject: [PATCH] Feature/flyout alert name validation (#367) (#374) * [FEATURE] Detector must have at least one alert set #288 Signed-off-by: Jovan Cvetkovic * [FEATURE] Add cypress custom commands to support better type events #364 Signed-off-by: Jovan Cvetkovic * [FEATURE] Trigger name should be required in Create alert trigger flyout #352 Signed-off-by: Jovan Cvetkovic Signed-off-by: Jovan Cvetkovic (cherry picked from commit 50430e3aae34908887b38bcc772b39a1c7997fc9) Co-authored-by: Jovan Cvetkovic Signed-off-by: AWSHurneyt --- .../pages/Findings/components/CreateAlertFlyout.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/public/pages/Findings/components/CreateAlertFlyout.tsx b/public/pages/Findings/components/CreateAlertFlyout.tsx index 60a3fe0aa..c0c99eb18 100644 --- a/public/pages/Findings/components/CreateAlertFlyout.tsx +++ b/public/pages/Findings/components/CreateAlertFlyout.tsx @@ -25,6 +25,7 @@ import { DEFAULT_EMPTY_DATA } from '../../../utils/constants'; import { NotificationChannelTypeOptions } from '../../CreateDetector/components/ConfigureAlerts/models/interfaces'; import { Finding } from '../models/interfaces'; import { getEmptyAlertCondition } from '../../CreateDetector/components/ConfigureAlerts/utils/helpers'; +import { validateName } from '../../../utils/validation'; interface CreateAlertFlyoutProps extends RouteComponentProps { closeFlyout: (refreshPage?: boolean) => void; @@ -42,6 +43,7 @@ interface CreateAlertFlyoutState { loading: boolean; detector: Detector; submitting: boolean; + isTriggerDataValid: boolean; } export default class CreateAlertFlyout extends Component< @@ -55,6 +57,7 @@ export default class CreateAlertFlyout extends Component< loading: false, detector: this.props.finding.detector._source, submitting: false, + isTriggerDataValid: false, }; } @@ -85,7 +88,10 @@ export default class CreateAlertFlyout extends Component< }; onAlertConditionChange = (newDetector: Detector): void => { - this.setState({ detector: { ...newDetector } }); + const isTriggerDataValid = newDetector.triggers.every((trigger) => { + return !!trigger.name && validateName(trigger.name); + }); + this.setState({ detector: { ...newDetector }, isTriggerDataValid }); }; onCreate = async () => { @@ -120,7 +126,7 @@ export default class CreateAlertFlyout extends Component< closeFlyout, notificationChannels, } = this.props; - const { alertCondition, loading, detector, submitting } = this.state; + const { alertCondition, loading, detector, submitting, isTriggerDataValid } = this.state; const indexNum = triggers.length; return ( @@ -159,7 +165,7 @@ export default class CreateAlertFlyout extends Component<