Skip to content

Commit

Permalink
[Fleet] Update landing page for add fleet server
Browse files Browse the repository at this point in the history
  • Loading branch information
criamico committed Oct 28, 2022
1 parent 30fcc1d commit 2cc2056
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useGetFleetServerHosts,
useComboInput,
useInput,
useSwitchInput,
} from '../../../hooks';
import type { FleetServerHost } from '../../../types';

Expand All @@ -31,6 +32,7 @@ export interface FleetServerHostForm {
inputs: {
hostUrlsInput: ReturnType<typeof useComboInput>;
nameInput: ReturnType<typeof useInput>;
isDefaultInput: ReturnType<typeof useSwitchInput>;
};
}

Expand All @@ -41,6 +43,11 @@ export const useFleetServerHost = (): FleetServerHostForm => {
const isPreconfigured = fleetServerHost?.is_preconfigured ?? false;
const nameInput = useInput(fleetServerHost?.name ?? '', validateName, isPreconfigured);

const isDefaultInput = useSwitchInput(
fleetServerHost?.is_default ?? false,
isPreconfigured || fleetServerHost?.is_default
);

const hostUrlsInput = useComboInput(
'hostUrls',
fleetServerHost?.host_urls || [],
Expand Down Expand Up @@ -105,6 +112,7 @@ export const useFleetServerHost = (): FleetServerHostForm => {
inputs: {
hostUrlsInput,
nameInput,
isDefaultInput,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { useState, useCallback, useEffect } from 'react';
import { i18n } from '@kbn/i18n';

import type { useComboInput, useInput } from '../../../hooks';
import type { useComboInput, useInput, useSwitchInput } from '../../../hooks';
import { sendCreateAgentPolicy, sendGetOneAgentPolicy, useStartServices } from '../../../hooks';

import type { NewAgentPolicy } from '../../../types';
Expand Down Expand Up @@ -42,6 +42,7 @@ export interface QuickStartCreateForm {
inputs: {
hostUrlsInput: ReturnType<typeof useComboInput>;
nameInput: ReturnType<typeof useInput>;
isDefaultInput: ReturnType<typeof useSwitchInput>;
};
}

Expand Down Expand Up @@ -84,7 +85,7 @@ export const useQuickStartCreateForm = (): QuickStartCreateForm => {
const newFleetServerHost = {
name: inputs.nameInput.value,
host_urls: inputs.hostUrlsInput.value,
is_default: true,
is_default: inputs.isDefaultInput.value,
id: 'fleet-server-host',
is_preconfigured: false,
};
Expand Down Expand Up @@ -125,6 +126,7 @@ export const useQuickStartCreateForm = (): QuickStartCreateForm => {
validate,
inputs.nameInput.value,
inputs.hostUrlsInput.value,
inputs.isDefaultInput.value,
setFleetServerHost,
saveFleetServerHost,
generateServiceToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useState } from 'react';
import React, { useState, useCallback } from 'react';
import {
EuiButtonGroup,
EuiFlexGroup,
Expand All @@ -16,12 +16,15 @@ import {
EuiSpacer,
EuiText,
EuiTitle,
EuiToolTip,
EuiFlexItem,
EuiButton,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';

import styled from 'styled-components';

import { useStartServices } from '../../hooks';
import { useStartServices, useFlyoutContext } from '../../hooks';

import { QuickStartTab } from './quick_start_tab';
import { AdvancedTab } from './advanced_tab';
Expand Down Expand Up @@ -134,17 +137,69 @@ export const FleetServerFlyout: React.FunctionComponent<Props> = ({ onClose }) =
);
};

// Renders instructions directly
export const FleetServerInstructions: React.FunctionComponent = () => {
const { tabs, currentTab, setCurrentTab, currentTabContent } = useFleetServerTabs();
export const AddFleetServerLanding: React.FunctionComponent = () => {
const { docLinks } = useStartServices();
const flyoutContext = useFlyoutContext();

const onClickAddFleetServer = useCallback(() => {
flyoutContext.openFleetServerFlyout();
}, [flyoutContext]);

return (
<ContentWrapper gutterSize="none" justifyContent="center" direction="column">
<Header tabs={tabs} currentTab={currentTab} onTabClick={(id) => setCurrentTab(id)} />

<EuiSpacer size="m" />

{currentTabContent}
<EuiFlexGroup alignItems="center" direction="column">
<EuiFlexItem>
<EuiTitle size="m">
<h2 data-test-subj="addFleetServerHeader">
<FormattedMessage
id="xpack.fleet.fleetServerFlyout.title"
defaultMessage="Add a Fleet Server"
/>
</h2>
</EuiTitle>
</EuiFlexItem>

<EuiFlexItem>
<EuiText>
<FormattedMessage
id="xpack.fleet.fleetServerFlyout.instructions"
defaultMessage="A Fleet Server is required before you can enroll agents with Fleet. Follow the instructions below to set up a Fleet Server. For more information, see the {userGuideLink}"
values={{
userGuideLink: (
<EuiLink
href={docLinks.links.fleet.fleetServerAddFleetServer}
external
target="_blank"
>
<FormattedMessage
id="xpack.fleet.fleetServerSetup.setupGuideLink"
defaultMessage="Fleet and Elastic Agent Guide"
/>
</EuiLink>
),
}}
/>
</EuiText>
</EuiFlexItem>
<EuiSpacer size="s" />
<EuiFlexItem>
<EuiToolTip
content={
<FormattedMessage
id="xpack.fleet.agentList.addFleetServerButton.tooltip"
defaultMessage="Fleet Server is a component of the Elastic Stack used to centrally manage Elastic Agents"
/>
}
>
<EuiButton onClick={onClickAddFleetServer} fill data-test-subj="addFleetServerButton">
<FormattedMessage
id="xpack.fleet.agentList.addFleetServerButton"
defaultMessage="Add Fleet Server"
/>
</EuiButton>
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
</ContentWrapper>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EuiText,
EuiFormRow,
EuiFieldText,
EuiSwitch,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
Expand Down Expand Up @@ -133,6 +134,19 @@ const GettingStartedStepContent: React.FunctionComponent<QuickStartCreateForm> =
{status === 'error' && <EuiFormErrorText>{error}</EuiFormErrorText>}
</>
</EuiFormRow>
<EuiFormRow fullWidth {...inputs.isDefaultInput.formRowProps}>
<EuiSwitch
data-test-subj="fleetServerHostsFlyout.isDefaultSwitch"
{...inputs.isDefaultInput.props}
disabled={false}
label={
<FormattedMessage
id="xpack.fleet.settings.fleetServerHostsFlyout.defaultOutputSwitchLabel"
defaultMessage="Make this Fleet server the default one."
/>
}
/>
</EuiFormRow>

<EuiSpacer size="m" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { FleetServerMissingPrivileges } from '../components/fleet_server_callout

import { Loading } from '../components';

import { FleetServerInstructions } from '../../../components';
import { AddFleetServerLanding } from '../../../components';

import { CloudInstructions, EnrollmentRecommendation } from './components';

Expand Down Expand Up @@ -78,7 +78,7 @@ export const FleetServerRequirementPage: React.FunctionComponent<
) : showEnrollmentRecommendation ? (
<EnrollmentRecommendation showStandaloneTab={showStandaloneTab} />
) : (
<FleetServerInstructions />
<AddFleetServerLanding />
)}
</FlexItemWithMinWidth>
</ContentWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* 2.0.
*/

import React from 'react';
import React, { useCallback } from 'react';

import { EuiTitle, EuiLink, EuiText, EuiSpacer, EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';

import type { FleetServerHost } from '../../../../types';
import { useLink, useStartServices } from '../../../../hooks';
import { useFlyoutContext, useStartServices } from '../../../../hooks';
import { FleetServerHostsTable } from '../fleet_server_hosts_table';

export interface FleetServerHostsSectionProps {
Expand All @@ -24,7 +24,11 @@ export const FleetServerHostsSection: React.FunctionComponent<FleetServerHostsSe
deleteFleetServerHost,
}) => {
const { docLinks } = useStartServices();
const { getHref } = useLink();
const flyoutContext = useFlyoutContext();

const onClickAddFleetServer = useCallback(() => {
flyoutContext.openFleetServerFlyout();
}, [flyoutContext]);

return (
<>
Expand Down Expand Up @@ -61,7 +65,7 @@ export const FleetServerHostsSection: React.FunctionComponent<FleetServerHostsSe
<EuiSpacer size="s" />
<EuiButtonEmpty
iconType="plusInCircle"
href={getHref('settings_create_fleet_server_hosts')}
onClick={onClickAddFleetServer}
data-test-subj="settings.fleetServerHosts.addFleetServerHostBtn"
>
<FormattedMessage
Expand Down

0 comments on commit 2cc2056

Please sign in to comment.