From f78f8dda364d065d4165a93c6ac2af0956d5d94f Mon Sep 17 00:00:00 2001 From: Jovan Cvetkovic Date: Mon, 9 Jan 2023 10:28:00 +0100 Subject: [PATCH 1/3] [FEATURE] Detector must have at least one alert set #288 Signed-off-by: Jovan Cvetkovic --- .../ConfigureAlerts/containers/ConfigureAlerts.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx b/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx index 9cf0ddbc1..5f4ce02b8 100644 --- a/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx +++ b/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx @@ -130,9 +130,13 @@ export default class ConfigureAlerts extends Component this.onDelete(index)}> - Remove alert trigger - + triggers.length > 1 ? ( + this.onDelete(index)}> + Remove alert trigger + + ) : ( + <> + ) } > From 058d35a4ce781aed69e65760e00f40f82cb28952 Mon Sep 17 00:00:00 2001 From: Jovan Cvetkovic Date: Sat, 14 Jan 2023 09:18:45 +0100 Subject: [PATCH 2/3] [FEATURE] Add cypress custom commands to support better type events #364 Signed-off-by: Jovan Cvetkovic --- .../Findings/components/CreateAlertFlyout.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/public/pages/Findings/components/CreateAlertFlyout.tsx b/public/pages/Findings/components/CreateAlertFlyout.tsx index 60a3fe0aa..382bd998a 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,12 @@ export default class CreateAlertFlyout extends Component< }; onAlertConditionChange = (newDetector: Detector): void => { - this.setState({ detector: { ...newDetector } }); + const isTriggerDataValid = newDetector.triggers.every((trigger) => { + console.log(trigger); + return !!trigger.name && validateName(trigger.name) && trigger.severity; + }); + + this.setState({ detector: { ...newDetector }, isTriggerDataValid }); }; onCreate = async () => { @@ -120,7 +128,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 +167,7 @@ export default class CreateAlertFlyout extends Component< Date: Sat, 14 Jan 2023 15:50:43 +0100 Subject: [PATCH 3/3] [FEATURE] Trigger name should be required in Create alert trigger flyout #352 Signed-off-by: Jovan Cvetkovic --- public/pages/Findings/components/CreateAlertFlyout.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/public/pages/Findings/components/CreateAlertFlyout.tsx b/public/pages/Findings/components/CreateAlertFlyout.tsx index 382bd998a..c0c99eb18 100644 --- a/public/pages/Findings/components/CreateAlertFlyout.tsx +++ b/public/pages/Findings/components/CreateAlertFlyout.tsx @@ -89,10 +89,8 @@ export default class CreateAlertFlyout extends Component< onAlertConditionChange = (newDetector: Detector): void => { const isTriggerDataValid = newDetector.triggers.every((trigger) => { - console.log(trigger); - return !!trigger.name && validateName(trigger.name) && trigger.severity; + return !!trigger.name && validateName(trigger.name); }); - this.setState({ detector: { ...newDetector }, isTriggerDataValid }); };