Skip to content

Commit

Permalink
[8.12] [Fleet] Fix package edit redirect (#174531) (#174839)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.12`:
- [[Fleet] Fix package edit redirect
(#174531)](#174531)

<!--- Backport version: 8.9.8 -->

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

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-01-09T20:05:01Z","message":"[Fleet]
Fix package edit redirect
(#174531)","sha":"66aa37444a16c5d40523b9cae3267983dd20a9db","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:skip","Team:Fleet","v8.13.0"],"number":174531,"url":"https://github.com/elastic/kibana/pull/174531","mergeCommit":{"message":"[Fleet]
Fix package edit redirect
(#174531)","sha":"66aa37444a16c5d40523b9cae3267983dd20a9db"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/174531","number":174531,"mergeCommit":{"message":"[Fleet]
Fix package edit redirect
(#174531)","sha":"66aa37444a16c5d40523b9cae3267983dd20a9db"}}]}]
BACKPORT-->

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
nchaulet and kibanamachine authored Jan 15, 2024
1 parent ba30fb7 commit 73b1a19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
return canWriteIntegrationPolicies ? (
<PackagePolicyActionsMenu
agentPolicy={agentPolicy}
from={'fleet-policy-list'}
packagePolicy={packagePolicy}
upgradePackagePolicyHref={`${getHref('upgrade_package_policy', {
policyId: agentPolicy.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,41 @@
*/

import React, { memo } from 'react';
import { useRouteMatch } from 'react-router-dom';
import { useLocation, useRouteMatch } from 'react-router-dom';

// TODO: Needs to be moved
import { EditPackagePolicyForm } from '../../../../../fleet/sections/agent_policy/edit_package_policy_page';
import type { EditPackagePolicyFrom } from '../../../../../fleet/sections/agent_policy/create_package_policy_page/types';
import { useGetOnePackagePolicyQuery, useUIExtension } from '../../../../hooks';

export const Policy = memo(() => {
const {
params: { packagePolicyId },
} = useRouteMatch<{ packagePolicyId: string }>();

const { search } = useLocation();
const { data: packagePolicyData } = useGetOnePackagePolicyQuery(packagePolicyId);

const extensionView = useUIExtension(
packagePolicyData?.item?.package?.name ?? '',
'package-policy-edit'
);

const qs = new URLSearchParams(search);
const fromQs = qs.get('from');

let from: EditPackagePolicyFrom | undefined;

if (fromQs && fromQs === 'fleet-policy-list') {
from = 'edit';
} else {
from = 'package-edit';
}

return (
<EditPackagePolicyForm
packagePolicyId={packagePolicyId}
from="package-edit"
from={from}
forceUpgrade={extensionView?.useLatestPackageVersion}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export const PackagePolicyActionsMenu: React.FunctionComponent<{
showAddAgent?: boolean;
defaultIsOpen?: boolean;
upgradePackagePolicyHref?: string;
from?: 'fleet-policy-list' | undefined;
}> = ({
agentPolicy,
packagePolicy,
showAddAgent,
upgradePackagePolicyHref,
defaultIsOpen = false,
from,
}) => {
const [isEnrollmentFlyoutOpen, setIsEnrollmentFlyoutOpen] = useState(false);
const { getHref } = useLink();
Expand Down Expand Up @@ -80,9 +82,9 @@ export const PackagePolicyActionsMenu: React.FunctionComponent<{
data-test-subj="PackagePolicyActionsEditItem"
disabled={!canWriteIntegrationPolicies || !agentPolicy}
icon="pencil"
href={getHref('integration_policy_edit', {
href={`${getHref('integration_policy_edit', {
packagePolicyId: packagePolicy.id,
})}
})}${from ? `?from=${from}` : ''}`}
key="packagePolicyEdit"
>
<FormattedMessage
Expand Down

0 comments on commit 73b1a19

Please sign in to comment.