Skip to content

Commit

Permalink
[8.10] [Defend Workflows]Changes to policy settings are not persisten…
Browse files Browse the repository at this point in the history
…t until a refresh (#164403) (#164557)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Defend Workflows]Changes to policy settings are not persistent until
a refresh (#164403)](#164403)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Konrad
Szwarc","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-23T10:46:04Z","message":"[Defend
Workflows]Changes to policy settings are not persistent until a refresh
(#164403)\n\nCloses
https://github.com/elastic/security-team/issues/7386\r\n\r\nDispatch an
action that will update the stored policy upon successful\r\nsaving of
Policy Settings. This should occur only when no 'routeState'\r\nis being
set, as in such a scenario, a page change triggers a refetch on\r\nits
own.\r\n\r\nEven though redux was removed from Policy Settings
in\r\nhttps://github.com//pull/161511 , the policy object
that\r\nfeeds the view is being fetched as a result of onUrlChange
action and\r\nstored in the redux store. This should be addressed in the
future.\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/29123534/cf008d0e-804a-49f9-a2f7-9bb7d1162b28","sha":"5eca8618eab9e6f35b1d13d9c6ae8b1df598ad5c","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Defend
Workflows","v8.10.0","v8.11.0"],"number":164403,"url":"https://github.com/elastic/kibana/pull/164403","mergeCommit":{"message":"[Defend
Workflows]Changes to policy settings are not persistent until a refresh
(#164403)\n\nCloses
https://github.com/elastic/security-team/issues/7386\r\n\r\nDispatch an
action that will update the stored policy upon successful\r\nsaving of
Policy Settings. This should occur only when no 'routeState'\r\nis being
set, as in such a scenario, a page change triggers a refetch on\r\nits
own.\r\n\r\nEven though redux was removed from Policy Settings
in\r\nhttps://github.com//pull/161511 , the policy object
that\r\nfeeds the view is being fetched as a result of onUrlChange
action and\r\nstored in the redux store. This should be addressed in the
future.\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/29123534/cf008d0e-804a-49f9-a2f7-9bb7d1162b28","sha":"5eca8618eab9e6f35b1d13d9c6ae8b1df598ad5c"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164403","number":164403,"mergeCommit":{"message":"[Defend
Workflows]Changes to policy settings are not persistent until a refresh
(#164403)\n\nCloses
https://github.com/elastic/security-team/issues/7386\r\n\r\nDispatch an
action that will update the stored policy upon successful\r\nsaving of
Policy Settings. This should occur only when no 'routeState'\r\nis being
set, as in such a scenario, a page change triggers a refetch on\r\nits
own.\r\n\r\nEven though redux was removed from Policy Settings
in\r\nhttps://github.com//pull/161511 , the policy object
that\r\nfeeds the view is being fetched as a result of onUrlChange
action and\r\nstored in the redux store. This should be addressed in the
future.\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/29123534/cf008d0e-804a-49f9-a2f7-9bb7d1162b28","sha":"5eca8618eab9e6f35b1d13d9c6ae8b1df598ad5c"}}]}]
BACKPORT-->

Co-authored-by: Konrad Szwarc <[email protected]>
  • Loading branch information
kibanamachine and szwarckonrad authored Aug 23, 2023
1 parent 09719cb commit 4960389
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 4960389

Please sign in to comment.