Skip to content

Commit 175286d

Browse files
opensearch-trigger-bot[bot]jovancvetkovic3006
authored andcommitted
Feature/flyout alert name validation (opensearch-project#367) (opensearch-project#374)
* [FEATURE] Detector must have at least one alert set opensearch-project#288 Signed-off-by: Jovan Cvetkovic <[email protected]> * [FEATURE] Add cypress custom commands to support better type events opensearch-project#364 Signed-off-by: Jovan Cvetkovic <[email protected]> * [FEATURE] Trigger name should be required in Create alert trigger flyout opensearch-project#352 Signed-off-by: Jovan Cvetkovic <[email protected]> Signed-off-by: Jovan Cvetkovic <[email protected]> (cherry picked from commit 50430e3) Co-authored-by: Jovan Cvetkovic <[email protected]> Signed-off-by: AWSHurneyt <[email protected]>
1 parent 8fcc762 commit 175286d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

public/pages/Findings/components/CreateAlertFlyout.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { DEFAULT_EMPTY_DATA } from '../../../utils/constants';
2525
import { NotificationChannelTypeOptions } from '../../CreateDetector/components/ConfigureAlerts/models/interfaces';
2626
import { Finding } from '../models/interfaces';
2727
import { getEmptyAlertCondition } from '../../CreateDetector/components/ConfigureAlerts/utils/helpers';
28+
import { validateName } from '../../../utils/validation';
2829

2930
interface CreateAlertFlyoutProps extends RouteComponentProps {
3031
closeFlyout: (refreshPage?: boolean) => void;
@@ -42,6 +43,7 @@ interface CreateAlertFlyoutState {
4243
loading: boolean;
4344
detector: Detector;
4445
submitting: boolean;
46+
isTriggerDataValid: boolean;
4547
}
4648

4749
export default class CreateAlertFlyout extends Component<
@@ -55,6 +57,7 @@ export default class CreateAlertFlyout extends Component<
5557
loading: false,
5658
detector: this.props.finding.detector._source,
5759
submitting: false,
60+
isTriggerDataValid: false,
5861
};
5962
}
6063

@@ -85,7 +88,10 @@ export default class CreateAlertFlyout extends Component<
8588
};
8689

8790
onAlertConditionChange = (newDetector: Detector): void => {
88-
this.setState({ detector: { ...newDetector } });
91+
const isTriggerDataValid = newDetector.triggers.every((trigger) => {
92+
return !!trigger.name && validateName(trigger.name);
93+
});
94+
this.setState({ detector: { ...newDetector }, isTriggerDataValid });
8995
};
9096

9197
onCreate = async () => {
@@ -120,7 +126,7 @@ export default class CreateAlertFlyout extends Component<
120126
closeFlyout,
121127
notificationChannels,
122128
} = this.props;
123-
const { alertCondition, loading, detector, submitting } = this.state;
129+
const { alertCondition, loading, detector, submitting, isTriggerDataValid } = this.state;
124130
const indexNum = triggers.length;
125131
return (
126132
<EuiFlyout onClose={closeFlyout} ownFocus={true} size={'m'}>
@@ -159,7 +165,7 @@ export default class CreateAlertFlyout extends Component<
159165

160166
<EuiFlexItem grow={false}>
161167
<EuiButton
162-
disabled={submitting}
168+
disabled={submitting || !isTriggerDataValid}
163169
fill={true}
164170
isLoading={submitting}
165171
onClick={this.onCreate}

0 commit comments

Comments
 (0)