-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Onboarding integration flow fleet (#203443)
## Summary Summarize your PR. If it involves visual changes include a screenshot or gif. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ...
- Loading branch information
Showing
40 changed files
with
1,072 additions
and
215 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
37 changes: 37 additions & 0 deletions
37
...reate_package_policy_page/embedded_integration_flow/embedded_integration_steps_layout.tsx
This file contains 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,37 @@ | ||
/* | ||
* 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 from 'react'; | ||
|
||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
|
||
import { Error } from '../../../../components'; | ||
|
||
import type { EmbeddedIntegrationStepsLayoutProps } from './types'; | ||
|
||
export const EmbeddedIntegrationStepsLayout: React.FunctionComponent< | ||
EmbeddedIntegrationStepsLayoutProps | ||
> = (props) => { | ||
const { steps, currentStep, error } = props; | ||
|
||
if (error) { | ||
return ( | ||
<Error | ||
title={ | ||
<FormattedMessage | ||
id="xpack.fleet.createPackagePolicy.errorLoadingPackageTitle" | ||
defaultMessage="Error loading package information" | ||
/> | ||
} | ||
error={error} | ||
/> | ||
); | ||
} | ||
|
||
const StepComponent = steps[currentStep].component; | ||
|
||
return <StepComponent {...props} />; | ||
}; |
149 changes: 149 additions & 0 deletions
149
...leet/sections/agent_policy/create_package_policy_page/embedded_integration_flow/index.tsx
This file contains 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,149 @@ | ||
/* | ||
* 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, { useCallback, useEffect, useMemo, useState } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { splitPkgKey } from '../../../../../../../common/services'; | ||
|
||
import { | ||
useGetPackageInfoByKeyQuery, | ||
useFleetServerHostsForPolicy, | ||
useStartServices, | ||
} from '../../../../hooks'; | ||
|
||
import { useIntegrationsStateContext } from '../../../../../integrations/hooks'; | ||
|
||
import type { AgentPolicy } from '../../../../types'; | ||
import { useGetAgentPolicyOrDefault } from '../multi_page_layout/hooks'; | ||
import { Loading } from '../../../../components'; | ||
|
||
import { onboardingManagedSteps } from './onboarding_steps'; | ||
|
||
import { EmbeddedIntegrationStepsLayout } from './embedded_integration_steps_layout'; | ||
import type { EmbeddedIntegrationFlowProps } from './types'; | ||
|
||
export const EmbeddedIntegrationFlow: React.FC<EmbeddedIntegrationFlowProps> = ({ | ||
prerelease, | ||
integrationName: integration, | ||
onStepNext, | ||
onCancel, | ||
handleViewAssets, | ||
from, | ||
}) => { | ||
const { notifications } = useStartServices(); | ||
|
||
const { pkgkey: pkgKeyContext } = useIntegrationsStateContext(); | ||
const pkgkey = pkgKeyContext || ''; | ||
const { pkgName, pkgVersion } = splitPkgKey(pkgkey); | ||
const [currentStep, setCurrentStep] = useState(0); | ||
const [isManaged, setIsManaged] = useState(true); | ||
const [enrolledAgentIds, setEnrolledAgentIds] = useState<string[]>([]); | ||
const [selectedAgentPolicies, setSelectedAgentPolicies] = useState<AgentPolicy[]>(); | ||
const toggleIsManaged = (newIsManaged: boolean) => { | ||
setIsManaged(newIsManaged); | ||
setCurrentStep(0); | ||
}; | ||
|
||
const agentPolicyId = useMemo(() => selectedAgentPolicies?.[0]?.id, [selectedAgentPolicies]); | ||
const { | ||
data: packageInfoData, | ||
error: packageInfoError, | ||
isLoading: isPackageInfoLoading, | ||
} = useGetPackageInfoByKeyQuery(pkgName, pkgVersion, { prerelease, full: true }); | ||
|
||
const { | ||
agentPolicy, | ||
enrollmentAPIKey, | ||
error: agentPolicyError, | ||
isLoading: isAgentPolicyLoading, | ||
} = useGetAgentPolicyOrDefault(agentPolicyId); | ||
|
||
const packageInfo = useMemo(() => packageInfoData?.item, [packageInfoData]); | ||
|
||
const integrationInfo = useMemo(() => { | ||
if (!integration) return; | ||
return packageInfo?.policy_templates?.find( | ||
(policyTemplate) => policyTemplate.name === integration | ||
); | ||
}, [packageInfo?.policy_templates, integration]); | ||
|
||
const { fleetServerHost, fleetProxy, downloadSource } = useFleetServerHostsForPolicy(agentPolicy); | ||
|
||
const stepsNext = useCallback( | ||
(props?: { selectedAgentPolicies?: AgentPolicy[]; toStep?: number }) => { | ||
if (currentStep === onboardingManagedSteps.length - 1) { | ||
return; | ||
} | ||
|
||
setCurrentStep(props?.toStep ?? currentStep + 1); | ||
onStepNext?.(props?.toStep ?? currentStep + 1); | ||
|
||
// selected agent policy is set after integration is configured | ||
if (props?.selectedAgentPolicies) { | ||
setSelectedAgentPolicies(props?.selectedAgentPolicies); | ||
} | ||
}, | ||
[currentStep, onStepNext] | ||
); | ||
|
||
const stepsBack = () => { | ||
if (currentStep === 0) { | ||
return; | ||
} | ||
|
||
setCurrentStep(currentStep - 1); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!isPackageInfoLoading && packageInfoError) { | ||
notifications.toasts.addError(packageInfoError, { | ||
title: i18n.translate('xpack.fleet.createPackagePolicy.errorLoadingPackageTitle', { | ||
defaultMessage: 'Error loading package information', | ||
}), | ||
toastMessage: packageInfoError.message, | ||
}); | ||
} | ||
}, [isPackageInfoLoading, notifications.toasts, packageInfoError]); | ||
|
||
useEffect(() => { | ||
if (!isAgentPolicyLoading && agentPolicyError) { | ||
notifications.toasts.addError(agentPolicyError, { | ||
title: i18n.translate('xpack.fleet.createPackagePolicy.errorLoadingAgentPolicyTitle', { | ||
defaultMessage: 'Error loading agent policy information', | ||
}), | ||
toastMessage: agentPolicyError.message, | ||
}); | ||
} | ||
}, [isAgentPolicyLoading, notifications.toasts, agentPolicyError]); | ||
|
||
return !isPackageInfoLoading && packageInfo ? ( | ||
<EmbeddedIntegrationStepsLayout | ||
fleetServerHost={fleetServerHost} | ||
fleetProxy={fleetProxy} | ||
downloadSource={downloadSource} | ||
agentPolicy={selectedAgentPolicies?.[0] ?? agentPolicy} | ||
enrollmentAPIKey={enrollmentAPIKey} | ||
currentStep={currentStep} | ||
steps={onboardingManagedSteps} | ||
packageInfo={packageInfo} | ||
integrationInfo={integrationInfo} | ||
onNext={stepsNext} | ||
onBack={stepsBack} | ||
isManaged={isManaged} | ||
setIsManaged={toggleIsManaged} | ||
setEnrolledAgentIds={setEnrolledAgentIds} | ||
enrolledAgentIds={enrolledAgentIds} | ||
onCancel={onCancel} | ||
prerelease={prerelease} | ||
handleViewAssets={handleViewAssets} | ||
from={from} | ||
selectedAgentPolicies={selectedAgentPolicies} | ||
/> | ||
) : ( | ||
<Loading /> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
...reate_package_policy_page/embedded_integration_flow/onboarding_steps/add_fleet_server.tsx
This file contains 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,43 @@ | ||
/* | ||
* 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 from 'react'; | ||
|
||
import { EuiSpacer } from '@elastic/eui'; | ||
|
||
import { useCheckPermissions } from '../../../../../hooks'; | ||
|
||
import { useFleetServerTabs } from '../../../../../components'; | ||
import { Header } from '../../../../../components/fleet_server_instructions'; | ||
import { FleetServerMissingESPrivileges } from '../../../../agents/components'; | ||
import type { EmbeddedIntegrationStepsLayoutProps } from '../types'; | ||
|
||
export const AddFleetServerStepFromOnboardingHub: React.FC<EmbeddedIntegrationStepsLayoutProps> = ({ | ||
onCancel, | ||
onNext, | ||
}) => { | ||
const { tabs, currentTab, setCurrentTab, currentTabContent } = useFleetServerTabs( | ||
onCancel, | ||
onNext | ||
); | ||
|
||
const { permissionsError, isPermissionsLoading } = useCheckPermissions(); | ||
|
||
return ( | ||
<> | ||
<Header tabs={tabs} currentTab={currentTab} onTabClick={(id) => setCurrentTab(id)} /> | ||
{!isPermissionsLoading && permissionsError === 'MISSING_FLEET_SERVER_SETUP_PRIVILEGES' ? ( | ||
<FleetServerMissingESPrivileges /> | ||
) : ( | ||
<> | ||
<EuiSpacer size="xl" /> | ||
{currentTabContent} | ||
</> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.