diff --git a/public/models/interfaces.ts b/public/models/interfaces.ts index b9194912f..767423ad8 100644 --- a/public/models/interfaces.ts +++ b/public/models/interfaces.ts @@ -25,14 +25,16 @@ export interface BrowserServices { notificationsService: NotificationsService; } +export interface RuleOptions { + name: string; + id: string; + severity: string; + tags: string[]; +} + export interface RulesSharedState { page: RulesPage; - rulesOptions: { - name: string; - id: string; - severity: string; - tags: string[]; - }[]; + rulesOptions: RuleOptions[]; } export interface RulesPage { diff --git a/public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx b/public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx index 8321692cf..4eea500c7 100644 --- a/public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx +++ b/public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx @@ -6,7 +6,7 @@ import React, { Component } from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import { DetectorHit } from '../../../../../server/models/interfaces'; +import { DetectorHit, RuleSource } from '../../../../../server/models/interfaces'; import { Detector } from '../../../../../models/interfaces'; import ConfigureAlerts from '../../../CreateDetector/components/ConfigureAlerts'; import { @@ -15,10 +15,14 @@ import { RuleService, OpenSearchService, } from '../../../../services'; -import { RulesSharedState } from '../../../../models/interfaces'; +import { RuleOptions } from '../../../../models/interfaces'; import { ROUTES, OS_NOTIFICATION_PLUGIN } from '../../../../utils/constants'; import { NotificationsStart } from 'opensearch-dashboards/public'; -import { errorNotificationToast, getPlugins } from '../../../../utils/helpers'; +import { + errorNotificationToast, + getPlugins, + successNotificationToast, +} from '../../../../utils/helpers'; export interface UpdateAlertConditionsProps extends RouteComponentProps { @@ -32,7 +36,7 @@ export interface UpdateAlertConditionsProps export interface UpdateAlertConditionsState { detector: Detector; rules: object; - rulesOptions: Pick['rulesOptions']; + rulesOptions: RuleOptions[]; submitting: boolean; plugins: string[]; } @@ -83,8 +87,8 @@ export default class UpdateAlertConditions extends Component< const prePackagedResponse = await ruleService.getRules(true, body); const customResponse = await ruleService.getRules(false, body); - const allRules = {}; - const rulesOptions = new Set(); + const allRules: { [id: string]: RuleSource } = {}; + const rulesOptions = new Set(); if (prePackagedResponse.ok) { prePackagedResponse.response.hits.hits.forEach((hit) => { @@ -127,7 +131,7 @@ export default class UpdateAlertConditions extends Component< } this.setState({ rules: allRules, rulesOptions: Array.from(rulesOptions) }); - } catch (e) { + } catch (e: any) { errorNotificationToast(this.props.notifications, 'retrieve', 'rules', e); } }; @@ -169,8 +173,10 @@ export default class UpdateAlertConditions extends Component< 'detector', updateDetectorResponse.error ); + } else { + successNotificationToast(this.props.notifications, 'updated', 'detector'); } - } catch (e) { + } catch (e: any) { errorNotificationToast(this.props.notifications, 'update', 'detector', e); } diff --git a/public/pages/Detectors/components/UpdateBasicDetails/UpdateBasicDetails.tsx b/public/pages/Detectors/components/UpdateBasicDetails/UpdateBasicDetails.tsx index 30644d375..b473143f0 100644 --- a/public/pages/Detectors/components/UpdateBasicDetails/UpdateBasicDetails.tsx +++ b/public/pages/Detectors/components/UpdateBasicDetails/UpdateBasicDetails.tsx @@ -23,7 +23,7 @@ import { DetectorHit, SearchDetectorsResponse } from '../../../../../server/mode import { EMPTY_DEFAULT_DETECTOR, ROUTES } from '../../../../utils/constants'; import { ServerResponse } from '../../../../../server/models/types'; import { NotificationsStart } from 'opensearch-dashboards/public'; -import { errorNotificationToast } from '../../../../utils/helpers'; +import { errorNotificationToast, successNotificationToast } from '../../../../utils/helpers'; export interface UpdateDetectorBasicDetailsProps extends RouteComponentProps { @@ -168,23 +168,18 @@ export const UpdateDetectorBasicDetails: React.FC { diff --git a/public/pages/Detectors/components/UpdateFieldMappings/UpdateFieldMappings.tsx b/public/pages/Detectors/components/UpdateFieldMappings/UpdateFieldMappings.tsx index 98f6cb930..eb5a6f5b5 100644 --- a/public/pages/Detectors/components/UpdateFieldMappings/UpdateFieldMappings.tsx +++ b/public/pages/Detectors/components/UpdateFieldMappings/UpdateFieldMappings.tsx @@ -14,7 +14,7 @@ import { EMPTY_DEFAULT_DETECTOR, ROUTES } from '../../../../utils/constants'; import { DetectorsService } from '../../../../services'; import { ServerResponse } from '../../../../../server/models/types'; import { NotificationsStart } from 'opensearch-dashboards/public'; -import { errorNotificationToast } from '../../../../utils/helpers'; +import { errorNotificationToast, successNotificationToast } from '../../../../utils/helpers'; export interface UpdateFieldMappingsProps extends RouteComponentProps { @@ -128,6 +128,8 @@ export default class UpdateFieldMappings extends Component< 'detector', updateDetectorResponse.error ); + } else { + successNotificationToast(this.props.notifications, 'updated', 'detector'); } } catch (error: any) { errorNotificationToast(this.props.notifications, 'update', 'detector', error); diff --git a/public/pages/Detectors/components/UpdateRules/UpdateRules.tsx b/public/pages/Detectors/components/UpdateRules/UpdateRules.tsx index 68aa9bc28..3d3b10995 100644 --- a/public/pages/Detectors/components/UpdateRules/UpdateRules.tsx +++ b/public/pages/Detectors/components/UpdateRules/UpdateRules.tsx @@ -19,7 +19,7 @@ import { EMPTY_DEFAULT_DETECTOR, ROUTES } from '../../../../utils/constants'; import { ServicesContext } from '../../../../services'; import { ServerResponse } from '../../../../../server/models/types'; import { NotificationsStart } from 'opensearch-dashboards/public'; -import { errorNotificationToast } from '../../../../utils/helpers'; +import { errorNotificationToast, successNotificationToast } from '../../../../utils/helpers'; export interface UpdateDetectorRulesProps extends RouteComponentProps< @@ -191,6 +191,8 @@ export const UpdateDetectorRules: React.FC = (props) = if (!updateDetectorRes.ok) { errorNotificationToast(props.notifications, 'update', 'detector', updateDetectorRes.error); + } else { + successNotificationToast(props.notifications, 'updated', 'detector'); } props.history.replace({ diff --git a/public/pages/Detectors/containers/Detector/DetectorDetails.tsx b/public/pages/Detectors/containers/Detector/DetectorDetails.tsx index b1eb3ddf3..b10d22d56 100644 --- a/public/pages/Detectors/containers/Detector/DetectorDetails.tsx +++ b/public/pages/Detectors/containers/Detector/DetectorDetails.tsx @@ -14,7 +14,6 @@ import { EuiSpacer, EuiTab, EuiTabs, - EuiText, EuiTitle, EuiHealth, } from '@elastic/eui';