-
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.
[Fleet] Add redesigned Fleet Server flyout (#127786)
* WIP new fleet server flyout * WIP finish up quick start tab * Refactor quick start steps into separate files: * Initial refactor of existing fleet server instructions * Move quick start form return value to explicit type * Flesh out fleet server commands * Fix translation error * Migrate on prem instructions component over to new file structure * Makes quick start tab actually create policy * Fix type errors * Fix missing hooks + update snapshots * Fix paths in mocks * Fix translations * WIP test fixes * Implement enabled/disabled state for new steps * Fix cypress tests * Force re-render to get last test passing * Fix failing tests * Fix import errors after conflicts * Fix snapshot tests * Use id instead of full policy for policy selector * Replace Fleet Server instructions w/ Advanced Tab contents * First pass at integrating add agent/fleet server flyouts * Test commit * Fix imports * Fix imports * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * Enforce https-only fleet server URL's + improve errors * Fix failing tests * Fix fleet server command in quick start * Show success state in Quick start when policy exists + use first fleet server host if it exists * Set initial service token value when Fleet Server policy ID is initiall set * Generate service token instead of enrollment token * Fix fleet server flyout opening from unhealthy callout * Revert service token change + use EuiComboBox for fleet server host * Fix checks + use custom option text * Move fleet server host combobox to component * Use new combobox in advanced tab * Fix translations * Fix unused import * Don't recreate quick start policy if it already exists * Actually use quick start policy fields 🙃 * Fix policy check * Update x-pack/plugins/fleet/public/applications/fleet/components/fleet_server_instructions/components/fleet_server_host_combobox.tsx Co-authored-by: Mark Hopkin <[email protected]> * Update x-pack/plugins/fleet/public/applications/fleet/components/fleet_server_instructions/steps/install_fleet_server.tsx Co-authored-by: Mark Hopkin <[email protected]> * Update x-pack/plugins/fleet/public/applications/fleet/components/fleet_server_instructions/steps/set_deployment_mode.tsx Co-authored-by: Mark Hopkin <[email protected]> * Fix formatting issue * Clean up fleet server settings variable declaration per PR review Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Mark Hopkin <[email protected]>
- Loading branch information
1 parent
ac8df39
commit b655b48
Showing
61 changed files
with
2,262 additions
and
1,137 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
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
66 changes: 66 additions & 0 deletions
66
...ins/fleet/public/applications/fleet/components/fleet_server_instructions/advanced_tab.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,66 @@ | ||
/* | ||
* 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 { EuiSteps } from '@elastic/eui'; | ||
import React from 'react'; | ||
|
||
import { useAdvancedForm } from './hooks'; | ||
|
||
import { | ||
getAddFleetServerHostStep, | ||
getSelectAgentPolicyStep, | ||
getGenerateServiceTokenStep, | ||
getSetDeploymentModeStep, | ||
getInstallFleetServerStep, | ||
getConfirmFleetServerConnectionStep, | ||
} from './steps'; | ||
|
||
export const AdvancedTab: React.FunctionComponent = () => { | ||
const { | ||
eligibleFleetServerPolicies, | ||
refreshEligibleFleetServerPolicies, | ||
fleetServerPolicyId, | ||
setFleetServerPolicyId, | ||
isFleetServerReady, | ||
serviceToken, | ||
isLoadingServiceToken, | ||
generateServiceToken, | ||
fleetServerHostForm, | ||
deploymentMode, | ||
setDeploymentMode, | ||
} = useAdvancedForm(); | ||
|
||
const steps = [ | ||
getSelectAgentPolicyStep({ | ||
policyId: fleetServerPolicyId, | ||
setPolicyId: setFleetServerPolicyId, | ||
eligibleFleetServerPolicies, | ||
refreshEligibleFleetServerPolicies, | ||
}), | ||
getSetDeploymentModeStep({ | ||
deploymentMode, | ||
setDeploymentMode, | ||
disabled: !Boolean(fleetServerPolicyId), | ||
}), | ||
getAddFleetServerHostStep({ fleetServerHostForm, disabled: !Boolean(fleetServerPolicyId) }), | ||
getGenerateServiceTokenStep({ | ||
serviceToken, | ||
generateServiceToken, | ||
isLoadingServiceToken, | ||
disabled: !Boolean(fleetServerHostForm.isFleetServerHostSubmitted), | ||
}), | ||
getInstallFleetServerStep({ | ||
isFleetServerReady, | ||
serviceToken, | ||
fleetServerHost: fleetServerHostForm.fleetServerHost, | ||
fleetServerPolicyId, | ||
disabled: !Boolean(serviceToken), | ||
}), | ||
getConfirmFleetServerConnectionStep({ isFleetServerReady, disabled: !Boolean(serviceToken) }), | ||
]; | ||
|
||
return <EuiSteps steps={steps} className="eui-textLeft" />; | ||
}; |
77 changes: 77 additions & 0 deletions
77
...ions/fleet/components/fleet_server_instructions/components/fleet_server_host_combobox.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,77 @@ | ||
/* | ||
* 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, { useState } from 'react'; | ||
import type { EuiComboBoxOptionOption } from '@elastic/eui'; | ||
import { EuiComboBox, EuiText } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
interface Props { | ||
fleetServerHost: string | undefined; | ||
fleetServerHostSettings: string[]; | ||
isDisabled: boolean; | ||
isInvalid: boolean; | ||
onFleetServerHostChange: (host: string) => void; | ||
} | ||
|
||
export const FleetServerHostComboBox: React.FunctionComponent<Props> = ({ | ||
fleetServerHost, | ||
fleetServerHostSettings, | ||
isDisabled = false, | ||
isInvalid = false, | ||
onFleetServerHostChange, | ||
}) => { | ||
// Track options that are created inline | ||
const [createdOptions, setCreatedOptions] = useState<string[]>([]); | ||
|
||
const options = [...createdOptions, ...fleetServerHostSettings].map((option) => ({ | ||
label: option, | ||
value: option, | ||
})); | ||
|
||
const handleChange = (selectedOptions: Array<EuiComboBoxOptionOption<string>>) => { | ||
const host = selectedOptions[0].value ?? ''; | ||
onFleetServerHostChange(host); | ||
}; | ||
|
||
const handleCreateOption = (option: string) => { | ||
setCreatedOptions([...createdOptions, option]); | ||
onFleetServerHostChange(option); | ||
}; | ||
|
||
return ( | ||
<EuiComboBox<string> | ||
fullWidth | ||
isClearable={false} | ||
singleSelection={{ asPlainText: true }} | ||
placeholder="https://fleet-server-host.com:8220" | ||
options={options} | ||
customOptionText={i18n.translate( | ||
'xpack.fleet.fleetServerSetup.addFleetServerHostCustomOptionText', | ||
{ | ||
defaultMessage: 'Add {searchValuePlaceholder} as a new Fleet Server host', | ||
values: { searchValuePlaceholder: '{searchValue}' }, | ||
} | ||
)} | ||
selectedOptions={fleetServerHost ? [{ label: fleetServerHost, value: fleetServerHost }] : []} | ||
prepend={ | ||
<EuiText> | ||
<FormattedMessage | ||
id="xpack.fleet.fleetServerSetup.addFleetServerHostInputLabel" | ||
defaultMessage="Fleet Server host" | ||
/> | ||
</EuiText> | ||
} | ||
noSuggestions={fleetServerHostSettings.length === 0} | ||
data-test-subj="fleetServerHostInput" | ||
isDisabled={isDisabled} | ||
isInvalid={isInvalid} | ||
onChange={handleChange} | ||
onCreateOption={handleCreateOption} | ||
/> | ||
); | ||
}; |
7 changes: 7 additions & 0 deletions
7
.../fleet/public/applications/fleet/components/fleet_server_instructions/components/index.ts
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,7 @@ | ||
/* | ||
* 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 './fleet_server_host_combobox'; |
33 changes: 33 additions & 0 deletions
33
...s/fleet/public/applications/fleet/components/fleet_server_instructions/flyout.stories.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,33 @@ | ||
/* | ||
* 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 { EuiButton } from '@elastic/eui'; | ||
|
||
import { FleetServerFlyout as FleetServerFlyoutComponent } from '.'; | ||
|
||
export const FleetServerFlyout = () => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
|
||
return ( | ||
<div style={{ width: 900 }}> | ||
<EuiButton size="m" fill color="primary" onClick={() => setIsOpen(true)}> | ||
Show flyout | ||
</EuiButton> | ||
{isOpen && <FleetServerFlyoutComponent onClose={() => setIsOpen(false)} />} | ||
</div> | ||
); | ||
}; | ||
|
||
FleetServerFlyout.args = { | ||
isCloudEnabled: false, | ||
}; | ||
|
||
export default { | ||
component: FleetServerFlyout, | ||
title: 'Sections/Fleet/Agents/Fleet Server Instructions/In Flyout', | ||
}; |
18 changes: 18 additions & 0 deletions
18
...ugins/fleet/public/applications/fleet/components/fleet_server_instructions/hooks/index.ts
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,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// These hooks are tightly coupled to each tab of the Fleet server instructions component, and provide | ||
// all necessary data to drive those UI's | ||
export * from './use_advanced_form'; | ||
export * from './use_quick_start_form'; | ||
|
||
// These are individual hooks for one-off consumption. These are typically composed in the hooks above, | ||
// but exported here to support individual usage. | ||
export * from './use_wait_for_fleet_server'; | ||
export * from './use_select_fleet_server_policy'; | ||
export * from './use_service_token'; | ||
export * from './use_fleet_server_host'; |
46 changes: 46 additions & 0 deletions
46
...public/applications/fleet/components/fleet_server_instructions/hooks/use_advanced_form.ts
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,46 @@ | ||
/* | ||
* 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 { useState } from 'react'; | ||
|
||
import type { DeploymentMode } from '../steps'; | ||
|
||
import { useFleetServerHost } from './use_fleet_server_host'; | ||
import { useSelectFleetServerPolicy } from './use_select_fleet_server_policy'; | ||
import { useServiceToken } from './use_service_token'; | ||
import { useWaitForFleetServer } from './use_wait_for_fleet_server'; | ||
|
||
/** | ||
* Provides all data/state required for the "advanced" tab in the Fleet Server instructions/flyout | ||
*/ | ||
export const useAdvancedForm = (defaultAgentPolicyId?: string) => { | ||
const { | ||
eligibleFleetServerPolicies, | ||
refreshEligibleFleetServerPolicies, | ||
fleetServerPolicyId, | ||
setFleetServerPolicyId, | ||
} = useSelectFleetServerPolicy(defaultAgentPolicyId); | ||
const { isFleetServerReady } = useWaitForFleetServer(); | ||
const { serviceToken, isLoadingServiceToken, generateServiceToken } = useServiceToken(); | ||
const fleetServerHostForm = useFleetServerHost(); | ||
|
||
const [deploymentMode, setDeploymentMode] = useState<DeploymentMode>('quickstart'); | ||
|
||
return { | ||
eligibleFleetServerPolicies, | ||
refreshEligibleFleetServerPolicies, | ||
fleetServerPolicyId, | ||
setFleetServerPolicyId, | ||
isFleetServerReady, | ||
serviceToken, | ||
isLoadingServiceToken, | ||
generateServiceToken, | ||
fleetServerHostForm, | ||
deploymentMode, | ||
setDeploymentMode, | ||
}; | ||
}; |
Oops, something went wrong.