Skip to content

Commit

Permalink
[Fleet] Fix package edit redirect (elastic#174531)
Browse files Browse the repository at this point in the history
(cherry picked from commit 66aa374)
  • Loading branch information
nchaulet committed Jan 15, 2024
1 parent 9456432 commit 97a58bf
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 97a58bf

Please sign in to comment.