Skip to content

Commit

Permalink
Fix edit alert flyout to update initialAlert after edit (#65359)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed May 9, 2020
1 parent 9a192da commit 155a268
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,27 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
defaultMessage="Edit"
/>
</EuiButtonEmpty>
<AlertsContextProvider
value={{
http,
actionTypeRegistry,
alertTypeRegistry,
toastNotifications,
uiSettings,
docLinks,
charts,
dataFieldsFormats: dataPlugin.fieldFormats,
reloadAlerts: setAlert,
capabilities,
}}
>
<AlertEdit
initialAlert={alert}
editFlyoutVisible={editFlyoutVisible}
setEditFlyoutVisibility={setEditFlyoutVisibility}
/>
</AlertsContextProvider>
{editFlyoutVisible && (
<AlertsContextProvider
value={{
http,
actionTypeRegistry,
alertTypeRegistry,
toastNotifications,
uiSettings,
docLinks,
charts,
dataFieldsFormats: dataPlugin.fieldFormats,
reloadAlerts: setAlert,
capabilities,
}}
>
<AlertEdit
initialAlert={alert}
onClose={() => setEditFlyoutVisibility(false)}
/>
</AlertsContextProvider>
)}
</Fragment>
</EuiFlexItem>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ describe('alert_edit', () => {
capabilities: deps!.capabilities,
}}
>
<AlertEdit
editFlyoutVisible={true}
setEditFlyoutVisibility={() => {}}
initialAlert={alert}
/>
<AlertEdit onClose={() => {}} initialAlert={alert} />
</AlertsContextProvider>
</AppContextProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ import { PLUGIN } from '../../constants/plugin';

interface AlertEditProps {
initialAlert: Alert;
editFlyoutVisible: boolean;
setEditFlyoutVisibility: React.Dispatch<React.SetStateAction<boolean>>;
onClose(): void;
}

export const AlertEdit = ({
initialAlert,
editFlyoutVisible,
setEditFlyoutVisibility,
}: AlertEditProps) => {
export const AlertEdit = ({ initialAlert, onClose }: AlertEditProps) => {
const [{ alert }, dispatch] = useReducer(alertReducer, { alert: initialAlert });
const [isSaving, setIsSaving] = useState<boolean>(false);
const [hasActionsDisabled, setHasActionsDisabled] = useState<boolean>(false);
Expand All @@ -57,14 +52,10 @@ export const AlertEdit = ({
} = useAlertsContext();

const closeFlyout = useCallback(() => {
setEditFlyoutVisibility(false);
onClose();
setAlert('alert', initialAlert);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setEditFlyoutVisibility]);

if (!editFlyoutVisible) {
return null;
}
}, [onClose]);

const alertType = alertTypeRegistry.get(alert.alertTypeId);

Expand Down

0 comments on commit 155a268

Please sign in to comment.