-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Refactor host isolation exceptions list page to now use <ArtifactListPage/>
component
#129099
Conversation
…host-isolation-exceptions-to-artifact-list-page-componet
…host-isolation-exceptions-to-artifact-list-page-componet
…host-isolation-exceptions-to-artifact-list-page-componet
* @param renderResult | ||
* @param [atIndex=0] | ||
*/ | ||
export const clickOnEffectedPolicy = async ( |
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: a reusable utility for clicking on policies based on the index of the policy entry. I had noticed that in many cases we are being forced to grab the ID of the policy in order to generate the data-test-subj
(which includes the ID of policy) when really in some cases, we don't really care for about the UUID. Sos this utility just clicks on a entry based on its index in the list.
Further below there is another test utility that reports on whether a policy based on its index is selected or not.
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.
This is super helpful. Thanks 🥇
…host-isolation-exceptions-to-artifact-list-page-componet
…ection store definition
…host-isolation-exceptions-to-artifact-list-page-componet # Conflicts: # x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/components/form.test.tsx # x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/components/form_flyout.test.tsx # x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/host_isolation_exceptions_list.test.tsx
…ct list page routing
Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt) |
* 2.0. | ||
*/ | ||
|
||
export * from './utils'; |
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: This directory (url_routing
) will be refactored and consolidated into a folder named routing
that will contain multiple files. I did not want to do that in this PR because then I would have to move over the existing routing.ts
module and that would have pulled in several others due to path changes. I will create a follow up PR to this one.
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ |
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.
Some of these were copied over from the existing routing.ts
. Once I refactor the existing routing.ts
over to a new folder named routing
, this util.ts
module will likely hold all of the other utilities found there
@@ -68,6 +68,9 @@ export interface ArtifactListPageProps { | |||
searchableFields?: MaybeImmutable<string[]>; | |||
flyoutSize?: EuiFlyoutSize; | |||
'data-test-subj'?: string; | |||
allowCardEditAction?: boolean; | |||
allowCardDeleteAction?: boolean; |
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.
Although delete is not currently needed, I just backed it in since we will likely need it in the future with RBAC and the ability to have View only pages under Management
* A general component for formatting errors. Recognizes different types of errors and displays | ||
* their information. | ||
*/ | ||
export const FormattedError = memo<FormattedErrorProps>( |
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.
We will likely improve upon this component moving forward. Example: if we ever introduce server/api provided error codes with response errors, this component could be improved to recognize those types of errors, and formatted them accordingly.
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.
🔥 awesome
@@ -0,0 +1,259 @@ | |||
/* |
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.
An exceptions list API HTTP set of mocks that currently uses the ExceptionsListItemGenerator
. I will look to improve this in the future and add support allowing a custom generator to be passed in (ex. TrustedApps, EventFilters, etc)
…host-isolation-exceptions-to-artifact-list-page-componet
…host-isolation-exceptions-to-artifact-list-page-componet
…host-isolation-exceptions-to-artifact-list-page-componet # Conflicts: # x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/service.ts # x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/components/delete_modal.test.tsx # x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/components/form_flyout.test.tsx # x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/host_isolation_exceptions_list.test.tsx # x-pack/plugins/security_solution/public/management/pages/mocks/exceptions_list_http_mocks.ts # x-pack/plugins/security_solution/public/management/pages/policy/view/policy_details.test.tsx # x-pack/plugins/security_solution/public/management/pages/policy/view/tabs/policy_tabs.tsx
…host-isolation-exceptions-to-artifact-list-page-componet
…host-isolation-exceptions-to-artifact-list-page-componet
@elasticmachine merge upstream |
…-to-artifact-list-page-componet
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsasync chunk count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
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.
I only have a few minor comments and suggestions but this is good to 🚢 . Thanks for the refactor and adding all the helper methods and utils for tests. 🙏
const normalizeArtifactListPageUrlSearchParams = ( | ||
urlSearchParams: Partial<ArtifactListPageUrlParams> = {} | ||
): Partial<ArtifactListPageUrlParams> => { | ||
return { | ||
...(!isDefaultOrMissing(urlSearchParams.page, 1) ? { page: urlSearchParams.page } : {}), | ||
...(!isDefaultOrMissing(urlSearchParams.pageSize, MANAGEMENT_DEFAULT_PAGE_SIZE) | ||
? { pageSize: urlSearchParams.pageSize } | ||
: {}), | ||
...(!isDefaultOrMissing(urlSearchParams.show, undefined) ? { show: urlSearchParams.show } : {}), | ||
...(!isDefaultOrMissing(urlSearchParams.itemId, undefined) | ||
? { itemId: urlSearchParams.itemId } | ||
: {}), | ||
...(!isDefaultOrMissing(urlSearchParams.filter, '') ? { filter: urlSearchParams.filter } : ''), | ||
...(!isDefaultOrMissing(urlSearchParams.includedPolicies, '') | ||
? { includedPolicies: urlSearchParams.includedPolicies } | ||
: ''), | ||
}; | ||
}; | ||
|
||
export const extractArtifactListPageUrlSearchParams = ( | ||
query: querystring.ParsedUrlQuery | ||
): ArtifactListPageUrlParams => { | ||
const showParamValue = extractFirstParamValue(query, 'show') as ArtifactListPageUrlParams['show']; | ||
|
||
return { | ||
page: extractPageNumber(query), | ||
pageSize: extractPageSizeNumber(query), | ||
includedPolicies: extractFirstParamValue(query, 'includedPolicies'), | ||
show: | ||
showParamValue && SHOW_PARAM_ALLOWED_VALUES.includes(showParamValue) | ||
? showParamValue | ||
: undefined, | ||
itemId: extractFirstParamValue(query, 'itemId'), | ||
}; | ||
}; |
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.
Nice ⭐ Looks like I had the same idea in my PR here.
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.
I think I'll copy these changes into my own PR or wait for this to merge. After updating to use ArtifactListPageUrlParams
for types some of these helper methods become obsolete.
@@ -158,11 +160,11 @@ export const EffectedPolicySelect = memo<EffectedPolicySelectProps>( | |||
), | |||
policy, | |||
checked: isPolicySelected.has(policy.id) ? 'on' : undefined, | |||
disabled: isGlobal || !isPlatinumPlus, | |||
disabled: isGlobal || !isPlatinumPlus || disabled, |
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.
Should add a test for this change.
if (allowCardEditAction) { | ||
cardActions.push({ | ||
icon: 'controlsHorizontal', | ||
onClick: () => { | ||
onAction({ type: 'edit', item: artifactItem }); | ||
}, | ||
'data-test-subj': getTestId('cardEditAction'), | ||
children: cardActionEditLabel, | ||
}); | ||
} | ||
|
||
if (allowCardDeleteAction) { | ||
cardActions.push({ | ||
icon: 'trash', | ||
onClick: () => { | ||
onAction({ type: 'delete', item: artifactItem }); | ||
}, | ||
'data-test-subj': getTestId('cardDeleteAction'), | ||
children: cardActionDeleteLabel, | ||
}); | ||
} | ||
|
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.
Nice these will be enabled with future RBAC controls. 👏
export type ReactQueryClientProviderProps = PropsWithChildren<{ | ||
queryClient?: QueryClient; | ||
}>; |
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.
This is not used elsewhere, so no need to export.
* @param renderResult | ||
* @param [atIndex=0] | ||
*/ | ||
export const clickOnEffectedPolicy = async ( |
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.
This is super helpful. Thanks 🥇
* A general component for formatting errors. Recognizes different types of errors and displays | ||
* their information. | ||
*/ | ||
export const FormattedError = memo<FormattedErrorProps>( |
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.
🔥 awesome
@@ -38,7 +38,7 @@ describe('When displaying the EndpointPackageCustomExtension fleet UI extension' | |||
}); | |||
|
|||
afterEach(() => { | |||
useEndpointPrivilegesMock.mockReturnValue(getEndpointPrivilegesInitialStateMock()); | |||
useEndpointPrivilegesMock.mockImplementation(getEndpointPrivilegesInitialStateMock); |
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.
Nice!
export const HOST_ISOLATION_EXCEPTIONS_LIST_DEFINITION: CreateExceptionListSchema = { | ||
name: ENDPOINT_HOST_ISOLATION_EXCEPTIONS_LIST_NAME, | ||
namespace_type: 'agnostic', | ||
description: ENDPOINT_HOST_ISOLATION_EXCEPTIONS_LIST_DESCRIPTION, | ||
list_id: ENDPOINT_HOST_ISOLATION_EXCEPTIONS_LIST_ID, | ||
type: HOST_ISOLATION_EXCEPTIONS_LIST_TYPE, | ||
type: ExceptionListTypeEnum.ENDPOINT_HOST_ISOLATION_EXCEPTIONS, |
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.
This is nice! Although, I notice for some reason the trusted_apps list type is called endpoint
😱 . We should update it to match the other names. Perhaps endpoint_trusted_apps
. I'll do this in my PR if you agree.
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.
Yeah, you can do that as long as it does not break anything. This custom type
value was introduced at some point after TA and we never got to update TA to also have its own type.
refs elastic/pull/129099/commits/b688d505b460964117ba1a303b417760b13a2888
…e` component (#129208) * move validations to artifacts fixes elastic/security-team/issues/3092 * use ArtifactsListPage fixes elastic/security-team/issues/3092 * Remove redundant files fixes elastic/security-team/issues/3092 * Update trusted app list ftr test fixes elastic/security-team/issues/3092 * fix test mock fixes elastic/security-team/issues/3092 * add trusted app form tests fixes elastic/security-team/issues/3092 * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * default page index to 1 when set to 0 refs /pull/129099/commits/b688d505b460964117ba1a303b417760b13a2888 * add tests for new routing methods refs /pull/129099/ * review changes fixes elastic/security-team/issues/3092 * update fleet integration test without any trusted app entries, it should see the trusted empty page * update translation again after merge refs 6a792fc * add a test for search field KQL review suggestions * remove redundant flyout size defaults to `m` Co-authored-by: kibanamachine <[email protected]>
… page to now use `<ArtifactListPage/>` component (elastic#129099) * Move Host Isolation Exceptions to `<ArtifactListPage>` * New Generic FormatError component for formatting error Objects * clean up un-used components ++ hooks * EffectedPolicySelect support for `disabled` prop * new ExceptionsList HTTP mocks * additional test utilities for EffectedPolicySelect component * New url routing utilities for Artifact List Page * Refactor `useCanSeeHostIsolationExceptionsMenu()` hook to use generic `useSummaryArtifact()` hook * add props to ArtifactListPage to allow for hiding actions like create, edit, delete * Split out useUserPrivileges() mock implementation function for reuse and mock resets * add generic `getFirstCard()` test utility to ArtifactListPage mocks
…e` component (elastic#129208) * move validations to artifacts fixes elastic/security-team/issues/3092 * use ArtifactsListPage fixes elastic/security-team/issues/3092 * Remove redundant files fixes elastic/security-team/issues/3092 * Update trusted app list ftr test fixes elastic/security-team/issues/3092 * fix test mock fixes elastic/security-team/issues/3092 * add trusted app form tests fixes elastic/security-team/issues/3092 * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * default page index to 1 when set to 0 refs elastic/pull/129099/commits/b688d505b460964117ba1a303b417760b13a2888 * add tests for new routing methods refs elastic/pull/129099/ * review changes fixes elastic/security-team/issues/3092 * update fleet integration test without any trusted app entries, it should see the trusted empty page * update translation again after merge refs 6a792fc * add a test for search field KQL review suggestions * remove redundant flyout size defaults to `m` Co-authored-by: kibanamachine <[email protected]>
Summary
<ArtifactListPage>
component. Deletes several files from under the page's directory that no longer apply<FormatError/>
component for displaying formattedError
's<EffectedPolicySelect>
updated with new test utilities and support fordisabled
prop<ArtifactListPage>
component updated with additional props that allows for removing the Create, Edit or Delete actionsgetArtifactListPageUrlPath()
url routing utility for use with pages that utilize the<ArtifactListPage/>
componentChecklist