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

[Cloud Security] CloudSecurityDataTable component #167587

Merged
merged 26 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e2bce7a
WIP: unified datatable
opauloh Sep 21, 2023
b62831f
WIP: cloud security data table
opauloh Sep 26, 2023
8bf5bee
Merge branch 'main' into unified-data-grid/foundation
opauloh Sep 26, 2023
f838a25
WIP: Cloud Security DataTable
opauloh Sep 27, 2023
50a7da9
data table component
opauloh Sep 29, 2023
d86aca3
layout consistency
opauloh Sep 29, 2023
372f994
fix data view function
opauloh Sep 29, 2023
b3d1d87
adding constants
opauloh Sep 29, 2023
dc1c90c
fix type and sorting
opauloh Sep 29, 2023
0f8dcdb
revert changes
opauloh Sep 29, 2023
5737847
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 29, 2023
fb560d9
enable multi filtering
opauloh Sep 29, 2023
6cb56c9
Merge remote-tracking branch 'origin/unified-data-grid/foundation' in…
opauloh Sep 29, 2023
397f09a
adding todos
opauloh Oct 1, 2023
3abd3dd
updating translations
opauloh Oct 1, 2023
8b4bace
fixing lexical sort
opauloh Oct 1, 2023
3cdfdae
removing unused function
opauloh Oct 1, 2023
2905d02
fixing FTR tests
opauloh Oct 1, 2023
9ffeca0
changing FTR methods for the datatable
opauloh Oct 1, 2023
196d6a4
removing unused fields
opauloh Oct 1, 2023
c6ab64d
Merge branch 'main' into unified-data-grid/foundation
opauloh Oct 1, 2023
8820da8
add partial types
opauloh Oct 1, 2023
279d6b3
Update x-pack/plugins/cloud_security_posture/public/common/api/use_la…
opauloh Oct 4, 2023
7050e51
Update use_latest_findings_data_view.ts
opauloh Oct 4, 2023
ad8219f
change the deprecated api
opauloh Oct 4, 2023
e1dc390
Merge branch 'main' into unified-data-grid/foundation
opauloh Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion x-pack/plugins/cloud_security_posture/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"requiredPlugins": [
"navigation",
"data",
"dataViews",
"fleet",
"unifiedSearch",
"taskManager",
Expand All @@ -19,7 +20,8 @@
"discover",
"cloud",
"licensing",
"share"
"share",
"kibanaUtils"
],
"optionalPlugins": ["usageCollection"],
"requiredBundles": ["kibanaReact", "usageCollection"]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,45 @@
import { useQuery } from '@tanstack/react-query';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import type { DataView } from '@kbn/data-plugin/common';
import { i18n } from '@kbn/i18n';
import { LATEST_FINDINGS_INDEX_PATTERN } from '../../../common/constants';
import { CspClientPluginStartDeps } from '../../types';

const cloudSecurityFieldLabels: Record<string, string> = {
'result.evaluation': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.resultColumnLabel',
{ defaultMessage: 'Result' }
),
'resource.id': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.resourceIdColumnLabel',
{ defaultMessage: 'Resource ID' }
),
'resource.name': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.resourceNameColumnLabel',
{ defaultMessage: 'Resource Name' }
),
'resource.sub_type': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.resourceTypeColumnLabel',
{ defaultMessage: 'Resource Type' }
),
'rule.benchmark.rule_number': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.ruleNumberColumnLabel',
{ defaultMessage: 'Rule Number' }
),
'rule.name': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.ruleNameColumnLabel',
{ defaultMessage: 'Rule Name' }
),
'rule.section': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.ruleSectionColumnLabel',
{ defaultMessage: 'CIS Section' }
),
'@timestamp': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.lastCheckedColumnLabel',
{ defaultMessage: 'Last Checked' }
),
} as const;

/**
* TODO: use perfected kibana data views
*/
Expand All @@ -19,11 +56,23 @@ export const useLatestFindingsDataView = (dataView: string) => {
} = useKibana<CspClientPluginStartDeps>().services;

