forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
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] Refactor host isolation exceptions list…
… 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
- Loading branch information
1 parent
a6f4ef4
commit f1a3edf
Showing
53 changed files
with
1,172 additions
and
2,416 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
76 changes: 76 additions & 0 deletions
76
...gins/security_solution/public/management/common/url_routing/artifact_list_page_routing.ts
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,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under 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. | ||
*/ | ||
|
||
// FIXME: Remove references to `querystring` | ||
// eslint-disable-next-line import/no-nodejs-modules | ||
import querystring from 'querystring'; | ||
import { ArtifactListPageUrlParams } from '../../components/artifact_list_page'; | ||
import { | ||
isDefaultOrMissing, | ||
extractFirstParamValue, | ||
extractPageSizeNumber, | ||
extractPageNumber, | ||
} from './utils'; | ||
import { MANAGEMENT_DEFAULT_PAGE_SIZE } from '../constants'; | ||
import { appendSearch } from '../../../common/components/link_to/helpers'; | ||
|
||
const SHOW_PARAM_ALLOWED_VALUES: ReadonlyArray<Required<ArtifactListPageUrlParams>['show']> = [ | ||
'edit', | ||
'create', | ||
]; | ||
|
||
/** | ||
* Normalizes the URL search params by dropping any that are either undefined or whose value is | ||
* equal to the default value. | ||
* @param urlSearchParams | ||
*/ | ||
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'), | ||
}; | ||
}; | ||
|
||
export const getArtifactListPageUrlPath = ( | ||
/** The path to the desired page that is using the `<ArtifactListPage>` component */ | ||
path: string, | ||
/** An optional set of url search params. These will be normalized prior to being appended to the url path */ | ||
searchParams: Partial<ArtifactListPageUrlParams> = {} | ||
): string => { | ||
return `${path}${appendSearch( | ||
querystring.stringify(normalizeArtifactListPageUrlSearchParams(searchParams)) | ||
)}`; | ||
}; |
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/security_solution/public/management/common/url_routing/index.ts
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,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under 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. | ||
*/ | ||
|
||
export * from './utils'; | ||
export { | ||
getArtifactListPageUrlPath, | ||
extractArtifactListPageUrlSearchParams, | ||
} from './artifact_list_page_routing'; |
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/security_solution/public/management/common/url_routing/utils.ts
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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
// eslint-disable-next-line import/no-nodejs-modules | ||
import querystring from 'querystring'; | ||
import { MANAGEMENT_DEFAULT_PAGE_SIZE, MANAGEMENT_PAGE_SIZE_OPTIONS } from '../constants'; | ||
|
||
/** | ||
* Checks if a given value is either undefined or equal to the default value provided on input | ||
* @param value | ||
* @param defaultValue | ||
*/ | ||
export const isDefaultOrMissing = <T>(value: T | undefined, defaultValue: T) => { | ||
return value === undefined || value === defaultValue; | ||
}; | ||
|
||
/** | ||
* Given an object with url params, and a given key, return back only the first param value (case multiples were defined) | ||
* @param query | ||
* @param key | ||
*/ | ||
export const extractFirstParamValue = ( | ||
query: querystring.ParsedUrlQuery, | ||
key: string | ||
): string | undefined => { | ||
const value = query[key]; | ||
|
||
return Array.isArray(value) ? value[value.length - 1] : value; | ||
}; | ||
|
||
/** | ||
* Extracts the page number from a url query object `page` param and validates it. | ||
* @param query | ||
*/ | ||
export const extractPageNumber = (query: querystring.ParsedUrlQuery): number => { | ||
const pageIndex = Number(extractFirstParamValue(query, 'page')); | ||
|
||
return !Number.isFinite(pageIndex) || pageIndex < 1 ? 1 : pageIndex; | ||
}; | ||
|
||
/** | ||
* Extracts the page size from a url query object `pageSize` param and validates it | ||
* @param query | ||
*/ | ||
export const extractPageSizeNumber = (query: querystring.ParsedUrlQuery): number => { | ||
const pageSize = Number(extractFirstParamValue(query, 'pageSize')); | ||
|
||
return MANAGEMENT_PAGE_SIZE_OPTIONS.includes(pageSize) ? pageSize : MANAGEMENT_DEFAULT_PAGE_SIZE; | ||
}; |
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.