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.
[Cloud Posture] [Quick wins] Enable edit DataView on the Misconfigura…
…tions Findings Table (elastic#173870) ## Summary This PR is part of the [Quick Wins](elastic/security-team#8254) improvements for 8.13.0. It enables the Edit DataView option on the Misconfigurations Findings Page. It also adds the following: - Unit tests to test the basic functionality of the `CloudSecurityDataTable` component. - Updated unit tests on the configurations page to reflect the current hook - Added deprecation notice on the `useCloudSecurityTable` hook. - FTR test to check if the option to edit DataView is enabled. - A Check on the `useLatestFindingsDataView` hook to only update when needed (This update logic is [planned](elastic#172615) to be replaced by a server-side callback when installing the Cloud Security integration. Still, for now, it is an improvement over the current logic). ### Screenshots ![image](https://github.com/elastic/kibana/assets/19270322/b7b738a6-4b90-4c9d-af15-fc91ca4a92d4) ![image](https://github.com/elastic/kibana/assets/19270322/44649e30-7bb3-4eec-83ca-d3ec7924c527) ![image](https://github.com/elastic/kibana/assets/19270322/accf66b1-882f-4c04-837c-24c8953aba2f)
- Loading branch information
Showing
12 changed files
with
182 additions
and
31 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
102 changes: 102 additions & 0 deletions
102
...ty_posture/public/components/cloud_security_data_table/cloud_security_data_table.test.tsx
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,102 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { TestProvider } from '../../test/test_provider'; | ||
import { CloudSecurityDataTable, CloudSecurityDataTableProps } from './cloud_security_data_table'; | ||
|
||
const mockDataView = { | ||
fields: { | ||
getAll: () => [ | ||
{ id: 'field1', name: 'field1', customLabel: 'Label 1', visualizable: true }, | ||
{ id: 'field2', name: 'field2', customLabel: 'Label 2', visualizable: true }, | ||
], | ||
getByName: (name: string) => ({ id: name }), | ||
}, | ||
getFieldByName: (name: string) => ({ id: name }), | ||
getFormatterForField: (name: string) => ({ | ||
convert: (value: string) => value, | ||
}), | ||
} as any; | ||
|
||
const mockDefaultColumns = [{ id: 'field1' }, { id: 'field2' }]; | ||
|
||
const mockCloudPostureDataTable = { | ||
setUrlQuery: jest.fn(), | ||
columnsLocalStorageKey: 'test', | ||
filters: [], | ||
onSort: jest.fn(), | ||
sort: [], | ||
query: {}, | ||
queryError: undefined, | ||
pageIndex: 0, | ||
urlQuery: {}, | ||
setTableOptions: jest.fn(), | ||
handleUpdateQuery: jest.fn(), | ||
pageSize: 10, | ||
setPageSize: jest.fn(), | ||
onChangeItemsPerPage: jest.fn(), | ||
onChangePage: jest.fn(), | ||
onResetFilters: jest.fn(), | ||
getRowsFromPages: jest.fn(), | ||
} as any; | ||
|
||
const renderDataTable = (props: Partial<CloudSecurityDataTableProps> = {}) => { | ||
const defaultProps: CloudSecurityDataTableProps = { | ||
dataView: mockDataView, | ||
isLoading: false, | ||
defaultColumns: mockDefaultColumns, | ||
rows: [], | ||
total: 0, | ||
flyoutComponent: () => <></>, | ||
cloudPostureDataTable: mockCloudPostureDataTable, | ||
loadMore: jest.fn(), | ||
title: 'Test Table', | ||
}; | ||
|
||
return render( | ||
<TestProvider> | ||
<CloudSecurityDataTable {...defaultProps} {...props} /> | ||
</TestProvider> | ||
); | ||
}; | ||
|
||
describe('CloudSecurityDataTable', () => { | ||
it('renders loading state', () => { | ||
const { getByTestId } = renderDataTable({ isLoading: true }); | ||
expect(getByTestId('unifiedDataTableLoading')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders empty state when no rows are present', () => { | ||
const { getByTestId } = renderDataTable(); | ||
expect(getByTestId('csp:empty-state')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders data table with rows', async () => { | ||
const mockRows = [ | ||
{ | ||
id: '1', | ||
raw: { | ||
field1: 'Label 1', | ||
field2: 'Label 2', | ||
}, | ||
flattened: { | ||
field1: 'Label 1', | ||
field2: 'Label 2', | ||
}, | ||
}, | ||
] as any; | ||
const { getByTestId, getByText } = renderDataTable({ | ||
rows: mockRows, | ||
total: mockRows.length, | ||
}); | ||
|
||
expect(getByTestId('discoverDocTable')).toBeInTheDocument(); | ||
expect(getByText('Label 1')).toBeInTheDocument(); | ||
expect(getByText('Label 2')).toBeInTheDocument(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.