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

[Detection Engine] Fix rule edit success toast #190928

Merged
merged 9 commits into from
Oct 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useParams } from 'react-router-dom';

import type { DataViewListItem } from '@kbn/data-views-plugin/common';

import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { isEsqlRule } from '../../../../../common/detection_engine/utils';
import { RulePreview } from '../../components/rule_preview';
import { getIsRulePreviewDisabled } from '../../components/rule_preview/helpers';
Expand All @@ -38,7 +39,6 @@ import {
getRuleDetailsUrl,
getDetectionEngineUrl,
} from '../../../../common/components/link_to/redirect_to_detection_engine';
import { displaySuccessToast, useStateToaster } from '../../../../common/components/toasters';
import { SpyRoute } from '../../../../common/utils/route/spy_routes';
import { useUserData } from '../../../../detections/components/user_info';
import { StepPanel } from '../../../rule_creation/components/step_panel';
Expand Down Expand Up @@ -73,7 +73,7 @@ import { CustomHeaderPageMemo } from '..';
import { SaveWithErrorsModal } from '../../components/save_with_errors_confirmation';

const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
const [, dispatchToaster] = useStateToaster();
const { addSuccess } = useAppToasts();
const [
{
loading: userInfoLoading,
Expand Down Expand Up @@ -394,7 +394,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {

const saveChanges = useCallback(async () => {
startTransaction({ name: SINGLE_RULE_ACTIONS.SAVE });
await updateRule({
const updatedRule = await updateRule({
...formatRule<RuleUpdateProps>(
defineStepData,
aboutStepData,
Expand All @@ -406,19 +406,18 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
...(ruleId ? { id: ruleId } : {}),
});

displaySuccessToast(i18n.SUCCESSFULLY_SAVED_RULE(rule?.name ?? ''), dispatchToaster);
addSuccess(i18n.SUCCESSFULLY_SAVED_RULE(updatedRule?.name ?? ''));
navigateToApp(APP_UI_ID, {
deepLinkId: SecurityPageName.rules,
path: getRuleDetailsUrl(ruleId ?? ''),
});
}, [
aboutStepData,
actionsStepData,
addSuccess,
defineStepData,
dispatchToaster,
navigateToApp,
rule?.exceptions_list,
rule?.name,
ruleId,
scheduleStepData,
startTransaction,
Expand Down