Skip to content

Commit

Permalink
Show warning in standalone mode for policies with fleet server
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Apr 29, 2021
1 parent 60f088c commit a8f5ead
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AgentPolicyPackageBadges } from '../agent_policy_package_badges';
type Props = {
agentPolicies?: AgentPolicy[];
onAgentPolicyChange?: (key: string) => void;
excludeFleetServer?: boolean;
} & (
| {
withKeySelection: true;
Expand All @@ -30,7 +31,7 @@ type Props = {

export const EnrollmentStepAgentPolicy: React.FC<Props> = (props) => {
const { notifications } = useStartServices();
const { withKeySelection, agentPolicies, onAgentPolicyChange } = props;
const { withKeySelection, agentPolicies, onAgentPolicyChange, excludeFleetServer } = props;
const onKeyChange = props.withKeySelection && props.onKeyChange;

const [isAuthenticationSettingsOpen, setIsAuthenticationSettingsOpen] = useState(false);
Expand Down Expand Up @@ -182,7 +183,10 @@ export const EnrollmentStepAgentPolicy: React.FC<Props> = (props) => {
/>
<EuiSpacer size="m" />
{selectedState.agentPolicyId && (
<AgentPolicyPackageBadges agentPolicyId={selectedState.agentPolicyId} />
<AgentPolicyPackageBadges
agentPolicyId={selectedState.agentPolicyId}
excludeFleetServer={excludeFleetServer}
/>
)}
{withKeySelection && onKeyChange && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const AgentPolicySelectionStep = ({
withKeySelection={setSelectedAPIKeyId ? true : false}
onKeyChange={setSelectedAPIKeyId}
onAgentPolicyChange={onAgentPolicyChange}
excludeFleetServer={excludeFleetServer}
/>
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
*/

import React, { useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiSpacer, EuiText, EuiFlexGroup, EuiFlexItem, EuiBadge } from '@elastic/eui';
import { EuiSpacer, EuiText, EuiFlexGroup, EuiFlexItem, EuiBadge, EuiCallOut } from '@elastic/eui';

import { FLEET_SERVER_PACKAGE } from '../../../../../../common/constants';

import type { PackagePolicy, PackagePolicyPackage } from '../../../types';
import { useGetOneAgentPolicy } from '../../../hooks';
Expand All @@ -16,11 +19,13 @@ import { PackageIcon } from '../../../components/package_icon';
interface Props {
agentPolicyId: string;
hideTitle?: boolean;
excludeFleetServer?: boolean;
}

export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
agentPolicyId,
hideTitle,
excludeFleetServer,
}) => {
const agentPolicyRequest = useGetOneAgentPolicy(agentPolicyId);
const agentPolicy = agentPolicyRequest.data ? agentPolicyRequest.data.item : null;
Expand Down Expand Up @@ -49,6 +54,13 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
return null;
}

const showFleetServerWarning =
excludeFleetServer && packages.some((pkg) => pkg.name === FLEET_SERVER_PACKAGE);

const collectedIntegrationsCount = packages.filter(
(pkg) => !excludeFleetServer || pkg.name !== FLEET_SERVER_PACKAGE
).length;

return (
<>
{!hideTitle && (
Expand All @@ -58,8 +70,8 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
id="xpack.fleet.agentReassignPolicy.policyDescription"
defaultMessage="The selected agent policy will collect data for {count, plural, one {{countValue} integration} other {{countValue} integrations}}:"
values={{
count: packages.length,
countValue: <b>{packages.length}</b>,
count: collectedIntegrationsCount,
countValue: <b>{collectedIntegrationsCount}</b>,
}}
/>
</EuiText>
Expand All @@ -68,7 +80,11 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
)}
{packages.map((pkg, idx) => {
return (
<EuiBadge key={idx} color="hollow">
<EuiBadge
key={idx}
color="hollow"
isDisabled={excludeFleetServer && pkg.name === FLEET_SERVER_PACKAGE}
>
<EuiFlexGroup direction="row" gutterSize="xs" alignItems="center">
<EuiFlexItem grow={false}>
<PackageIcon
Expand All @@ -89,6 +105,23 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
</EuiBadge>
);
})}
{showFleetServerWarning && (
<>
<EuiSpacer size="s" />
<EuiCallOut
size="s"
color="warning"
iconType="alert"
title={i18n.translate(
'xpack.fleet.agentReassignPolicy.packageBadgeFleetServerWarning',
{
defaultMessage:
'The Fleet Server integration will not collect data in standalone mode.',
}
)}
/>
</>
)}
</>
);
};

0 comments on commit a8f5ead

Please sign in to comment.