diff --git a/public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx b/public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx index bbc932d63..e3ad3d294 100644 --- a/public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx +++ b/public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx @@ -20,8 +20,12 @@ import { } from '@elastic/eui'; import { Detector } from '../../../../../../../models/interfaces'; import { AlertCondition } from '../../../../../../../models/interfaces'; -import { createSelectedOptions, parseAlertSeverityToOption } from '../../utils/helpers'; -import { ALERT_SEVERITY_OPTIONS, EMPTY_DEFAULT_ALERT_CONDITION } from '../../utils/constants'; +import { + createSelectedOptions, + getEmptyAlertCondition, + parseAlertSeverityToOption, +} from '../../utils/helpers'; +import { ALERT_SEVERITY_OPTIONS } from '../../utils/constants'; import { CreateDetectorRulesOptions } from '../../../../../../models/types'; import { NotificationChannelOption, NotificationChannelTypeOptions } from '../../models/interfaces'; import { NOTIFICATIONS_HREF } from '../../../../../../utils/constants'; @@ -247,7 +251,7 @@ export default class AlertConditionPanel extends Component< render() { const { - alertCondition = EMPTY_DEFAULT_ALERT_CONDITION, + alertCondition = getEmptyAlertCondition(), allNotificationChannels, indexNum, loadingNotifications, diff --git a/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx b/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx index 4d3943dce..9cf0ddbc1 100644 --- a/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx +++ b/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx @@ -15,13 +15,17 @@ import { EuiText, } from '@elastic/eui'; import { createDetectorSteps } from '../../../utils/constants'; -import { EMPTY_DEFAULT_ALERT_CONDITION, MAX_ALERT_CONDITIONS } from '../utils/constants'; +import { MAX_ALERT_CONDITIONS } from '../utils/constants'; import AlertConditionPanel from '../components/AlertCondition'; import { Detector } from '../../../../../../models/interfaces'; import { DetectorCreationStep } from '../../../models/types'; import { CreateDetectorRulesOptions } from '../../../../../models/types'; import { NotificationChannelTypeOptions } from '../models/interfaces'; -import { getNotificationChannels, parseNotificationChannelsToOptions } from '../utils/helpers'; +import { + getEmptyAlertCondition, + getNotificationChannels, + parseNotificationChannelsToOptions, +} from '../utils/helpers'; import { NotificationsService } from '../../../../../services'; interface ConfigureAlertsProps extends RouteComponentProps { @@ -71,7 +75,7 @@ export default class ConfigureAlerts extends Component => { return Object.values(ALERT_SEVERITY_OPTIONS).find( @@ -48,3 +49,34 @@ export function parseNotificationChannelsToOptions( options: allOptions.filter((channel) => channel.type === type), })); } + +export function getEmptyAlertCondition(): AlertCondition { + const emptyTriggerAction: TriggerAction = { + id: '', + name: '', + destination_id: '', + subject_template: { + source: '', + lang: 'mustache', + }, + message_template: { + source: '', + lang: 'mustache', + }, + throttle_enabled: false, + throttle: { + value: 10, + unit: 'MINUTES', + }, + }; + + return { + name: '', + sev_levels: [], + tags: [], + actions: [emptyTriggerAction], + types: [], + severity: '1', + ids: [], + }; +} diff --git a/public/pages/Findings/components/CreateAlertFlyout.tsx b/public/pages/Findings/components/CreateAlertFlyout.tsx index fb2d5805c..60a3fe0aa 100644 --- a/public/pages/Findings/components/CreateAlertFlyout.tsx +++ b/public/pages/Findings/components/CreateAlertFlyout.tsx @@ -13,19 +13,18 @@ import { EuiFlyoutBody, EuiFlyoutHeader, EuiFormRow, - EuiLink, EuiSpacer, EuiText, EuiTitle, } from '@elastic/eui'; import AlertConditionPanel from '../../CreateDetector/components/ConfigureAlerts/components/AlertCondition'; import { AlertCondition, Detector } from '../../../../models/interfaces'; -import { EMPTY_DEFAULT_ALERT_CONDITION } from '../../CreateDetector/components/ConfigureAlerts/utils/constants'; import { DetectorsService } from '../../../services'; import { RulesSharedState } from '../../../models/interfaces'; 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'; interface CreateAlertFlyoutProps extends RouteComponentProps { closeFlyout: (refreshPage?: boolean) => void; @@ -52,7 +51,7 @@ export default class CreateAlertFlyout extends Component< constructor(props: CreateAlertFlyoutProps) { super(props); this.state = { - alertCondition: EMPTY_DEFAULT_ALERT_CONDITION, + alertCondition: getEmptyAlertCondition(), loading: false, detector: this.props.finding.detector._source, submitting: false,