Skip to content
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

[Fleet] Show Add Fleet Server instead of add agent when adding agent from agent policy #144105

Merged
merged 5 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EuiContextMenuItem, EuiPortal } from '@elastic/eui';
import type { AgentPolicy } from '../../../types';
import { useAuthz } from '../../../hooks';
import { AgentEnrollmentFlyout, ContextMenuActions } from '../../../components';
import { FLEET_SERVER_PACKAGE } from '../../../constants';

import { AgentPolicyYamlFlyout } from './agent_policy_yaml_flyout';
import { AgentPolicyCopyProvider } from './agent_policy_copy_provider';
Expand All @@ -36,6 +37,14 @@ export const AgentPolicyActionMenu = memo<{
enrollmentFlyoutOpenByDefault
);

const isFleetServerPolicy = useMemo(
() =>
agentPolicy.package_policies?.some(
(packagePolicy) => packagePolicy.package?.name === FLEET_SERVER_PACKAGE
),
[agentPolicy]
);

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false);

const onContextMenuChange = useCallback(
Expand Down Expand Up @@ -83,10 +92,17 @@ export const AgentPolicyActionMenu = memo<{
}}
key="enrollAgents"
>
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.enrollAgentActionText"
defaultMessage="Add agent"
/>
{isFleetServerPolicy ? (
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.enrollAgentActionText"
nchaulet marked this conversation as resolved.
Show resolved Hide resolved
defaultMessage="Add Fleet Server"
/>
) : (
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.enrollAgentActionText"
defaultMessage="Add agent"
/>
)}
</EuiContextMenuItem>,
viewPolicyItem,
<EuiContextMenuItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ import {
EuiFlyoutFooter,
EuiTab,
EuiTabs,
EuiLink,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';

import { useGetSettings, useFleetStatus, useAgentEnrollmentFlyoutData } from '../../hooks';
import {
useGetSettings,
useFleetStatus,
useAgentEnrollmentFlyoutData,
useStartServices,
} from '../../hooks';
import { FLEET_SERVER_PACKAGE } from '../../constants';
import type { PackagePolicy, AgentPolicy } from '../../types';

Expand Down Expand Up @@ -54,6 +60,7 @@ export const AgentEnrollmentFlyout: React.FunctionComponent<FlyOutProps> = ({
const settings = useGetSettings();
const fleetStatus = useFleetStatus();
const fleetServerHosts = settings.data?.item?.fleet_server_hosts || [];
const { docLinks } = useStartServices();

const [selectedPolicyId, setSelectedPolicyId] = useState(agentPolicy?.id);
const [isFleetServerPolicySelected, setIsFleetServerPolicySelected] = useState<boolean>(false);
Expand Down Expand Up @@ -99,19 +106,50 @@ export const AgentEnrollmentFlyout: React.FunctionComponent<FlyOutProps> = ({
<EuiFlyoutHeader hasBorder aria-labelledby="FleetAgentEnrollmentFlyoutTitle">
<EuiTitle size="m">
<h2 id="FleetAgentEnrollmentFlyoutTitle">
<FormattedMessage
id="xpack.fleet.agentEnrollment.flyoutTitle"
defaultMessage="Add agent"
/>
{isFleetServerPolicySelected ? (
<FormattedMessage
id="xpack.fleet.agentEnrollment.flyoutFleetServerTitle"
defaultMessage="Add Fleet Server"
/>
) : (
<FormattedMessage
id="xpack.fleet.agentEnrollment.flyoutTitle"
defaultMessage="Add agent"
/>
)}
</h2>
</EuiTitle>
<EuiSpacer size="l" />
<EuiText>
<FormattedMessage
id="xpack.fleet.agentEnrollment.agentDescription"
defaultMessage="Add Elastic Agents to your hosts to collect data and send it to the Elastic Stack."
/>
</EuiText>
{isFleetServerPolicySelected ? (
<EuiText>
<FormattedMessage
id="xpack.fleet.agentEnrollment.instructionstFleetServer"
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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user might have a fleet server already set up, does this make it sound like they haven't and they need to add one to add an agent? We might want to get DeDe to review this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same copy that we use in the Add Fleet Server here, it probably had some unnecessary complexity (in my opinion) to add a specific copy if there is already a Fleet Server.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep agreed 👌

values={{
userGuideLink: (
<EuiLink
href={docLinks.links.fleet.fleetServerAddFleetServer}
external
target="_blank"
>
<FormattedMessage
id="xpack.fleet.agentEnrollment.setupGuideLink"
defaultMessage="Fleet and Elastic Agent Guide"
/>
</EuiLink>
),
}}
/>
</EuiText>
) : (
<EuiText>
<FormattedMessage
id="xpack.fleet.agentEnrollment.agentDescription"
defaultMessage="Add Elastic Agents to your hosts to collect data and send it to the Elastic Stack."
/>
</EuiText>
)}

{selectionType === 'tabs' ? (
<>
<EuiSpacer size="l" />
Expand Down