Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.10] [Defend Workflows]Changes to policy settings are not persistent until a refresh (#164403) #164557

Merged
merged 2 commits into from
Aug 23, 2023
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