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

[Fleet] Fix package edit redirect #174531

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
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 @@ -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
Loading