Skip to content

Commit 172b42a

Browse files
amsiglangithub-actions[bot]
authored andcommitted
creating new object for alert condition initialization (#255)
Signed-off-by: Amardeepsingh Siglani <[email protected]> Signed-off-by: Amardeepsingh Siglani <[email protected]> (cherry picked from commit ee374d5)
1 parent 51856ee commit 172b42a

File tree

5 files changed

+48
-41
lines changed

5 files changed

+48
-41
lines changed

public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ import {
2020
} from '@elastic/eui';
2121
import { Detector } from '../../../../../../../models/interfaces';
2222
import { AlertCondition } from '../../../../../../../models/interfaces';
23-
import { createSelectedOptions, parseAlertSeverityToOption } from '../../utils/helpers';
24-
import { ALERT_SEVERITY_OPTIONS, EMPTY_DEFAULT_ALERT_CONDITION } from '../../utils/constants';
23+
import {
24+
createSelectedOptions,
25+
getEmptyAlertCondition,
26+
parseAlertSeverityToOption,
27+
} from '../../utils/helpers';
28+
import { ALERT_SEVERITY_OPTIONS } from '../../utils/constants';
2529
import { CreateDetectorRulesOptions } from '../../../../../../models/types';
2630
import { NotificationChannelOption, NotificationChannelTypeOptions } from '../../models/interfaces';
2731
import { NOTIFICATIONS_HREF } from '../../../../../../utils/constants';
@@ -247,7 +251,7 @@ export default class AlertConditionPanel extends Component<
247251

248252
render() {
249253
const {
250-
alertCondition = EMPTY_DEFAULT_ALERT_CONDITION,
254+
alertCondition = getEmptyAlertCondition(),
251255
allNotificationChannels,
252256
indexNum,
253257
loadingNotifications,

public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import {
1515
EuiText,
1616
} from '@elastic/eui';
1717
import { createDetectorSteps } from '../../../utils/constants';
18-
import { EMPTY_DEFAULT_ALERT_CONDITION, MAX_ALERT_CONDITIONS } from '../utils/constants';
18+
import { MAX_ALERT_CONDITIONS } from '../utils/constants';
1919
import AlertConditionPanel from '../components/AlertCondition';
2020
import { Detector } from '../../../../../../models/interfaces';
2121
import { DetectorCreationStep } from '../../../models/types';
2222
import { CreateDetectorRulesOptions } from '../../../../../models/types';
2323
import { NotificationChannelTypeOptions } from '../models/interfaces';
24-
import { getNotificationChannels, parseNotificationChannelsToOptions } from '../utils/helpers';
24+
import {
25+
getEmptyAlertCondition,
26+
getNotificationChannels,
27+
parseNotificationChannelsToOptions,
28+
} from '../utils/helpers';
2529
import { NotificationsService } from '../../../../../services';
2630

2731
interface ConfigureAlertsProps extends RouteComponentProps {
@@ -71,7 +75,7 @@ export default class ConfigureAlerts extends Component<ConfigureAlertsProps, Con
7175
detector,
7276
detector: { triggers },
7377
} = this.props;
74-
triggers.push(EMPTY_DEFAULT_ALERT_CONDITION);
78+
triggers.push(getEmptyAlertCondition());
7579
changeDetector({ ...detector, triggers });
7680
};
7781

public/pages/CreateDetector/components/ConfigureAlerts/utils/constants.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
6-
import { AlertCondition, TriggerAction } from '../../../../../../models/interfaces';
7-
85
export const MAX_ALERT_CONDITIONS = 10;
96
export const MIN_ALERT_CONDITIONS = 0;
107

@@ -27,35 +24,6 @@ export const RULE_SEVERITY_OPTIONS = {
2724
INFORMATIONAL: { id: '5', value: 'informational', label: 'Info', text: 'Info' },
2825
};
2926

30-
export const EMPTY_DEFAULT_TRIGGER_ACTION: TriggerAction = {
31-
id: '',
32-
name: '',
33-
destination_id: '',
34-
subject_template: {
35-
source: '',
36-
lang: 'mustache',
37-
},
38-
message_template: {
39-
source: '',
40-
lang: 'mustache',
41-
},
42-
throttle_enabled: false,
43-
throttle: {
44-
value: 10,
45-
unit: 'MINUTES',
46-
},
47-
};
48-
49-
export const EMPTY_DEFAULT_ALERT_CONDITION: AlertCondition = {
50-
name: '',
51-
sev_levels: [],
52-
tags: [],
53-
actions: [EMPTY_DEFAULT_TRIGGER_ACTION],
54-
types: [],
55-
severity: '1',
56-
ids: [],
57-
};
58-
5927
export const MIN_NUM_NOTIFICATION_CHANNELS = 1;
6028
export const MAX_NUM_NOTIFICATION_CHANNELS = 5;
6129

public/pages/CreateDetector/components/ConfigureAlerts/utils/helpers.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ALERT_SEVERITY_OPTIONS, CHANNEL_TYPES } from './constants';
88
import { FeatureChannelList } from '../../../../../../server/models/interfaces/Notifications';
99
import { NotificationChannelTypeOptions } from '../models/interfaces';
1010
import { NotificationsService } from '../../../../../services';
11+
import { AlertCondition, TriggerAction } from '../../../../../../models/interfaces';
1112

1213
export const parseAlertSeverityToOption = (severity: string): EuiComboBoxOptionOption<string> => {
1314
return Object.values(ALERT_SEVERITY_OPTIONS).find(
@@ -48,3 +49,34 @@ export function parseNotificationChannelsToOptions(
4849
options: allOptions.filter((channel) => channel.type === type),
4950
}));
5051
}
52+
53+
export function getEmptyAlertCondition(): AlertCondition {
54+
const emptyTriggerAction: TriggerAction = {
55+
id: '',
56+
name: '',
57+
destination_id: '',
58+
subject_template: {
59+
source: '',
60+
lang: 'mustache',
61+
},
62+
message_template: {
63+
source: '',
64+
lang: 'mustache',
65+
},
66+
throttle_enabled: false,
67+
throttle: {
68+
value: 10,
69+
unit: 'MINUTES',
70+
},
71+
};
72+
73+
return {
74+
name: '',
75+
sev_levels: [],
76+
tags: [],
77+
actions: [emptyTriggerAction],
78+
types: [],
79+
severity: '1',
80+
ids: [],
81+
};
82+
}