const findDataView = async (): Promise<DataView> => {
const dataViewObj = (await dataViews.find(dataView))?.[0];
const [dataViewObj] = await dataViews.find(dataView);
if (!dataViewObj) {
throw new Error(`Data view not found [Name: {${dataView}}]`);
}

if (dataView === LATEST_FINDINGS_INDEX_PATTERN) {
Object.entries(cloudSecurityFieldLabels).forEach(([field, label]) => {
if (
!dataViewObj.getFieldAttrs()[field]?.customLabel ||
dataViewObj.getFieldAttrs()[field]?.customLabel === field
) {
dataViewObj.setFieldCustomLabel(field, label);
}
});
await dataViews.updateSavedObject(dataViewObj);
}

return dataViewObj;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const CSP_MOMENT_FORMAT = 'MMMM D, YYYY @ HH:mm:ss.SSS';
export const MAX_FINDINGS_TO_LOAD = 500;
export const DEFAULT_VISIBLE_ROWS_PER_PAGE = 25;

export const LOCAL_STORAGE_DATA_TABLE_PAGE_SIZE_KEY = 'cloudPosture:dataTable:pageSize';
export const LOCAL_STORAGE_DATA_TABLE_COLUMNS_KEY = 'cloudPosture:dataTable:columns';
export const LOCAL_STORAGE_PAGE_SIZE_FINDINGS_KEY = 'cloudPosture:findings:pageSize';
export const LOCAL_STORAGE_PAGE_SIZE_BENCHMARK_KEY = 'cloudPosture:benchmark:pageSize';
export const LOCAL_STORAGE_PAGE_SIZE_RULES_KEY = 'cloudPosture:rules:pageSize';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,36 @@ import { Dispatch, SetStateAction, useCallback } from 'react';
import { type DataView } from '@kbn/data-views-plugin/common';
import { BoolQuery } from '@kbn/es-query';
import { CriteriaWithPagination } from '@elastic/eui';
import { DataTableRecord } from '@kbn/discover-utils/types';
import { useUrlQuery } from '../use_url_query';
import { usePageSize } from '../use_page_size';
import { getDefaultQuery, useBaseEsQuery, usePersistedQuery } from './utils';

interface QuerySort {
direction: string;
id: string;
}
import { LOCAL_STORAGE_DATA_TABLE_COLUMNS_KEY } from '../../constants';

export interface CloudPostureTableResult {
// TODO: Remove any when all finding tables are converted to CloudSecurityDataTable
setUrlQuery: (query: any) => void;
// TODO: remove any, this sorting is used for both EuiGrid and EuiTable which uses different types of sorts
// TODO: Remove any when all finding tables are converted to CloudSecurityDataTable
sort: any;
// TODO: Remove any when all finding tables are converted to CloudSecurityDataTable
filters: any[];
query?: { bool: BoolQuery };
queryError?: Error;
pageIndex: number;
// TODO: remove any, urlQuery is an object with query fields but we also add custom fields to it, need to assert usages
urlQuery: any;
setTableOptions: (options: CriteriaWithPagination<object>) => void;
// TODO: Remove any when all finding tables are converted to CloudSecurityDataTable
handleUpdateQuery: (query: any) => void;
pageSize: number;
setPageSize: Dispatch<SetStateAction<number | undefined>>;
onChangeItemsPerPage: (newPageSize: number) => void;
onChangePage: (newPageIndex: number) => void;
onSort: (sort: QuerySort[]) => void;
// TODO: Remove any when all finding tables are converted to CloudSecurityDataTable
onSort: (sort: any) => void;
onResetFilters: () => void;
columnsLocalStorageKey: string;
getRowsFromPages: (data: Array<{ page: DataTableRecord[] }> | undefined) => DataTableRecord[];
}

/*
Expand All @@ -44,10 +47,13 @@ export const useCloudPostureTable = ({
defaultQuery = getDefaultQuery,
dataView,
paginationLocalStorageKey,
columnsLocalStorageKey,
}: {
// TODO: Remove any when all finding tables are converted to CloudSecurityDataTable
defaultQuery?: (params: any) => any;
dataView: DataView;
paginationLocalStorageKey: string;
columnsLocalStorageKey?: string;
}): CloudPostureTableResult => {
const getPersistedDefaultQuery = usePersistedQuery(defaultQuery);
const { urlQuery, setUrlQuery } = useUrlQuery(getPersistedDefaultQuery);
Expand Down Expand Up @@ -120,6 +126,13 @@ export const useCloudPostureTable = ({
[setUrlQuery]
);

const getRowsFromPages = (data: Array<{ page: DataTableRecord[] }> | undefined) =>
data
?.map(({ page }: { page: DataTableRecord[] }) => {
return page;
})
.flat() || [];

return {
setUrlQuery,
sort: urlQuery.sort,
Expand All @@ -136,5 +149,7 @@ export const useCloudPostureTable = ({
onChangePage,
onSort,
onResetFilters,
columnsLocalStorageKey: columnsLocalStorageKey || LOCAL_STORAGE_DATA_TABLE_COLUMNS_KEY,
getRowsFromPages,
};
};
Loading
Loading