From f78f8dda364d065d4165a93c6ac2af0956d5d94f Mon Sep 17 00:00:00 2001 From: Jovan Cvetkovic Date: Mon, 9 Jan 2023 10:28:00 +0100 Subject: [PATCH 1/2] [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 7903628366cbe9dfa3a915a4eb9de5324c95f676 Mon Sep 17 00:00:00 2001 From: Jovan Cvetkovic Date: Mon, 9 Jan 2023 12:02:15 +0100 Subject: [PATCH 2/2] [FEATURE] Detector must have at least one alert set #288 Signed-off-by: Jovan Cvetkovic --- .../containers/ConfigureAlerts.tsx | 4 +++- .../UpdateAlertConditions.tsx | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx b/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx index 5f4ce02b8..f8499056d 100644 --- a/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx +++ b/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx @@ -27,6 +27,7 @@ import { parseNotificationChannelsToOptions, } from '../utils/helpers'; import { NotificationsService } from '../../../../../services'; +import { validateName } from '../../../../../utils/validation'; interface ConfigureAlertsProps extends RouteComponentProps { detector: Detector; @@ -81,8 +82,9 @@ export default class ConfigureAlerts extends Component { const isTriggerDataValid = newDetector.triggers.every((trigger) => { - return !!trigger.name && trigger.severity; + return !!trigger.name && validateName(trigger.name) && trigger.severity; }); + this.props.changeDetector(newDetector); this.props.updateDataValidState(DetectorCreationStep.CONFIGURE_ALERTS, isTriggerDataValid); }; diff --git a/public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx b/public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx index 4eea500c7..55bc57056 100644 --- a/public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx +++ b/public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx @@ -23,6 +23,7 @@ import { getPlugins, successNotificationToast, } from '../../../../utils/helpers'; +import { DetectorCreationStep } from '../../../CreateDetector/models/types'; export interface UpdateAlertConditionsProps extends RouteComponentProps { @@ -39,6 +40,7 @@ export interface UpdateAlertConditionsState { rulesOptions: RuleOptions[]; submitting: boolean; plugins: string[]; + isTriggerNameValid: boolean; } export default class UpdateAlertConditions extends Component< @@ -53,6 +55,7 @@ export default class UpdateAlertConditions extends Component< rulesOptions: [], submitting: false, plugins: [], + isTriggerNameValid: true, }; } @@ -189,8 +192,15 @@ export default class UpdateAlertConditions extends Component< }); }; + updateDataValidState = (step: DetectorCreationStep, isValid: boolean): void => { + this.setState({ + isTriggerNameValid: isValid, + }); + }; + render() { - const { detector, rulesOptions, submitting } = this.state; + const { detector, rulesOptions, submitting, isTriggerNameValid } = this.state; + const isSaveDisabled = submitting || !isTriggerNameValid; return (
{}} + updateDataValidState={this.updateDataValidState} hasNotificationPlugin={this.state.plugins.includes(OS_NOTIFICATION_PLUGIN)} /> @@ -211,7 +221,7 @@ export default class UpdateAlertConditions extends Component<