[Security Solution] Fix issue where Endpoint list page crashes on missing Policy Id (#137788) (#137971)

* [Security Solution] Fix issue where Endpoint list page crashes on missing Policy Id

* pr comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit b8aaf561da)

Co-authored-by: Kevin Logan <56395104+kevinlog@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2022-08-03 09:33:22 -04:00 committed by GitHub
parent 46166da467
commit 1da8d682c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -7,7 +7,8 @@
import React, { memo, useMemo } from 'react';
import type { EuiLinkAnchorProps } from '@elastic/eui';
import { EuiLink } from '@elastic/eui';
import { EuiLink, EuiText, EuiIcon } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { getPolicyDetailPath } from '../common/routing';
import { useNavigateByRouterEventHandler } from '../../common/hooks/endpoint/use_navigate_by_router_event_handler';
import { useAppUrl } from '../../common/lib/kibana/hooks';
@ -27,7 +28,7 @@ export const EndpointPolicyLink = memo<
>(({ policyId, backLink, children, missingPolicies = {}, ...otherProps }) => {
const { getAppUrl } = useAppUrl();
const { toRoutePath, toRouteUrl } = useMemo(() => {
const path = getPolicyDetailPath(policyId);
const path = policyId ? getPolicyDetailPath(policyId) : '';
return {
toRoutePath: backLink ? { pathname: path, state: { backLink } } : path,
toRouteUrl: getAppUrl({ path }),
@ -35,10 +36,20 @@ export const EndpointPolicyLink = memo<
}, [policyId, getAppUrl, backLink]);
const clickHandler = useNavigateByRouterEventHandler(toRoutePath);
if (missingPolicies[policyId]) {
if (!policyId || missingPolicies[policyId]) {
return (
<span className={otherProps.className} data-test-subj={otherProps['data-test-subj']}>
{children}
{
<EuiText color="subdued" size="xs" className="eui-textNoWrap">
<EuiIcon size="m" type="alert" color="warning" />
&nbsp;
<FormattedMessage
id="xpack.securitySolution.endpoint.policyNotFound"
defaultMessage="Policy not found!"
/>
</EuiText>
}
</span>
);
}

View file

@ -13,7 +13,7 @@ export const isPolicyOutOfDate = (
reported: HostMetadata['Endpoint']['policy']['applied'],
current: HostInfo['policy_info']
): boolean => {
if (current === undefined || current === null) {
if (!current || !reported.id) {
return false; // we don't know, can't declare it out-of-date
}
return !(