-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SECURITY_SOLUTION][ENDPOINT] Handle Host list/details policy links to non-existing policies #73208
Merged
paul-tavares
merged 6 commits into
elastic:master
from
paul-tavares:task/EMT-634-handle-host-links-to-deleted-policy
Jul 27, 2020
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d48e2fd
Make API call to check policies and save it to store
paul-tavares 0eae82a
change policy list and details to not show policy as a link if it doe…
paul-tavares d1c421c
Fix test + types
paul-tavares f385288
fix bug in middleware
paul-tavares 625cf51
Fix bug in HostPolicyLink
paul-tavares 060479e
Merge branch 'master' into task/EMT-634-handle-host-links-to-deleted-…
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I don't like that these
then().catch()
blocks are repeated below. Will look to improve in the future (maybe by passing along thedispatch
method to thegetNonexistingPoliciesForHostList()
as an argument.