Skip to content

Commit

Permalink
[Fleet] Fix incomplete agent count message on policy tab (#100497) (#…
Browse files Browse the repository at this point in the history
…100515)

Co-authored-by: Zacqary Adam Xeper <Zacqary@users.noreply.github.com>
  • Loading branch information
kibanamachine and Zacqary authored May 25, 2021
1 parent a2c2f98 commit c7f8276
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { memo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import type { EuiLinkAnchorProps } from '@elastic/eui';
import { EuiLink } from '@elastic/eui';

Expand All @@ -16,24 +17,37 @@ import { AGENT_SAVED_OBJECT_TYPE } from '../constants';
* Displays the provided `count` number as a link to the Agents list if it is greater than zero
*/
export const LinkedAgentCount = memo<
Omit<EuiLinkAnchorProps, 'href'> & { count: number; agentPolicyId: string }
>(({ count, agentPolicyId, ...otherEuiLinkProps }) => {
Omit<EuiLinkAnchorProps, 'href'> & {
count: number;
agentPolicyId: string;
showAgentText?: boolean;
}
>(({ count, agentPolicyId, showAgentText, ...otherEuiLinkProps }) => {
const { getHref } = useLink();
const displayValue = showAgentText ? (
<FormattedMessage
id="xpack.fleet.agentPolicy.linkedAgentCountText"
defaultMessage="{count, plural, one {# agent} other {# agents}}"
values={{ count }}
/>
) : (
count
);
return count > 0 ? (
<EuiLink
{...otherEuiLinkProps}
href={getHref('fleet_agent_list', {
kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id : ${agentPolicyId}`,
})}
>
{count}
{displayValue}
</EuiLink>
) : (
<span
data-test-subj={otherEuiLinkProps['data-test-subj']}
className={otherEuiLinkProps.className}
>
{count}
{displayValue}
</span>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const AgentPolicyDetailsPage: React.FunctionComponent = () => {
<LinkedAgentCount
count={(agentStatus && agentStatus.total) || 0}
agentPolicyId={(agentPolicy && agentPolicy.id) || ''}
showAgentText
/>
),
},
Expand Down

0 comments on commit c7f8276

Please sign in to comment.