Skip to content

Commit

Permalink
refactor integration details Policies list to use LinkedAgentCount co…
Browse files Browse the repository at this point in the history
…mponent
  • Loading branch information
paul-tavares committed Dec 22, 2020
1 parent 1c23dad commit a73da05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
*/

import React, { memo } from 'react';
import { EuiLink } from '@elastic/eui';
import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui';
import { useLink } from '../hooks';
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<{ count: number; agentPolicyId: string }>(
({ count, agentPolicyId }) => {
const { getHref } = useLink();
return count > 0 ? (
<EuiLink
href={getHref('fleet_agent_list', {
kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id : ${agentPolicyId}`,
})}
>
{count}
</EuiLink>
) : (
<>count</>
);
}
);
export const LinkedAgentCount = memo<
Omit<EuiLinkAnchorProps, 'href'> & { count: number; agentPolicyId: string }
>(({ count, agentPolicyId, ...otherEuiLinkProps }) => {
const { getHref } = useLink();
return count > 0 ? (
<EuiLink
{...otherEuiLinkProps}
href={getHref('fleet_agent_list', {
kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id : ${agentPolicyId}`,
})}
>
{count}
</EuiLink>
) : (
<>{count}</>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ import { FormattedRelative, FormattedMessage } from '@kbn/i18n/react';
import { useGetPackageInstallStatus } from '../../hooks';
import { InstallStatus } from '../../../../types';
import { useLink } from '../../../../hooks';
import {
AGENT_SAVED_OBJECT_TYPE,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
} from '../../../../../../../common/constants';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../../../../common/constants';
import { useUrlPagination } from '../../../../hooks';
import {
PackagePolicyAndAgentPolicy,
usePackagePoliciesWithAgentPolicy,
} from './use_package_policies_with_agent_policy';
import { LinkAndRevision, LinkAndRevisionProps } from '../../../../components';
import { Persona } from './persona';
import { LinkedAgentCount } from '../../../../components/linked_agent_count';

const IntegrationDetailsLink = memo<{
packagePolicy: PackagePolicyAndAgentPolicy['packagePolicy'];
Expand Down Expand Up @@ -66,22 +64,6 @@ const AgentPolicyDetailLink = memo<{
);
});

const PolicyAgentListLink = memo<{ agentPolicyId: string; children: ReactNode }>(
({ agentPolicyId, children }) => {
const { getHref } = useLink();
return (
<EuiLink
className="eui-textTruncate"
href={getHref('fleet_agent_list', {
kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id:%20${agentPolicyId}`,
})}
>
{children}
</EuiLink>
);
}
);

interface PackagePoliciesPanelProps {
name: string;
version: string;
Expand Down Expand Up @@ -156,9 +138,11 @@ export const PackagePoliciesPanel = ({ name, version }: PackagePoliciesPanelProp
width: '8ch',
render({ packagePolicy, agentPolicy }: PackagePolicyAndAgentPolicy) {
return (
<PolicyAgentListLink agentPolicyId={packagePolicy.policy_id}>
{agentPolicy?.agents ?? 0}
</PolicyAgentListLink>
<LinkedAgentCount
count={agentPolicy?.agents ?? 0}
agentPolicyId={packagePolicy.policy_id}
className="eui-textTruncate"
/>
);
},
},
Expand Down

0 comments on commit a73da05

Please sign in to comment.