Fleet UI: Fix policy automations from resetting automations on other pages (#16505)

This commit is contained in:
RachelElysia 2024-01-31 13:09:11 -05:00 committed by GitHub
parent 4416a68496
commit 3bdae3629d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View file

@ -0,0 +1 @@
- Fix a bug where policy automations when saved were resetting automations on other pages

View file

@ -225,11 +225,34 @@ const ManagePolicyAutomationsModal = ({
// newPolicyIds = [];
// }
const updatedEnabledPoliciesAcrossPages = () => {
if (webhook.policy_ids) {
// Array of policy ids on the page
const availablePoliciesIds = availablePolicies.map(
(policy) => policy.id
);
// Array of policy ids enabled NOT on the page
const enabledPoliciesOnOtherPages = webhook.policy_ids.filter(
(policyId) => !availablePoliciesIds.includes(policyId)
);
// Concatenate with array of policies enabled on the page
const allEnabledPolicies = enabledPoliciesOnOtherPages.concat(
newPolicyIds
);
return allEnabledPolicies;
}
return [];
};
// NOTE: backend uses webhook_settings to store automated policy ids for both webhooks and integrations
const newWebhook = {
failing_policies_webhook: {
destination_url: destinationUrl,
policy_ids: newPolicyIds,
policy_ids: updatedEnabledPoliciesAcrossPages(),
enable_failing_policies_webhook:
isPolicyAutomationsEnabled && isWebhookEnabled,
},