From 92949c7a486a2903ef2fe4852b397a26b6de2cb8 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 30 Dec 2022 16:18:44 +0530 Subject: [PATCH] creating new object for alert condition initialization (#255) (#271) Signed-off-by: Amardeepsingh Siglani Signed-off-by: Amardeepsingh Siglani (cherry picked from commit ee374d534e39b30becc3a16aa50bc53808c5b1b5) Co-authored-by: Amardeepsingh Siglani --- .../AlertCondition/AlertConditionPanel.tsx | 10 ++++-- .../containers/ConfigureAlerts.tsx | 10 ++++-- .../ConfigureAlerts/utils/constants.ts | 32 ------------------- .../ConfigureAlerts/utils/helpers.ts | 32 +++++++++++++++++++ .../Findings/components/CreateAlertFlyout.tsx | 5 ++- 5 files changed, 48 insertions(+), 41 deletions(-) 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,