-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Cloud Security] [Findings] [Vulnerabilities] Vulnerabilities Table #154388
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
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
95260d5
renaming route to configurations
opauloh 500ea44
moving findings to configurations
opauloh b59284f
adding tabs to findings page
opauloh 57ebe16
adding vulnerabilities tab content placeholder
opauloh 3365ef7
fix i18n
opauloh 01bb8fe
remove unused translation
opauloh 191c44a
remove unused translation
opauloh 5e2385c
WIP: vulnerabilities table
opauloh 4857900
fixing test subj placement
opauloh bffd4a6
Merge branch 'main' into vuln/split-findings-page
opauloh b5f2b9b
Merge branch 'vuln/split-findings-page' into vuln/table
opauloh 1638246
Merge branch 'main' into vuln/table
opauloh 2495264
WIP: fix update index safe
opauloh 70491f5
Merge branch 'main' into vuln/table
opauloh 091e91f
wip moving common files
opauloh 0abf0cb
updating index pattern
opauloh a594a3e
wip: moving common files
opauloh b8ef0b0
wip: vulnerability table
opauloh f44a72c
Merge branch 'main' into vuln/table
opauloh 87f7165
data view index pattern
opauloh f6fc8a0
add new helper hook
opauloh befe2c3
add posture table helper hook
opauloh c1a0de4
moving files
opauloh b9fb3ec
updating latest findings table to new hook
opauloh 6b0f54f
moving files
opauloh 87623e8
vulnerabilities
opauloh c286e9d
add no results components
opauloh 4f575b3
adding method description
opauloh f0c06bc
adding wrapper and removing null
opauloh 9c4c3cc
fix casing
opauloh 7d7ed66
add badges
opauloh 7b816e3
Merge branch 'main' into vuln/table
opauloh 4d873cc
Merge branch 'main' into vuln/table
opauloh 89d20cc
update vulnerability schema
opauloh 016f8c8
remove message
opauloh 070a839
updating vulnerabilities utils
opauloh 1b7afe8
add translate and handle plural
opauloh 6c6e89f
Merge branch 'main' into vuln/table
opauloh 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 hidden or 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 hidden or 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
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/cloud_security_posture/public/common/api/use_filtered_data_view.ts
This file contains hidden or 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,45 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
| import type { DataView } from '@kbn/data-plugin/common'; | ||
| import { DATA_VIEW_INDEX_PATTERN } from '../../../common/constants'; | ||
| import { CspClientPluginStartDeps } from '../../types'; | ||
|
|
||
| /** | ||
| * Returns the common logs-* data view with fields filtered by | ||
| * fields present in the given index pattern | ||
| */ | ||
| export const useFilteredDataView = (indexPattern: string) => { | ||
| const { | ||
| data: { dataViews }, | ||
| } = useKibana<CspClientPluginStartDeps>().services; | ||
|
|
||
| const findDataView = async (): Promise<DataView> => { | ||
| const dataView = (await dataViews.find(DATA_VIEW_INDEX_PATTERN))?.[0]; | ||
| if (!dataView) { | ||
| throw new Error('Findings data view not found'); | ||
| } | ||
|
|
||
| const indexPatternFields = await dataViews.getFieldsForWildcard({ | ||
| pattern: indexPattern, | ||
| }); | ||
|
|
||
| if (!indexPatternFields) { | ||
| throw new Error('Error fetching fields for the index pattern'); | ||
| } | ||
|
|
||
| dataView.fields = dataView.fields.filter((field) => | ||
| indexPatternFields.some((indexPatternField) => indexPatternField.name === field.name) | ||
| ) as DataView['fields']; | ||
|
|
||
| return dataView; | ||
| }; | ||
|
|
||
| return useQuery(['latest_findings_data_view', indexPattern], findDataView); | ||
| }; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/cloud_security_posture/public/common/hooks/use_cloud_posture_table/index.ts
This file contains hidden or 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,8 @@ | ||
| /* | ||
| * 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 './use_cloud_posture_table'; |
100 changes: 100 additions & 0 deletions
100
...d_security_posture/public/common/hooks/use_cloud_posture_table/use_cloud_posture_table.ts
This file contains hidden or 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,100 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| import { useCallback } from 'react'; | ||
| import { type DataView } from '@kbn/data-views-plugin/common'; | ||
| import { useUrlQuery } from '../use_url_query'; | ||
| import { usePageSize } from '../use_page_size'; | ||
| import { getDefaultQuery, useBaseEsQuery, usePersistedQuery } from './utils'; | ||
|
|
||
| /* | ||
| Hook for managing common table state and methods for Cloud Posture | ||
| */ | ||
| export const useCloudPostureTable = ({ | ||
| defaultQuery = getDefaultQuery, | ||
| dataView, | ||
| paginationLocalStorageKey, | ||
| }: { | ||
| defaultQuery?: (params: any) => any; | ||
| dataView: DataView; | ||
| paginationLocalStorageKey: string; | ||
| }) => { | ||
| const getPersistedDefaultQuery = usePersistedQuery(defaultQuery); | ||
| const { urlQuery, setUrlQuery } = useUrlQuery(getPersistedDefaultQuery); | ||
| const { pageSize, setPageSize } = usePageSize(paginationLocalStorageKey); | ||
|
|
||
| const onChangeItemsPerPage = useCallback( | ||
| (newPageSize) => { | ||
| setPageSize(newPageSize); | ||
| setUrlQuery({ | ||
| pageIndex: 0, | ||
| }); | ||
| }, | ||
| [setUrlQuery, setPageSize] | ||
| ); | ||
|
|
||
| const onChangePage = useCallback( | ||
| (newPageIndex) => { | ||
| setUrlQuery({ | ||
| pageIndex: newPageIndex, | ||
| }); | ||
| }, | ||
| [setUrlQuery] | ||
| ); | ||
|
|
||
| const onSort = useCallback( | ||
| (sort) => { | ||
| setUrlQuery({ | ||
| sort, | ||
| }); | ||
| }, | ||
| [setUrlQuery] | ||
| ); | ||
|
|
||
| const setTableOptions = useCallback( | ||
| ({ page, sort }) => { | ||
| setPageSize(page.size); | ||
| setUrlQuery({ | ||
| sort, | ||
| pageIndex: page.index, | ||
| }); | ||
| }, | ||
| [setUrlQuery, setPageSize] | ||
| ); | ||
|
|
||
| /** | ||
| * Page URL query to ES query | ||
| */ | ||
| const baseEsQuery = useBaseEsQuery({ | ||
| dataView, | ||
| filters: urlQuery.filters, | ||
| query: urlQuery.query, | ||
| }); | ||
|
|
||
| const handleUpdateQuery = useCallback( | ||
| (query) => { | ||
| setUrlQuery({ ...query, pageIndex: 0 }); | ||
| }, | ||
| [setUrlQuery] | ||
| ); | ||
|
|
||
| return { | ||
| setUrlQuery, | ||
| sort: urlQuery.sort, | ||
| filters: urlQuery.filters, | ||
| query: baseEsQuery.query, | ||
| queryError: baseEsQuery.error, | ||
| pageIndex: urlQuery.pageIndex, | ||
| urlQuery, | ||
| setTableOptions, | ||
| handleUpdateQuery, | ||
| pageSize, | ||
| setPageSize, | ||
| onChangeItemsPerPage, | ||
| onChangePage, | ||
| onSort, | ||
| }; | ||
| }; |
113 changes: 113 additions & 0 deletions
113
x-pack/plugins/cloud_security_posture/public/common/hooks/use_cloud_posture_table/utils.ts
This file contains hidden or 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,113 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| import { useEffect, useCallback, useMemo } from 'react'; | ||
| import { buildEsQuery } from '@kbn/es-query'; | ||
| import type { EuiBasicTableProps, Pagination } from '@elastic/eui'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { type Query } from '@kbn/es-query'; | ||
| import { useKibana } from '../use_kibana'; | ||
| import type { FindingsBaseProps, FindingsBaseURLQuery } from '../../types'; | ||
|
|
||
| const getBaseQuery = ({ dataView, query, filters }: FindingsBaseURLQuery & FindingsBaseProps) => { | ||
| try { | ||
| return { | ||
| query: buildEsQuery(dataView, query, filters), // will throw for malformed query | ||
| }; | ||
| } catch (error) { | ||
| return { | ||
| query: undefined, | ||
| error: error instanceof Error ? error : new Error('Unknown Error'), | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| type TablePagination = NonNullable<EuiBasicTableProps<unknown>['pagination']>; | ||
|
|
||
| export const getPaginationTableParams = ( | ||
| params: TablePagination & Pick<Required<TablePagination>, 'pageIndex' | 'pageSize'>, | ||
| pageSizeOptions = [10, 25, 100], | ||
| showPerPageOptions = true | ||
| ): Required<TablePagination> => ({ | ||
| ...params, | ||
| pageSizeOptions, | ||
| showPerPageOptions, | ||
| }); | ||
|
|
||
| export const getPaginationQuery = ({ | ||
| pageIndex, | ||
| pageSize, | ||
| }: Pick<Pagination, 'pageIndex' | 'pageSize'>) => ({ | ||
| from: pageIndex * pageSize, | ||
| size: pageSize, | ||
| }); | ||
|
|
||
| export const useBaseEsQuery = ({ | ||
| dataView, | ||
| filters, | ||
| query, | ||
| }: FindingsBaseURLQuery & FindingsBaseProps) => { | ||
| const { | ||
| notifications: { toasts }, | ||
| data: { | ||
| query: { filterManager, queryString }, | ||
| }, | ||
| } = useKibana().services; | ||
|
|
||
| const baseEsQuery = useMemo( | ||
| () => getBaseQuery({ dataView, filters, query }), | ||
| [dataView, filters, query] | ||
| ); | ||
|
|
||
| /** | ||
| * Sync filters with the URL query | ||
| */ | ||
| useEffect(() => { | ||
| filterManager.setAppFilters(filters); | ||
| queryString.setQuery(query); | ||
| }, [filters, filterManager, queryString, query]); | ||
|
|
||
| const handleMalformedQueryError = () => { | ||
| const error = baseEsQuery.error; | ||
| if (error) { | ||
| toasts.addError(error, { | ||
| title: i18n.translate('xpack.csp.findings.search.queryErrorToastMessage', { | ||
| defaultMessage: 'Query Error', | ||
| }), | ||
| toastLifeTimeMs: 1000 * 5, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| useEffect(handleMalformedQueryError, [baseEsQuery.error, toasts]); | ||
|
|
||
| return baseEsQuery; | ||
| }; | ||
|
|
||
| export const usePersistedQuery = <T>(getter: ({ filters, query }: FindingsBaseURLQuery) => T) => { | ||
| const { | ||
| data: { | ||
| query: { filterManager, queryString }, | ||
| }, | ||
| } = useKibana().services; | ||
|
|
||
| return useCallback( | ||
| () => | ||
| getter({ | ||
| filters: filterManager.getAppFilters(), | ||
| query: queryString.getQuery() as Query, | ||
| }), | ||
| [getter, filterManager, queryString] | ||
| ); | ||
| }; | ||
|
|
||
| export const getDefaultQuery = ({ query, filters }: any): any => ({ | ||
| query, | ||
| filters, | ||
| sort: { field: '@timestamp', direction: 'desc' }, | ||
| pageIndex: 0, | ||
| }); |
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/cloud_security_posture/public/common/utils/show_error_toast.ts
This file contains hidden or 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,22 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| import type { CoreStart } from '@kbn/core/public'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { extractErrorMessage } from '../../../common/utils/helpers'; | ||
|
|
||
| const SEARCH_FAILED_TEXT = i18n.translate( | ||
| 'xpack.csp.findings.findingsErrorToast.searchFailedTitle', | ||
| { defaultMessage: 'Search failed' } | ||
| ); | ||
|
|
||
| export const showErrorToast = ( | ||
| toasts: CoreStart['notifications']['toasts'], | ||
| error: unknown | ||
| ): void => { | ||
| if (error instanceof Error) toasts.addError(error, { title: SEARCH_FAILED_TEXT }); | ||
| else toasts.addDanger(extractErrorMessage(error, SEARCH_FAILED_TEXT)); | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.