diff --git a/x-pack/plugins/fleet/public/applications/fleet/components/index.ts b/x-pack/plugins/fleet/public/applications/fleet/components/index.ts index ac5a78a4ea709..5e927c5b0e3d6 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/components/index.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/components/index.ts @@ -7,5 +7,4 @@ export * from '../../../components'; -export * from './enrollment_instructions'; export * from './search_bar'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx index bdf49f44f4397..798ed4f038156 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx @@ -11,8 +11,7 @@ import { EuiContextMenuItem, EuiPortal } from '@elastic/eui'; import type { AgentPolicy } from '../../../types'; import { useCapabilities } from '../../../hooks'; -import { ContextMenuActions } from '../../../components'; -import { AgentEnrollmentFlyout } from '../../agents/components'; +import { AgentEnrollmentFlyout, ContextMenuActions } from '../../../components'; import { AgentPolicyYamlFlyout } from './agent_policy_yaml_flyout'; import { AgentPolicyCopyProvider } from './agent_policy_copy_provider'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/index.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/index.ts index 09282a7de7cb9..439e474d416cb 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/index.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/index.ts @@ -11,8 +11,6 @@ export { LinkedAgentCount } from '../../../components'; export { AgentPolicyForm, agentPolicyFormValidation } from './agent_policy_form'; export { AgentPolicyCopyProvider } from './agent_policy_copy_provider'; export { AgentPolicyDeleteProvider } from './agent_policy_delete_provider'; -export { PackagePolicyDeleteProvider } from './package_policy_delete_provider'; export { AgentPolicyYamlFlyout } from './agent_policy_yaml_flyout'; export { ConfirmDeployAgentPolicyModal } from './confirm_deploy_modal'; -export { DangerEuiContextMenuItem } from './danger_eui_context_menu_item'; export { AgentPolicyActionMenu } from './actions_menu'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/package_policies/package_policies_table.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/package_policies/package_policies_table.tsx index 9e23fc775a213..2e6e7fb984ef0 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/package_policies/package_policies_table.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/package_policies/package_policies_table.tsx @@ -12,7 +12,6 @@ import type { EuiInMemoryTableProps } from '@elastic/eui'; import { EuiInMemoryTable, EuiBadge, - EuiContextMenuItem, EuiButton, EuiFlexGroup, EuiFlexItem, @@ -20,10 +19,8 @@ import { } from '@elastic/eui'; import type { AgentPolicy, PackagePolicy } from '../../../../../types'; -import { PackageIcon, ContextMenuActions } from '../../../../../components'; -import { PackagePolicyDeleteProvider, DangerEuiContextMenuItem } from '../../../components'; +import { PackageIcon, PackagePolicyActionsMenu } from '../../../../../components'; import { useCapabilities, useLink } from '../../../../../hooks'; -import { useAgentPolicyRefresh } from '../../hooks'; interface InMemoryPackagePolicy extends PackagePolicy { packageName?: string; @@ -54,7 +51,6 @@ export const PackagePoliciesTable: React.FunctionComponent = ({ }) => { const { getHref } = useLink(); const hasWriteCapabilities = useCapabilities().write; - const refreshAgentPolicy = useAgentPolicyRefresh(); // With the package policies provided on input, generate the list of package policies // used in the InMemoryTable (flattens some values for search) as well as @@ -168,71 +164,15 @@ export const PackagePoliciesTable: React.FunctionComponent = ({ actions: [ { render: (packagePolicy: InMemoryPackagePolicy) => { - const menuItems = [ - // FIXME: implement View package policy action - // {}} - // key="packagePolicyView" - // > - // - // , - - - , - // FIXME: implement Copy package policy action - // {}} key="packagePolicyCopy"> - // - // , - ]; - - if (!agentPolicy.is_managed) { - menuItems.push( - - {(deletePackagePoliciesPrompt) => { - return ( - { - deletePackagePoliciesPrompt([packagePolicy.id], refreshAgentPolicy); - }} - > - - - ); - }} - - ); - } - return ; + return ( + + ); }, }, ], }, ], - [agentPolicy, getHref, hasWriteCapabilities, refreshAgentPolicy] + [agentPolicy] ); return ( diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx index e91d32a78ec96..1ea1a7de53b95 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx @@ -20,13 +20,13 @@ import { sendUpdateAgentPolicy, useConfig, sendGetAgentStatus, + useAgentPolicyRefresh, } from '../../../../../hooks'; import { AgentPolicyForm, agentPolicyFormValidation, ConfirmDeployAgentPolicyModal, } from '../../../components'; -import { useAgentPolicyRefresh } from '../../hooks'; const FormWrapper = styled.div` max-width: 800px; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/hooks/index.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/hooks/index.ts index 07daef8bb2ced..fb269f95213d9 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/hooks/index.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/hooks/index.ts @@ -6,4 +6,3 @@ */ export { useGetAgentStatus, AgentStatusRefreshContext } from './use_agent_status'; -export { AgentPolicyRefreshContext, useAgentPolicyRefresh } from './use_config'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/index.tsx index 7138abb081a77..9d3fe64b6639d 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/index.tsx @@ -28,6 +28,7 @@ import styled from 'styled-components'; import type { AgentPolicy, AgentPolicyDetailsDeployAgentAction } from '../../../types'; import { FLEET_ROUTING_PATHS } from '../../../constants'; import { + AgentPolicyRefreshContext, useGetOneAgentPolicy, useLink, useBreadcrumbs, @@ -39,7 +40,7 @@ import { Loading, Error } from '../../../components'; import { WithHeaderLayout } from '../../../layouts'; import { LinkedAgentCount, AgentPolicyActionMenu } from '../components'; -import { AgentPolicyRefreshContext, useGetAgentStatus, AgentStatusRefreshContext } from './hooks'; +import { useGetAgentStatus, AgentStatusRefreshContext } from './hooks'; import { PackagePoliciesView, SettingsView } from './components'; const Divider = styled.div` diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_overview.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_overview.tsx index 540b06d7a9786..fb80611e5295c 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_overview.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_overview.tsx @@ -23,8 +23,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import type { Agent, AgentPolicy } from '../../../../../types'; import { useKibanaVersion } from '../../../../../hooks'; import { isAgentUpgradeable } from '../../../../../services'; -import { AgentPolicyPackageBadges } from '../../../components/agent_policy_package_badges'; -import { AgentPolicySummaryLine } from '../../../../../components'; +import { AgentPolicyPackageBadges, AgentPolicySummaryLine } from '../../../../../components'; // Allows child text to be truncated const FlexItemWithMinWidth = styled(EuiFlexItem)` diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx index 70cb6cddad5fa..672b8718c9cbe 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx @@ -22,7 +22,6 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage, FormattedRelative } from '@kbn/i18n/react'; -import { AgentEnrollmentFlyout } from '../components'; import type { Agent, AgentPolicy, SimplifiedAgentStatus } from '../../../types'; import { usePagination, @@ -37,7 +36,11 @@ import { useKibanaVersion, useStartServices, } from '../../../hooks'; -import { AgentPolicySummaryLine, ContextMenuActions } from '../../../components'; +import { + AgentEnrollmentFlyout, + AgentPolicySummaryLine, + ContextMenuActions, +} from '../../../components'; import { AgentStatusKueryHelper, isAgentUpgradeable } from '../../../services'; import { AGENT_SAVED_OBJECT_TYPE } from '../../../constants'; import { diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_requirements_page/fleet_server_requirement_page.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_requirements_page/fleet_server_requirement_page.tsx index 83f09789a9414..20d366b01af2b 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_requirements_page/fleet_server_requirement_page.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_requirements_page/fleet_server_requirement_page.tsx @@ -26,10 +26,15 @@ import styled from 'styled-components'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { DownloadStep } from '../components/agent_enrollment_flyout/steps'; -import { useStartServices, useGetOutputs, sendGenerateServiceToken } from '../../../hooks'; -import { PLATFORM_OPTIONS, usePlatform } from '../hooks/use_platform'; -import type { PLATFORM_TYPE } from '../hooks/use_platform'; +import { DownloadStep } from '../../../components'; +import { + useStartServices, + useGetOutputs, + sendGenerateServiceToken, + usePlatform, + PLATFORM_OPTIONS, +} from '../../../hooks'; +import type { PLATFORM_TYPE } from '../../../hooks'; const FlexItemWithMinWidth = styled(EuiFlexItem)` min-width: 0px; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_reassign_policy_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_reassign_policy_modal/index.tsx index 8ee401d3c4ddf..f15b58200ea88 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_reassign_policy_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_reassign_policy_modal/index.tsx @@ -24,7 +24,7 @@ import { useStartServices, useGetAgentPolicies, } from '../../../../hooks'; -import { AgentPolicyPackageBadges } from '../agent_policy_package_badges'; +import { AgentPolicyPackageBadges } from '../../../../components'; interface Props { onClose: () => void; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/index.tsx index 45f09c79d5533..966a777941373 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/index.tsx @@ -7,7 +7,6 @@ export * from './loading'; export * from './agent_reassign_policy_modal'; -export * from './agent_enrollment_flyout'; export * from './agent_health'; export * from './agent_unenroll_modal'; export * from './agent_upgrade_modal'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/list_layout.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/list_layout.tsx index 40642587c1a38..67758282521b7 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/list_layout.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/list_layout.tsx @@ -14,7 +14,7 @@ import { useRouteMatch } from 'react-router-dom'; import { FLEET_ROUTING_PATHS } from '../../../constants'; import { WithHeaderLayout } from '../../../layouts'; import { useCapabilities, useLink, useGetAgentPolicies } from '../../../hooks'; -import { AgentEnrollmentFlyout } from '../components'; +import { AgentEnrollmentFlyout } from '../../../components'; export const ListLayout: React.FunctionComponent<{}> = ({ children }) => { const { getHref } = useLink(); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx index 66e0c338dbbbc..8dc9ad33962e0 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx @@ -22,6 +22,7 @@ import { import { FormattedMessage, FormattedDate } from '@kbn/i18n/react'; import { ENROLLMENT_API_KEYS_INDEX } from '../../../constants'; +import { NewEnrollmentTokenModal } from '../../../components'; import { useBreadcrumbs, usePagination, @@ -34,7 +35,6 @@ import { import type { EnrollmentAPIKey, GetAgentPoliciesResponseItem } from '../../../types'; import { SearchBar } from '../../../components/search_bar'; -import { NewEnrollmentTokenModal } from './components/new_enrollment_key_modal'; import { ConfirmEnrollmentTokenDelete } from './components/confirm_delete_modal'; const ApiKeyField: React.FunctionComponent<{ apiKeyId: string }> = ({ apiKeyId }) => { diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/hooks/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/hooks/index.tsx deleted file mode 100644 index d9b3bcd80752d..0000000000000 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/hooks/index.tsx +++ /dev/null @@ -1,8 +0,0 @@ -/* - * 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. - */ - -export * from './use_platform'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/overview/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/overview/index.tsx index 9da10c1de2be0..f905fd1c89da2 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/overview/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/overview/index.tsx @@ -20,7 +20,7 @@ import { i18n } from '@kbn/i18n'; import { WithHeaderLayout } from '../../layouts'; import { useGetAgentPolicies, useBreadcrumbs } from '../../hooks'; -import { AgentEnrollmentFlyout } from '../agents/components'; +import { AgentEnrollmentFlyout } from '../../components'; import { OverviewAgentSection } from './components/agent_section'; import { OverviewPolicySection } from './components/agent_policy_section'; diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/index.test.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/index.test.tsx index 3477335321a2c..04253994d3875 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/index.test.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/index.test.tsx @@ -202,12 +202,30 @@ describe('when on integration detail', () => { expect(firstRowAgentCount.tagName).not.toEqual('A'); }); + it('should show add agent button if agent count is zero', async () => { + await mockedApi.waitForApi(); + const firstRowAgentCount = renderResult.getAllByTestId('rowAgentCount')[0]; + expect(firstRowAgentCount.textContent).toEqual('0'); + + const addAgentButton = renderResult.getAllByTestId('addAgentButton')[0]; + expect(addAgentButton).not.toBeNull(); + }); + it('should show link for agent count if greater than zero', async () => { await mockedApi.waitForApi(); const secondRowAgentCount = renderResult.getAllByTestId('rowAgentCount')[1]; expect(secondRowAgentCount.textContent).toEqual('100'); expect(secondRowAgentCount.tagName).toEqual('A'); }); + + it('should NOT show add agent button if agent count is greater than zero', async () => { + await mockedApi.waitForApi(); + const secondRowAgentCount = renderResult.getAllByTestId('rowAgentCount')[1]; + expect(secondRowAgentCount.textContent).toEqual('100'); + + const addAgentButton = renderResult.getAllByTestId('addAgentButton')[1]; + expect(addAgentButton).toBeUndefined(); + }); }); }); diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/policies/package_policies.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/policies/package_policies.tsx index d5dce6334762c..7da7328fdebbc 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/policies/package_policies.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/policies/package_policies.tsx @@ -5,23 +5,44 @@ * 2.0. */ -import React, { memo, useCallback, useMemo } from 'react'; +import React, { memo, useCallback, useMemo, useState } from 'react'; import { Redirect } from 'react-router-dom'; import type { CriteriaWithPagination, EuiTableFieldDataColumnType } from '@elastic/eui'; -import { EuiBasicTable, EuiLink, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { + EuiButtonIcon, + EuiBasicTable, + EuiLink, + EuiFlexGroup, + EuiFlexItem, + EuiToolTip, +} from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedRelative, FormattedMessage } from '@kbn/i18n/react'; +import styled from 'styled-components'; import { InstallStatus } from '../../../../../types'; -import { useLink, useUrlPagination, useGetPackageInstallStatus } from '../../../../../hooks'; +import { + useLink, + useUrlPagination, + useGetPackageInstallStatus, + AgentPolicyRefreshContext, +} from '../../../../../hooks'; import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../../constants'; -import { AgentPolicySummaryLine } from '../../../../../components'; -import { LinkedAgentCount } from '../../../../../components'; +import { + AgentEnrollmentFlyout, + AgentPolicySummaryLine, + LinkedAgentCount, + PackagePolicyActionsMenu, +} from '../../../../../components'; import type { PackagePolicyAndAgentPolicy } from './use_package_policies_with_agent_policy'; import { usePackagePoliciesWithAgentPolicy } from './use_package_policies_with_agent_policy'; import { Persona } from './persona'; +const AddAgentButton = styled(EuiButtonIcon)` + margin-left: ${(props) => props.theme.eui.euiSizeS}; +`; + const IntegrationDetailsLink = memo<{ packagePolicy: PackagePolicyAndAgentPolicy['packagePolicy']; }>(({ packagePolicy }) => { @@ -39,16 +60,18 @@ const IntegrationDetailsLink = memo<{ ); }); + interface PackagePoliciesPanelProps { name: string; version: string; } export const PackagePoliciesPage = ({ name, version }: PackagePoliciesPanelProps) => { + const [flyoutOpenForPolicyId, setFlyoutOpenForPolicyId] = useState(null); const { getPath } = useLink(); const getPackageInstallStatus = useGetPackageInstallStatus(); const packageInstallStatus = getPackageInstallStatus(name); const { pagination, pageSizeOptions, setPagination } = useUrlPagination(); - const { data, isLoading } = usePackagePoliciesWithAgentPolicy({ + const { data, isLoading, resendRequest: refreshPolicies } = usePackagePoliciesWithAgentPolicy({ page: pagination.currentPage, perPage: pagination.pageSize, kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: ${name}`, @@ -97,16 +120,36 @@ export const PackagePoliciesPage = ({ name, version }: PackagePoliciesPanelProps defaultMessage: 'Agents', }), truncateText: true, - align: 'right', + align: 'left', width: '8ch', render({ packagePolicy, agentPolicy }: PackagePolicyAndAgentPolicy) { + const count = agentPolicy?.agents ?? 0; + return ( - + <> + + {count === 0 && ( + + setFlyoutOpenForPolicyId(agentPolicy.id)} + data-test-subj="addAgentButton" + /> + + )} + ); }, }, @@ -134,6 +177,19 @@ export const PackagePoliciesPage = ({ name, version }: PackagePoliciesPanelProps ); }, }, + { + field: '', + name: i18n.translate('xpack.fleet.epm.packageDetails.integrationList.actions', { + defaultMessage: 'Actions', + }), + width: '8ch', + align: 'right', + render({ agentPolicy, packagePolicy }) { + return ( + + ); + }, + }, ], [] ); @@ -165,19 +221,31 @@ export const PackagePoliciesPage = ({ name, version }: PackagePoliciesPanelProps } return ( - - - - + + + + + + + {flyoutOpenForPolicyId && ( + setFlyoutOpenForPolicyId(null)} + agentPolicies={ + data?.items + .filter(({ agentPolicy }) => agentPolicy.id === flyoutOpenForPolicyId) + .map(({ agentPolicy }) => agentPolicy) ?? [] + } /> - - + )} + ); }; diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/policies/use_package_policies_with_agent_policy.ts b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/policies/use_package_policies_with_agent_policy.ts index aae43a1acd568..33c1d3ff77302 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/policies/use_package_policies_with_agent_policy.ts +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/policies/use_package_policies_with_agent_policy.ts @@ -43,11 +43,13 @@ export const usePackagePoliciesWithAgentPolicy = ( isLoading: boolean; error: Error | null; data?: GetPackagePoliciesWithAgentPolicy; + resendRequest: () => void; } => { const { data: packagePoliciesData, error, isLoading: isLoadingPackagePolicies, + resendRequest, } = useGetPackagePolicies(query); const agentPoliciesFilter = useMemo(() => { @@ -124,5 +126,6 @@ export const usePackagePoliciesWithAgentPolicy = ( data: enrichedData, error, isLoading: isLoadingPackagePolicies || isLoadingAgentPolicies, + resendRequest, }; }; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/agent_policy_selection.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/agent_policy_selection.tsx similarity index 98% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/agent_policy_selection.tsx rename to x-pack/plugins/fleet/public/components/agent_enrollment_flyout/agent_policy_selection.tsx index 4edc1121b1091..dc239213baf36 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/agent_policy_selection.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/agent_policy_selection.tsx @@ -10,13 +10,13 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButtonEmpty, EuiButton, EuiCallOut, EuiSelect, EuiSpacer, EuiText } from '@elastic/eui'; -import { SO_SEARCH_LIMIT } from '../../../../constants'; -import type { AgentPolicy, GetEnrollmentAPIKeysResponse } from '../../../../types'; +import { SO_SEARCH_LIMIT } from '../../constants'; +import type { AgentPolicy, GetEnrollmentAPIKeysResponse } from '../../types'; import { sendGetEnrollmentAPIKeys, useStartServices, sendCreateEnrollmentAPIKey, -} from '../../../../hooks'; +} from '../../hooks'; import { AgentPolicyPackageBadges } from '../agent_policy_package_badges'; type Props = { diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx similarity index 95% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/index.tsx rename to x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx index 1aa88dcef4adc..84f881e8baa0c 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/index.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx @@ -26,8 +26,8 @@ import { import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { useGetSettings, useUrlModal } from '../../../../hooks'; -import type { AgentPolicy } from '../../../../types'; +import { useGetSettings, useUrlModal } from '../../hooks'; +import type { AgentPolicy } from '../../types'; import { ManagedInstructions } from './managed_instructions'; import { StandaloneInstructions } from './standalone_instructions'; @@ -37,6 +37,11 @@ interface Props { agentPolicies?: AgentPolicy[]; } +export * from './agent_policy_selection'; +export * from './managed_instructions'; +export * from './standalone_instructions'; +export * from './steps'; + const MissingFleetServerHostCallout: React.FunctionComponent = () => { const { setModal } = useUrlModal(); return ( diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/managed_instructions.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/managed_instructions.tsx similarity index 91% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/managed_instructions.tsx rename to x-pack/plugins/fleet/public/components/agent_enrollment_flyout/managed_instructions.tsx index df1630abfab47..5f2e0d6e4c414 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/managed_instructions.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/managed_instructions.tsx @@ -11,22 +11,17 @@ import type { EuiContainedStepProps } from '@elastic/eui/src/components/steps/st import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import type { AgentPolicy } from '../../../../types'; -import { - useGetOneEnrollmentAPIKey, - useGetSettings, - useLink, - useFleetStatus, -} from '../../../../hooks'; -import { NewEnrollmentTokenModal } from '../../enrollment_token_list_page/components/new_enrollment_key_modal'; +import type { AgentPolicy } from '../../types'; +import { NewEnrollmentTokenModal } from '../../components'; +import { useGetOneEnrollmentAPIKey, useGetSettings, useLink, useFleetStatus } from '../../hooks'; -import { ManualInstructions } from '../../../../components/enrollment_instructions'; +import { ManualInstructions } from '../../components/enrollment_instructions'; import { FleetServerRequirementPage, ServiceTokenStep, FleetServerCommandStep, useFleetServerInstructions, -} from '../../agent_requirements_page'; +} from '../../applications/fleet/sections/agents/agent_requirements_page'; import { DownloadStep, AgentPolicySelectionStep } from './steps'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/standalone_instructions.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/standalone_instructions.tsx similarity index 98% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/standalone_instructions.tsx rename to x-pack/plugins/fleet/public/components/agent_enrollment_flyout/standalone_instructions.tsx index 1d830b2c578b1..0fd846b074f98 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/standalone_instructions.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/standalone_instructions.tsx @@ -22,9 +22,9 @@ import type { EuiContainedStepProps } from '@elastic/eui/src/components/steps/st import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import type { AgentPolicy } from '../../../../types'; -import { useStartServices, useLink, sendGetOneAgentPolicyFull } from '../../../../hooks'; -import { fullAgentPolicyToYaml, agentPolicyRouteService } from '../../../../services'; +import type { AgentPolicy } from '../../types'; +import { useStartServices, useLink, sendGetOneAgentPolicyFull } from '../../hooks'; +import { fullAgentPolicyToYaml, agentPolicyRouteService } from '../../services'; import { DownloadStep, AgentPolicySelectionStep } from './steps'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/steps.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps.tsx similarity index 94% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/steps.tsx rename to x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps.tsx index 8ba0098b3d277..fc22cbdd047c3 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_enrollment_flyout/steps.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps.tsx @@ -10,9 +10,9 @@ import { EuiText, EuiButton, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import type { AgentPolicy, PackagePolicy } from '../../../../types'; -import { sendGetOneAgentPolicy } from '../../../../hooks'; -import { FLEET_SERVER_PACKAGE } from '../../../../constants'; +import type { AgentPolicy, PackagePolicy } from '../../types'; +import { sendGetOneAgentPolicy } from '../../hooks'; +import { FLEET_SERVER_PACKAGE } from '../../constants'; import { EnrollmentStepAgentPolicy } from './agent_policy_selection'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_policy_package_badges.tsx b/x-pack/plugins/fleet/public/components/agent_policy_package_badges.tsx similarity index 94% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_policy_package_badges.tsx rename to x-pack/plugins/fleet/public/components/agent_policy_package_badges.tsx index 605888349ab4e..418e274022461 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_policy_package_badges.tsx +++ b/x-pack/plugins/fleet/public/components/agent_policy_package_badges.tsx @@ -10,11 +10,11 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiSpacer, EuiText, EuiFlexGroup, EuiFlexItem, EuiBadge, EuiCallOut } from '@elastic/eui'; -import { FLEET_SERVER_PACKAGE } from '../../../../../../common/constants'; +import { FLEET_SERVER_PACKAGE } from '../../common/constants'; -import type { PackagePolicy, PackagePolicyPackage } from '../../../types'; -import { useGetOneAgentPolicy } from '../../../hooks'; -import { PackageIcon } from '../../../components'; +import type { PackagePolicy, PackagePolicyPackage } from '../types'; +import { useGetOneAgentPolicy } from '../hooks'; +import { PackageIcon } from '../components'; interface Props { agentPolicyId: string; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/danger_eui_context_menu_item.tsx b/x-pack/plugins/fleet/public/components/danger_eui_context_menu_item.tsx similarity index 100% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/danger_eui_context_menu_item.tsx rename to x-pack/plugins/fleet/public/components/danger_eui_context_menu_item.tsx diff --git a/x-pack/plugins/fleet/public/applications/fleet/components/enrollment_instructions/index.tsx b/x-pack/plugins/fleet/public/components/enrollment_instructions/index.tsx similarity index 100% rename from x-pack/plugins/fleet/public/applications/fleet/components/enrollment_instructions/index.tsx rename to x-pack/plugins/fleet/public/components/enrollment_instructions/index.tsx diff --git a/x-pack/plugins/fleet/public/applications/fleet/components/enrollment_instructions/manual/index.tsx b/x-pack/plugins/fleet/public/components/enrollment_instructions/manual/index.tsx similarity index 95% rename from x-pack/plugins/fleet/public/applications/fleet/components/enrollment_instructions/manual/index.tsx rename to x-pack/plugins/fleet/public/components/enrollment_instructions/manual/index.tsx index c9f011c59504b..f746a1c914460 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/components/enrollment_instructions/manual/index.tsx +++ b/x-pack/plugins/fleet/public/components/enrollment_instructions/manual/index.tsx @@ -12,8 +12,8 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; import type { EnrollmentAPIKey } from '../../../types'; -import { PLATFORM_OPTIONS, usePlatform } from '../../../sections/agents/hooks/use_platform'; -import type { PLATFORM_TYPE } from '../../../sections/agents/hooks/use_platform'; +import { PLATFORM_OPTIONS, usePlatform } from '../../../hooks'; +import type { PLATFORM_TYPE } from '../../../hooks'; interface Props { fleetServerHosts: string[]; diff --git a/x-pack/plugins/fleet/public/components/index.ts b/x-pack/plugins/fleet/public/components/index.ts index 6db18c0e73a14..d054b96ccb4c6 100644 --- a/x-pack/plugins/fleet/public/components/index.ts +++ b/x-pack/plugins/fleet/public/components/index.ts @@ -13,5 +13,11 @@ export { ExtensionWrapper } from './extension_wrapper'; export { AlphaMessaging } from './alpha_messaging'; export { AlphaFlyout } from './alpha_flyout'; export { HeaderProps, Header } from './header'; +export { NewEnrollmentTokenModal } from './new_enrollment_key_modal'; +export { AgentPolicyPackageBadges } from './agent_policy_package_badges'; +export { DangerEuiContextMenuItem } from './danger_eui_context_menu_item'; +export { PackagePolicyDeleteProvider } from './package_policy_delete_provider'; +export { PackagePolicyActionsMenu } from './package_policy_actions_menu'; export * from './link_and_revision'; export * from './settings_flyout'; +export * from './agent_enrollment_flyout'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/components/new_enrollment_key_modal.tsx b/x-pack/plugins/fleet/public/components/new_enrollment_key_modal.tsx similarity index 97% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/components/new_enrollment_key_modal.tsx rename to x-pack/plugins/fleet/public/components/new_enrollment_key_modal.tsx index 29e130f5583ab..0752c1ab34889 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/components/new_enrollment_key_modal.tsx +++ b/x-pack/plugins/fleet/public/components/new_enrollment_key_modal.tsx @@ -9,8 +9,8 @@ import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiConfirmModal, EuiForm, EuiFormRow, EuiFieldText, EuiSelect } from '@elastic/eui'; -import type { AgentPolicy, EnrollmentAPIKey } from '../../../../types'; -import { useInput, useStartServices, sendCreateEnrollmentAPIKey } from '../../../../hooks'; +import type { AgentPolicy, EnrollmentAPIKey } from '../types'; +import { useInput, useStartServices, sendCreateEnrollmentAPIKey } from '../hooks'; function useCreateApiKeyForm( policyIdDefaultValue: string | undefined, diff --git a/x-pack/plugins/fleet/public/components/package_policy_actions_menu.tsx b/x-pack/plugins/fleet/public/components/package_policy_actions_menu.tsx new file mode 100644 index 0000000000000..03bf2095f7f3e --- /dev/null +++ b/x-pack/plugins/fleet/public/components/package_policy_actions_menu.tsx @@ -0,0 +1,112 @@ +/* + * 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, useState } from 'react'; +import { EuiContextMenuItem, EuiPortal } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; + +import type { AgentPolicy, PackagePolicy } from '../types'; + +import { useAgentPolicyRefresh, useCapabilities, useLink } from '../hooks'; + +import { AgentEnrollmentFlyout } from './agent_enrollment_flyout'; +import { ContextMenuActions } from './context_menu_actions'; +import { DangerEuiContextMenuItem } from './danger_eui_context_menu_item'; +import { PackagePolicyDeleteProvider } from './package_policy_delete_provider'; + +export const PackagePolicyActionsMenu: React.FunctionComponent<{ + agentPolicy: AgentPolicy; + packagePolicy: PackagePolicy; +}> = ({ agentPolicy, packagePolicy }) => { + const [isEnrollmentFlyoutOpen, setIsEnrollmentFlyoutOpen] = useState(false); + const { getHref } = useLink(); + const hasWriteCapabilities = useCapabilities().write; + const refreshAgentPolicy = useAgentPolicyRefresh(); + + const onEnrollmentFlyoutClose = useMemo(() => { + return () => setIsEnrollmentFlyoutOpen(false); + }, []); + + const menuItems = [ + // FIXME: implement View package policy action + // {}} + // key="packagePolicyView" + // > + // + // , + setIsEnrollmentFlyoutOpen(true)} + key="addAgent" + > + + , + + + , + // FIXME: implement Copy package policy action + // {}} key="packagePolicyCopy"> + // + // , + ]; + + if (!agentPolicy.is_managed) { + menuItems.push( + + {(deletePackagePoliciesPrompt) => { + return ( + { + deletePackagePoliciesPrompt([packagePolicy.id], refreshAgentPolicy); + }} + > + + + ); + }} + + ); + } + return ( + <> + {isEnrollmentFlyoutOpen && ( + + + + )} + + + ); +}; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/package_policy_delete_provider.tsx b/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx similarity index 98% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/package_policy_delete_provider.tsx rename to x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx index 198886e9b9c7f..86f064405497b 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/package_policy_delete_provider.tsx +++ b/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx @@ -10,9 +10,9 @@ import { EuiCallOut, EuiConfirmModal, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { useStartServices, sendRequest, sendDeletePackagePolicy, useConfig } from '../../../hooks'; -import { AGENT_API_ROUTES, AGENT_SAVED_OBJECT_TYPE } from '../../../constants'; -import type { AgentPolicy } from '../../../types'; +import { useStartServices, sendRequest, sendDeletePackagePolicy, useConfig } from '../hooks'; +import { AGENT_API_ROUTES, AGENT_SAVED_OBJECT_TYPE } from '../../common/constants'; +import type { AgentPolicy } from '../types'; interface Props { agentPolicy: AgentPolicy; diff --git a/x-pack/plugins/fleet/public/hooks/index.ts b/x-pack/plugins/fleet/public/hooks/index.ts index 0b413f72094d9..9f41e5c7cc92b 100644 --- a/x-pack/plugins/fleet/public/hooks/index.ts +++ b/x-pack/plugins/fleet/public/hooks/index.ts @@ -24,3 +24,5 @@ export * from './use_url_params'; export * from './use_fleet_status'; export * from './use_ui_extension'; export * from './use_intra_app_state'; +export * from './use_platform'; +export * from './use_agent_policy_refresh'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/hooks/use_config.tsx b/x-pack/plugins/fleet/public/hooks/use_agent_policy_refresh.tsx similarity index 100% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/hooks/use_config.tsx rename to x-pack/plugins/fleet/public/hooks/use_agent_policy_refresh.tsx diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/hooks/use_platform.tsx b/x-pack/plugins/fleet/public/hooks/use_platform.tsx similarity index 100% rename from x-pack/plugins/fleet/public/applications/fleet/sections/agents/hooks/use_platform.tsx rename to x-pack/plugins/fleet/public/hooks/use_platform.tsx