Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show success toast when detector is updated #224

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions public/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<any, any, { detectorHit: DetectorHit }> {
Expand All @@ -32,7 +36,7 @@ export interface UpdateAlertConditionsProps
export interface UpdateAlertConditionsState {
detector: Detector;
rules: object;
rulesOptions: Pick<RulesSharedState, 'rulesOptions'>['rulesOptions'];
rulesOptions: RuleOptions[];
submitting: boolean;
plugins: string[];
}
Expand Down Expand Up @@ -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<RuleOptions>();

if (prePackagedResponse.ok) {
prePackagedResponse.response.hits.hits.forEach((hit) => {
Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any, { detectorHit: DetectorHit }> {
Expand Down Expand Up @@ -168,23 +168,18 @@ export const UpdateDetectorBasicDetails: React.FC<UpdateDetectorBasicDetailsProp
);

if (updateDetectorRes?.ok) {
props.history.replace({
pathname: `${ROUTES.DETECTOR_DETAILS}/${detectorId}`,
state: {
detectorHit: { ...detectorHit, _source: { ...detectorHit._source, ...detector } },
},
});
successNotificationToast(props.notifications, 'updated', 'detector');
} else {
errorNotificationToast(props.notifications, 'update', 'detector', updateDetectorRes?.error);
}

setSubmitting(false);
props.history.replace({
pathname: `${ROUTES.DETECTOR_DETAILS}/${detectorId}`,
state: {
detectorHit: { ...detectorHit, _source: { ...detectorHit._source, ...detector } },
},
});
setSubmitting(false);
};

updateDetector().catch((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any, { detectorHit: DetectorHit }> {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -191,6 +191,8 @@ export const UpdateDetectorRules: React.FC<UpdateDetectorRulesProps> = (props) =

if (!updateDetectorRes.ok) {
errorNotificationToast(props.notifications, 'update', 'detector', updateDetectorRes.error);
} else {
successNotificationToast(props.notifications, 'updated', 'detector');
}

props.history.replace({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
EuiSpacer,
EuiTab,
EuiTabs,
EuiText,
EuiTitle,
EuiHealth,
} from '@elastic/eui';
Expand Down