Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import type { ApplicationStart } from '@kbn/core-application-browser';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiButton, EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
Expand Down Expand Up @@ -42,6 +43,7 @@ export const PolicySettingsLayout = memo<PolicySettingsLayoutProps>(({ policy: _
},
} = useKibana();
const toasts = useToasts();
const dispatch = useDispatch();
const { state: locationRouteState } = useLocation<PolicyDetailsRouteState>();
const { canWritePolicyManagement } = useUserPrivileges().endpointPrivileges;
const { isLoading: isUpdating, mutateAsync: sendPolicyUpdate } = useUpdateEndpointPolicy();
Expand Down Expand Up @@ -89,7 +91,7 @@ export const PolicySettingsLayout = memo<PolicySettingsLayoutProps>(({ policy: _

update.inputs[0].config.policy.value = policySettings;
sendPolicyUpdate({ policy: update })
.then(() => {
.then(({ item: policyItem }) => {
toasts.addSuccess({
'data-test-subj': 'policyDetailsSuccessMessage',
title: i18n.translate(
Expand All @@ -109,6 +111,14 @@ export const PolicySettingsLayout = memo<PolicySettingsLayoutProps>(({ policy: _

if (routeState && routeState.onSaveNavigateTo) {
navigateToApp(...routeState.onSaveNavigateTo);
} else {
// Since the 'policyItem' is stored in a store and fetched as a result of an action on urlChange, we still need to dispatch an action even though Redux was removed from this component.
dispatch({
type: 'serverReturnedPolicyDetailsData',
payload: {
policyItem,
},
});
}
})
.catch((err) => {
Expand All @@ -123,6 +133,7 @@ export const PolicySettingsLayout = memo<PolicySettingsLayoutProps>(({ policy: _

handleSaveCancel();
}, [
dispatch,
handleSaveCancel,
navigateToApp,
policy,
Expand Down