Skip to content

Commit 85ae533

Browse files
committed
Fixed console error, which appears when saving changes in Edit Alert flyout
1 parent 982639f commit 85ae533

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { useState, Fragment, useEffect } from 'react';
7+
import React, { useState, Fragment, useEffect, useReducer } from 'react';
88
import { keyBy } from 'lodash';
99
import { useHistory } from 'react-router-dom';
1010
import {
@@ -41,6 +41,7 @@ import { AlertEdit } from '../../alert_form';
4141
import { AlertsContextProvider } from '../../../context/alerts_context';
4242
import { routeToAlertDetails } from '../../../constants';
4343
import { alertsErrorReasonTranslationsMapping } from '../../alerts_list/translations';
44+
import { alertReducer } from '../../alert_form/alert_reducer';
4445

4546
type AlertDetailsProps = {
4647
alert: Alert;
@@ -73,6 +74,10 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
7374
setBreadcrumbs,
7475
chrome,
7576
} = useAppDependencies();
77+
const [{}, dispatch] = useReducer(alertReducer, { alert });
78+
const setInitialAlert = (key: string, value: any) => {
79+
dispatch({ command: { type: 'setAlert' }, payload: { key, value } });
80+
};
7681

7782
// Set breadcrumb and page title
7883
useEffect(() => {
@@ -166,7 +171,10 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
166171
>
167172
<AlertEdit
168173
initialAlert={alert}
169-
onClose={() => setEditFlyoutVisibility(false)}
174+
onClose={() => {
175+
setInitialAlert('alert', alert);
176+
setEditFlyoutVisibility(false);
177+
}}
170178
/>
171179
</AlertsContextProvider>
172180
)}

x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
import React, { Fragment, useCallback, useReducer, useState } from 'react';
6+
import React, { Fragment, useReducer, useState } from 'react';
77
import { FormattedMessage } from '@kbn/i18n/react';
88
import {
99
EuiTitle,
@@ -40,9 +40,6 @@ export const AlertEdit = ({ initialAlert, onClose }: AlertEditProps) => {
4040
const [hasActionsWithBrokenConnector, setHasActionsWithBrokenConnector] = useState<boolean>(
4141
false
4242
);
43-
const setAlert = (key: string, value: any) => {
44-
dispatch({ command: { type: 'setAlert' }, payload: { key, value } });
45-
};
4643

4744
const {
4845
reloadAlerts,
@@ -53,12 +50,6 @@ export const AlertEdit = ({ initialAlert, onClose }: AlertEditProps) => {
5350
docLinks,
5451
} = useAlertsContext();
5552

56-
const closeFlyout = useCallback(() => {
57-
onClose();
58-
setAlert('alert', initialAlert);
59-
// eslint-disable-next-line react-hooks/exhaustive-deps
60-
}, [onClose]);
61-
6253
const alertType = alertTypeRegistry.get(alert.alertTypeId);
6354

6455
const errors = {
@@ -105,7 +96,7 @@ export const AlertEdit = ({ initialAlert, onClose }: AlertEditProps) => {
10596
return (
10697
<EuiPortal>
10798
<EuiFlyout
108-
onClose={closeFlyout}
99+
onClose={() => onClose()}
109100
aria-labelledby="flyoutAlertEditTitle"
110101
size="m"
111102
maxWidth={620}
@@ -155,7 +146,7 @@ export const AlertEdit = ({ initialAlert, onClose }: AlertEditProps) => {
155146
<EuiFlexItem grow={false}>
156147
<EuiButtonEmpty
157148
data-test-subj="cancelSaveEditedAlertButton"
158-
onClick={closeFlyout}
149+
onClick={() => onClose()}
159150
>
160151
{i18n.translate(
161152
'xpack.triggersActionsUI.sections.alertEdit.cancelButtonLabel',
@@ -179,7 +170,7 @@ export const AlertEdit = ({ initialAlert, onClose }: AlertEditProps) => {
179170
const savedAlert = await onSaveAlert();
180171
setIsSaving(false);
181172
if (savedAlert) {
182-
closeFlyout();
173+
onClose();
183174
if (reloadAlerts) {
184175
reloadAlerts();
185176
}

0 commit comments

Comments
 (0)