Skip to content

Commit

Permalink
[Defend Workflows]Changes to policy settings are not persistent until…
Browse files Browse the repository at this point in the history
… a refresh (elastic#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
elastic#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)
  • Loading branch information
szwarckonrad committed Aug 23, 2023
1 parent 92e708f commit 46dd2d0
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 46dd2d0

Please sign in to comment.