public/pages/Findings/components/CreateAlertFlyout.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ import {
1313
EuiFlyoutBody,
1414
EuiFlyoutHeader,
1515
EuiFormRow,
16-
EuiLink,
1716
EuiSpacer,
1817
EuiText,
1918
EuiTitle,
2019
} from '@elastic/eui';
2120
import AlertConditionPanel from '../../CreateDetector/components/ConfigureAlerts/components/AlertCondition';
2221
import { AlertCondition, Detector } from '../../../../models/interfaces';
23-
import { EMPTY_DEFAULT_ALERT_CONDITION } from '../../CreateDetector/components/ConfigureAlerts/utils/constants';
2422
import { DetectorsService } from '../../../services';
2523
import { RulesSharedState } from '../../../models/interfaces';
2624
import { DEFAULT_EMPTY_DATA } from '../../../utils/constants';
2725
import { NotificationChannelTypeOptions } from '../../CreateDetector/components/ConfigureAlerts/models/interfaces';
2826
import { Finding } from '../models/interfaces';
27+
import { getEmptyAlertCondition } from '../../CreateDetector/components/ConfigureAlerts/utils/helpers';
2928

3029
interface CreateAlertFlyoutProps extends RouteComponentProps {
3130
closeFlyout: (refreshPage?: boolean) => void;
@@ -52,7 +51,7 @@ export default class CreateAlertFlyout extends Component<
5251
constructor(props: CreateAlertFlyoutProps) {
5352
super(props);
5453
this.state = {
55-
alertCondition: EMPTY_DEFAULT_ALERT_CONDITION,
54+
alertCondition: getEmptyAlertCondition(),
5655
loading: false,
5756
detector: this.props.finding.detector._source,
5857
submitting: false,

0 commit comments

Comments
 (0)