-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY_SOLUTION][ENDPOINT] Handle Host list/details policy links t…
…o non-existing policies (#73208) * Make API call to check policies and save it to store * change policy list and details to not show policy as a link if it does not exist
- Loading branch information
1 parent
9aa5e17
commit 6d4bb9d
Showing
10 changed files
with
224 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...rity_solution/public/management/pages/endpoint_hosts/view/components/host_policy_link.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { memo, useMemo } from 'react'; | ||
import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui'; | ||
import { useHostSelector } from '../hooks'; | ||
import { nonExistingPolicies } from '../../store/selectors'; | ||
import { getPolicyDetailPath } from '../../../../common/routing'; | ||
import { useFormatUrl } from '../../../../../common/components/link_to'; | ||
import { SecurityPageName } from '../../../../../../common/constants'; | ||
import { useNavigateByRouterEventHandler } from '../../../../../common/hooks/endpoint/use_navigate_by_router_event_handler'; | ||
|
||
/** | ||
* A policy link (to details) that first checks to see if the policy id exists against | ||
* the `nonExistingPolicies` value in the store. If it does not exist, then regular | ||
* text is returned. | ||
*/ | ||
export const HostPolicyLink = memo< | ||
Omit<EuiLinkAnchorProps, 'href'> & { | ||
policyId: string; | ||
} | ||
>(({ policyId, children, onClick, ...otherProps }) => { | ||
const missingPolicies = useHostSelector(nonExistingPolicies); | ||
const { formatUrl } = useFormatUrl(SecurityPageName.administration); | ||
const { toRoutePath, toRouteUrl } = useMemo(() => { | ||
const toPath = getPolicyDetailPath(policyId); | ||
return { | ||
toRoutePath: toPath, | ||
toRouteUrl: formatUrl(toPath), | ||
}; | ||
}, [formatUrl, policyId]); | ||
const clickHandler = useNavigateByRouterEventHandler(toRoutePath, onClick); | ||
|
||
if (missingPolicies[policyId]) { | ||
return ( | ||
<span className={otherProps.className} data-test-subj={otherProps['data-test-subj']}> | ||
{children} | ||
</span> | ||
); | ||
} | ||
|
||
return ( | ||
// eslint-disable-next-line @elastic/eui/href-or-on-click | ||
<EuiLink href={toRouteUrl} onClick={clickHandler} {...otherProps}> | ||
{children} | ||
</EuiLink> | ||
); | ||
}); | ||
|
||
HostPolicyLink.displayName = 'HostPolicyLink'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.