Skip to content

Commit 8d835ce

Browse files
authored
show success toast when detector is updated (#224)
Signed-off-by: Amardeepsingh Siglani <[email protected]> Signed-off-by: Amardeepsingh Siglani <[email protected]>
1 parent 9136293 commit 8d835ce

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

public/models/interfaces.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ export interface BrowserServices {
2525
notificationsService: NotificationsService;
2626
}
2727

28+
export interface RuleOptions {
29+
name: string;
30+
id: string;
31+
severity: string;
32+
tags: string[];
33+
}
34+
2835
export interface RulesSharedState {
2936
page: RulesPage;
30-
rulesOptions: {
31-
name: string;
32-
id: string;
33-
severity: string;
34-
tags: string[];
35-
}[];
37+
rulesOptions: RuleOptions[];
3638
}
3739

3840
export interface RulesPage {

public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import React, { Component } from 'react';
77
import { RouteComponentProps } from 'react-router-dom';
88
import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
9-
import { DetectorHit } from '../../../../../server/models/interfaces';
9+
import { DetectorHit, RuleSource } from '../../../../../server/models/interfaces';
1010
import { Detector } from '../../../../../models/interfaces';
1111
import ConfigureAlerts from '../../../CreateDetector/components/ConfigureAlerts';
1212
import {
@@ -15,10 +15,14 @@ import {
1515
RuleService,
1616
OpenSearchService,
1717
} from '../../../../services';
18-
import { RulesSharedState } from '../../../../models/interfaces';
18+
import { RuleOptions } from '../../../../models/interfaces';
1919
import { ROUTES, OS_NOTIFICATION_PLUGIN } from '../../../../utils/constants';
2020
import { NotificationsStart } from 'opensearch-dashboards/public';
21-
import { errorNotificationToast, getPlugins } from '../../../../utils/helpers';
21+
import {
22+
errorNotificationToast,
23+
getPlugins,
24+
successNotificationToast,
25+
} from '../../../../utils/helpers';
2226

2327
export interface UpdateAlertConditionsProps
2428
extends RouteComponentProps<any, any, { detectorHit: DetectorHit }> {
@@ -32,7 +36,7 @@ export interface UpdateAlertConditionsProps
3236
export interface UpdateAlertConditionsState {
3337
detector: Detector;
3438
rules: object;
35-
rulesOptions: Pick<RulesSharedState, 'rulesOptions'>['rulesOptions'];
39+
rulesOptions: RuleOptions[];
3640
submitting: boolean;
3741
plugins: string[];
3842
}
@@ -83,8 +87,8 @@ export default class UpdateAlertConditions extends Component<
8387
const prePackagedResponse = await ruleService.getRules(true, body);
8488
const customResponse = await ruleService.getRules(false, body);
8589

86-
const allRules = {};
87-
const rulesOptions = new Set();
90+
const allRules: { [id: string]: RuleSource } = {};
91+
const rulesOptions = new Set<RuleOptions>();
8892

8993
if (prePackagedResponse.ok) {
9094
prePackagedResponse.response.hits.hits.forEach((hit) => {
@@ -127,7 +131,7 @@ export default class UpdateAlertConditions extends Component<
127131
}
128132

129133
this.setState({ rules: allRules, rulesOptions: Array.from(rulesOptions) });
130-
} catch (e) {
134+
} catch (e: any) {
131135
errorNotificationToast(this.props.notifications, 'retrieve', 'rules', e);
132136
}
133137
};
@@ -169,8 +173,10 @@ export default class UpdateAlertConditions extends Component<
169173
'detector',
170174
updateDetectorResponse.error
171175
);
176+
} else {
177+
successNotificationToast(this.props.notifications, 'updated', 'detector');
172178
}
173-
} catch (e) {
179+
} catch (e: any) {
174180
errorNotificationToast(this.props.notifications, 'update', 'detector', e);
175181
}
176182

public/pages/Detectors/components/UpdateBasicDetails/UpdateBasicDetails.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { DetectorHit, SearchDetectorsResponse } from '../../../../../server/mode
2323
import { EMPTY_DEFAULT_DETECTOR, ROUTES } from '../../../../utils/constants';
2424
import { ServerResponse } from '../../../../../server/models/types';
2525
import { NotificationsStart } from 'opensearch-dashboards/public';
26-
import { errorNotificationToast } from '../../../../utils/helpers';
26+
import { errorNotificationToast, successNotificationToast } from '../../../../utils/helpers';
2727

2828
export interface UpdateDetectorBasicDetailsProps
2929
extends RouteComponentProps<any, any, { detectorHit: DetectorHit }> {
@@ -168,23 +168,18 @@ export const UpdateDetectorBasicDetails: React.FC<UpdateDetectorBasicDetailsProp
168168
);
169169

170170
if (updateDetectorRes?.ok) {
171-
props.history.replace({
172-
pathname: `${ROUTES.DETECTOR_DETAILS}/${detectorId}`,
173-
state: {
174-
detectorHit: { ...detectorHit, _source: { ...detectorHit._source, ...detector } },
175-
},
176-
});
171+
successNotificationToast(props.notifications, 'updated', 'detector');
177172
} else {
178173
errorNotificationToast(props.notifications, 'update', 'detector', updateDetectorRes?.error);
179174
}
180175

176+
setSubmitting(false);
181177
props.history.replace({
182178
pathname: `${ROUTES.DETECTOR_DETAILS}/${detectorId}`,
183179
state: {
184180
detectorHit: { ...detectorHit, _source: { ...detectorHit._source, ...detector } },
185181
},
186182
});
187-
setSubmitting(false);
188183
};
189184

