Skip to content

Commit 46dd2d0

Browse files
committed
[Defend Workflows]Changes to policy settings are not persistent until a refresh (#164403)
Closes elastic/security-team#7386 Dispatch an action that will update the stored policy upon successful saving of Policy Settings. This should occur only when no 'routeState' is being set, as in such a scenario, a page change triggers a refetch on its own. Even though redux was removed from Policy Settings in #161511 , the policy object that feeds the view is being fetched as a result of onUrlChange action and stored in the redux store. This should be addressed in the future. https://github.com/elastic/kibana/assets/29123534/cf008d0e-804a-49f9-a2f7-9bb7d1162b28 (cherry picked from commit 5eca861)
1 parent 92e708f commit 46dd2d0

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

x-pack/plugins/security_solution/public/management/pages/policy/view/policy_settings_layout/policy_settings_layout.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

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

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

110112
if (routeState && routeState.onSaveNavigateTo) {
111113
navigateToApp(...routeState.onSaveNavigateTo);
114+
} else {
115+
// 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.
116+
dispatch({
117+
type: 'serverReturnedPolicyDetailsData',
118+
payload: {
119+
policyItem,
120+
},
121+
});
112122
}
113123
})
114124
.catch((err) => {
@@ -123,6 +133,7 @@ export const PolicySettingsLayout = memo<PolicySettingsLayoutProps>(({ policy: _
123133

124134
handleSaveCancel();
125135
}, [
136+
dispatch,
126137
handleSaveCancel,
127138
navigateToApp,
128139
policy,

0 commit comments

Comments
 (0)