-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Fleet] Add Copy integration policy feature #249592
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e374530
[Fleet] Add Copy integration policy feature
nchaulet b8c5ec8
fix linting
nchaulet 1829fe0
fix TODO
nchaulet ac87fbd
Add tests
nchaulet f47d63f
fix breadcrumb
nchaulet 3c0f6d2
fix breadcrumb
nchaulet 2823842
fix breadcrumbs
nchaulet 3947f02
Merge branch 'main' of github.com:elastic/kibana into feature-fleet-c…
nchaulet c1e604f
fix tooltip
nchaulet 0641dcb
fix breadcrumbs
nchaulet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
.../fleet/public/applications/fleet/sections/agent_policy/copy_package_policy_page/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import React, { useMemo, memo } from 'react'; | ||
| import { useRouteMatch, useLocation } from 'react-router-dom'; | ||
|
|
||
| import { EuiEmptyPrompt, EuiFlexGroup } from '@elastic/eui'; | ||
| import { FormattedMessage } from '@kbn/i18n-react'; | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| import { EXCLUDED_FROM_PACKAGE_POLICY_COPY_PACKAGES } from '../../../../../../common/constants'; | ||
|
|
||
| import { useGetOnePackagePolicy } from '../../../../integrations/hooks'; | ||
| import { Loading } from '../../../components'; | ||
| import type { EditPackagePolicyFrom } from '../create_package_policy_page/types'; | ||
|
|
||
| import { CreatePackagePolicySinglePage } from '../create_package_policy_page/single_page_layout'; | ||
| import { useBreadcrumbs, useGetOneAgentPolicy } from '../../../hooks'; | ||
| import { useBreadcrumbs as useIntegrationsBreadcrumbs } from '../../../../integrations/hooks'; | ||
|
|
||
| const ContentWrapper = styled(EuiFlexGroup)` | ||
| height: 100%; | ||
| margin: 0 auto; | ||
| `; | ||
|
|
||
| const IntegrationsBreadcrumb = memo<{ | ||
| pkgTitle: string; | ||
| policyName: string; | ||
| pkgkey: string; | ||
| }>(({ pkgTitle, policyName, pkgkey }) => { | ||
| useIntegrationsBreadcrumbs('integration_policy_copy', { policyName, pkgTitle, pkgkey }); | ||
| return null; | ||
| }); | ||
|
|
||
| const PoliciesBreadcrumb: React.FunctionComponent<{ | ||
| policyName: string; | ||
| policyId: string; | ||
| }> = ({ policyName, policyId }) => { | ||
| useBreadcrumbs('copy_integration', { policyName, policyId }); | ||
| return null; | ||
| }; | ||
|
|
||
| const InstalledIntegrationsBreadcrumb = memo<{ | ||
| policyName: string; | ||
| }>(({ policyName }) => { | ||
| useIntegrationsBreadcrumbs('integration_policy_copy_from_installed', { policyName }); | ||
| return null; | ||
| }); | ||
|
|
||
| export const CopyPackagePolicyPage = memo(() => { | ||
| const { | ||
| params: { packagePolicyId, policyId }, | ||
| } = useRouteMatch<{ packagePolicyId: string; policyId?: string }>(); | ||
|
|
||
| const packagePolicy = useGetOnePackagePolicy(packagePolicyId); | ||
| const agentPolicy = useGetOneAgentPolicy(policyId); | ||
|
|
||
| const packagePolicyData = useMemo(() => { | ||
| if (packagePolicy.data?.item) { | ||
| return { | ||
| ...packagePolicy.data.item, | ||
| name: 'copy-' + packagePolicy.data.item.name, | ||
| }; | ||
| } | ||
| }, [packagePolicy.data?.item]); | ||
|
|
||
| // Parse the 'from' query parameter to determine navigation after save | ||
| const { search } = useLocation(); | ||
|
|
||
| const from = useMemo(() => { | ||
| const qs = new URLSearchParams(search); | ||
| const qsFrom = (qs.get('from') as EditPackagePolicyFrom | null) ?? 'fleet-policy-list'; | ||
|
|
||
| if (qsFrom === 'fleet-policy-list') { | ||
| return 'copy-from-fleet-policy-list'; | ||
| } else if (qsFrom === 'installed-integrations') { | ||
| return 'copy-from-installed-integrations'; | ||
| } else { | ||
| return 'copy-from-integrations-policy-list'; | ||
| } | ||
| }, [search]); | ||
|
|
||
| if (packagePolicy.isLoading || !packagePolicy.data) { | ||
| return ( | ||
| <> | ||
| <Loading /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| const breadcrumb = | ||
| from === 'copy-from-fleet-policy-list' && policyId ? ( | ||
| <PoliciesBreadcrumb policyName={agentPolicy.data?.item?.name || ''} policyId={policyId} /> | ||
| ) : from === 'copy-from-installed-integrations' ? ( | ||
| <InstalledIntegrationsBreadcrumb policyName={packagePolicy.data?.item?.name || ''} /> | ||
| ) : ( | ||
| <IntegrationsBreadcrumb | ||
| pkgTitle={packagePolicy.data?.item?.package?.title || ''} | ||
| policyName={packagePolicy.data?.item?.name || ''} | ||
| pkgkey={packagePolicy.data?.item?.package?.name || ''} | ||
| /> | ||
| ); | ||
|
|
||
| const pkgName = packagePolicy.data?.item?.package?.name; | ||
|
|
||
| if (pkgName && EXCLUDED_FROM_PACKAGE_POLICY_COPY_PACKAGES.includes(pkgName)) { | ||
| return ( | ||
| <ContentWrapper> | ||
| {breadcrumb} | ||
| <EuiEmptyPrompt | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.fleet.copyPackagePolicyPage.notAllowedTitle" | ||
| defaultMessage="Copying this integration policy is not allowed." | ||
| /> | ||
| } | ||
| color="danger" | ||
| iconType="error" | ||
| /> | ||
| </ContentWrapper> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {breadcrumb} | ||
| <CreatePackagePolicySinglePage | ||
| from={from} | ||
| pkgName={packagePolicy.data!.item!.package!.name} | ||
| pkgVersion={packagePolicy.data!.item!.package!.version} | ||
| defaultPolicyData={packagePolicyData} | ||
| noBreadcrumb={true} | ||
| prerelease={true} | ||
| /> | ||
| </> | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.