190185
updateDetector().catch((e) => {

public/pages/Detectors/components/UpdateFieldMappings/UpdateFieldMappings.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { EMPTY_DEFAULT_DETECTOR, ROUTES } from '../../../../utils/constants';
1414
import { DetectorsService } from '../../../../services';
1515
import { ServerResponse } from '../../../../../server/models/types';
1616
import { NotificationsStart } from 'opensearch-dashboards/public';
17-
import { errorNotificationToast } from '../../../../utils/helpers';
17+
import { errorNotificationToast, successNotificationToast } from '../../../../utils/helpers';
1818

1919
export interface UpdateFieldMappingsProps
2020
extends RouteComponentProps<any, any, { detectorHit: DetectorHit }> {
@@ -128,6 +128,8 @@ export default class UpdateFieldMappings extends Component<
128128
'detector',
129129
updateDetectorResponse.error
130130
);
131+
} else {
132+
successNotificationToast(this.props.notifications, 'updated', 'detector');
131133
}
132134
} catch (error: any) {
133135
errorNotificationToast(this.props.notifications, 'update', 'detector', error);

public/pages/Detectors/components/UpdateRules/UpdateRules.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { EMPTY_DEFAULT_DETECTOR, ROUTES } from '../../../../utils/constants';
1919
import { ServicesContext } from '../../../../services';
2020
import { ServerResponse } from '../../../../../server/models/types';
2121
import { NotificationsStart } from 'opensearch-dashboards/public';
22-
import { errorNotificationToast } from '../../../../utils/helpers';
22+
import { errorNotificationToast, successNotificationToast } from '../../../../utils/helpers';
2323

2424
export interface UpdateDetectorRulesProps
2525
extends RouteComponentProps<
@@ -191,6 +191,8 @@ export const UpdateDetectorRules: React.FC<UpdateDetectorRulesProps> = (props) =
191191

192192
if (!updateDetectorRes.ok) {
193193
errorNotificationToast(props.notifications, 'update', 'detector', updateDetectorRes.error);
194+
} else {
195+
successNotificationToast(props.notifications, 'updated', 'detector');
194196
}
195197

196198
props.history.replace({

public/pages/Detectors/containers/Detector/DetectorDetails.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
EuiSpacer,
1515
EuiTab,
1616
EuiTabs,
17-
EuiText,
1817
EuiTitle,
1918
EuiHealth,
2019
} from '@elastic/eui';

0 commit comments

Comments
 (0)