Skip to content
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

paul-tavares
Copy link
Contributor

@paul-tavares paul-tavares commented Mar 31, 2022

Summary

  • Refactors the Host Isolation Exceptions page to use the new <ArtifactListPage> component. Deletes several files from under the page's directory that no longer apply
  • Refactor some policy details code to use generic artifact data hooks + Exceptions api client instad of custom hooks/services that were under the Host Isolations Exceptions
  • New generic <FormatError/> component for displaying formatted Error's
  • <EffectedPolicySelect> updated with new test utilities and support for disabled prop
  • <ArtifactListPage> component updated with additional props that allows for removing the Create, Edit or Delete actions
  • New generic getArtifactListPageUrlPath() url routing utility for use with pages that utilize the <ArtifactListPage/> component

olm-3094-refactor-hie-to-artifactListPage

Checklist

@paul-tavares paul-tavares added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:Defend Workflows “EDR Workflows” sub-team of Security Solution OLM Sprint v8.3.0 labels Mar 31, 2022
@paul-tavares paul-tavares self-assigned this Mar 31, 2022
* @param renderResult
* @param [atIndex=0]
*/
export const clickOnEffectedPolicy = async (
Copy link
Contributor Author

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.

Copy link
Member

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
…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
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt)

* 2.0.
*/

export * from './utils';
Copy link
Contributor Author

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.
*/
Copy link
Contributor Author

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;
Copy link
Contributor Author

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>(
Copy link
Contributor Author

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.

Copy link
Member

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 @@
/*
Copy link
Contributor Author

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)

@paul-tavares paul-tavares requested a review from a team as a code owner April 7, 2022 15:45
…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
@paul-tavares
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2777 2775 -2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 4.8MB 4.8MB -13.8KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 248.0KB 248.1KB +37.0B
Unknown metric groups

async chunk count

id before after diff
securitySolution 23 24 +1

ESLint disabled line counts

id before after diff
securitySolution 448 449 +1

Total ESLint disabled count

id before after diff
securitySolution 517 518 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @paul-tavares

Copy link
Member

@ashokaditya ashokaditya left a 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. 🙏

Comment on lines +31 to +65
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'),
};
};
Copy link
Member

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.

Copy link
Member

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,
Copy link
Member

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.

Comment on lines +68 to +89
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,
});
}

Copy link
Member

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. 👏

Comment on lines +11 to +13
export type ReactQueryClientProviderProps = PropsWithChildren<{
queryClient?: QueryClient;
}>;
Copy link
Member

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 (
Copy link
Member

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>(
Copy link
Member

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);
Copy link
Member

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

@paul-tavares paul-tavares merged commit cc34125 into elastic:main Apr 19, 2022
@paul-tavares paul-tavares deleted the task/olm-3094-move-host-isolation-exceptions-to-artifact-list-page-componet branch April 19, 2022 14:56
ashokaditya added a commit to ashokaditya/kibana that referenced this pull request Apr 20, 2022
refs elastic/pull/129099/commits/b688d505b460964117ba1a303b417760b13a2888
ashokaditya added a commit to ashokaditya/kibana that referenced this pull request Apr 20, 2022
ashokaditya added a commit that referenced this pull request Apr 21, 2022
…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]>
kertal pushed a commit to kertal/kibana that referenced this pull request May 24, 2022
… 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
kertal pushed a commit to kertal/kibana that referenced this pull request May 24, 2022
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting OLM Sprint release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants