Skip to content

Commit

Permalink
[FEATURE] Detector must have at least one alert set opensearch-projec…
Browse files Browse the repository at this point in the history
…t#288 (opensearch-project#289) (opensearch-project#290)

* [FEATURE] Detector must have at least one alert set opensearch-project#288

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Detector must have at least one alert set opensearch-project#288

Signed-off-by: Jovan Cvetkovic <[email protected]>

Signed-off-by: Jovan Cvetkovic <[email protected]>
(cherry picked from commit c8c9f1c)

Co-authored-by: Jovan Cvetkovic <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
2 people authored and AWSHurneyt committed Oct 12, 2023
1 parent 6f94317 commit 6979904
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
parseNotificationChannelsToOptions,
} from '../utils/helpers';
import { NotificationsService } from '../../../../../services';
import { validateName } from '../../../../../utils/validation';

interface ConfigureAlertsProps extends RouteComponentProps {
detector: Detector;
Expand Down Expand Up @@ -81,8 +82,9 @@ export default class ConfigureAlerts extends Component<ConfigureAlertsProps, Con

onAlertTriggerChanged = (newDetector: Detector): void => {
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);
};
Expand Down Expand Up @@ -130,9 +132,13 @@ export default class ConfigureAlerts extends Component<ConfigureAlertsProps, Con
paddingSize={'none'}
initialIsOpen={true}
extraAction={
<EuiButton color="danger" onClick={() => this.onDelete(index)}>
Remove alert trigger
</EuiButton>
triggers.length > 1 ? (
<EuiButton color="danger" onClick={() => this.onDelete(index)}>
Remove alert trigger
</EuiButton>
) : (
<></>
)
}
>
<EuiHorizontalRule margin={'xs'} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getPlugins,
successNotificationToast,
} from '../../../../utils/helpers';
import { DetectorCreationStep } from '../../../CreateDetector/models/types';

export interface UpdateAlertConditionsProps
extends RouteComponentProps<any, any, { detectorHit: DetectorHit }> {
Expand All @@ -39,6 +40,7 @@ export interface UpdateAlertConditionsState {
rulesOptions: RuleOptions[];
submitting: boolean;
plugins: string[];
isTriggerNameValid: boolean;
}

export default class UpdateAlertConditions extends Component<
Expand All @@ -53,6 +55,7 @@ export default class UpdateAlertConditions extends Component<
rulesOptions: [],
submitting: false,
plugins: [],
isTriggerNameValid: true,
};
}

Expand Down Expand Up @@ -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 (
<div>
<ConfigureAlerts
Expand All @@ -199,7 +209,7 @@ export default class UpdateAlertConditions extends Component<
detector={detector}
rulesOptions={rulesOptions}
changeDetector={this.changeDetector}
updateDataValidState={() => {}}
updateDataValidState={this.updateDataValidState}
hasNotificationPlugin={this.state.plugins.includes(OS_NOTIFICATION_PLUGIN)}
/>

Expand All @@ -211,7 +221,7 @@ export default class UpdateAlertConditions extends Component<
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
disabled={submitting}
disabled={isSaveDisabled}
fill={true}
isLoading={submitting}
onClick={this.onSave}
Expand Down

0 comments on commit 6979904

Please sign in to comment.