-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security solution] [RAC] Add checkbox control column to t-grid (#107144
) (#107630) * Add checkbox control column to t-grid * Add unit tests * Update translations Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
6f7c022
commit 23e3037
Showing
12 changed files
with
299 additions
and
66 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
x-pack/plugins/timelines/public/components/t_grid/body/control_columns/checkbox.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,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. | ||
*/ | ||
|
||
import { render, fireEvent } from '@testing-library/react'; | ||
import { ActionProps, HeaderActionProps, TimelineTabs } from '../../../../../common'; | ||
import { HeaderCheckBox, RowCheckBox } from './checkbox'; | ||
import React from 'react'; | ||
|
||
describe('checkbox control column', () => { | ||
describe('RowCheckBox', () => { | ||
const defaultProps: ActionProps = { | ||
ariaRowindex: 1, | ||
columnId: 'test-columnId', | ||
columnValues: 'test-columnValues', | ||
checked: false, | ||
onRowSelected: jest.fn(), | ||
eventId: 'test-event-id', | ||
loadingEventIds: [], | ||
onEventDetailsPanelOpened: jest.fn(), | ||
showCheckboxes: true, | ||
data: [], | ||
ecsData: { | ||
_id: 'test-ecsData-id', | ||
}, | ||
index: 1, | ||
rowIndex: 1, | ||
showNotes: true, | ||
timelineId: 'test-timelineId', | ||
}; | ||
test('displays loader when id is included on loadingEventIds', () => { | ||
const { getByTestId } = render( | ||
<RowCheckBox {...defaultProps} loadingEventIds={[defaultProps.eventId]} /> | ||
); | ||
expect(getByTestId('event-loader')).not.toBeNull(); | ||
}); | ||
|
||
test('calls onRowSelected when checked', () => { | ||
const onRowSelected = jest.fn(); | ||
const { getByTestId } = render( | ||
<RowCheckBox {...defaultProps} onRowSelected={onRowSelected} /> | ||
); | ||
|
||
fireEvent.click(getByTestId('select-event')); | ||
|
||
expect(onRowSelected).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('HeaderCheckBox', () => { | ||
const defaultProps: HeaderActionProps = { | ||
width: 99999, | ||
browserFields: {}, | ||
columnHeaders: [], | ||
isSelectAllChecked: true, | ||
onSelectAll: jest.fn(), | ||
showEventsSelect: true, | ||
showSelectAllCheckbox: true, | ||
sort: [], | ||
tabType: TimelineTabs.query, | ||
timelineId: 'test-timelineId', | ||
}; | ||
|
||
test('calls onSelectAll when checked', () => { | ||
const onSelectAll = jest.fn(); | ||
const { getByTestId } = render( | ||
<HeaderCheckBox {...defaultProps} onSelectAll={onSelectAll} /> | ||
); | ||
fireEvent.click(getByTestId('select-all-events')); | ||
|
||
expect(onSelectAll).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
x-pack/plugins/timelines/public/components/t_grid/body/control_columns/checkbox.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,59 @@ | ||
/* | ||
* 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 { EuiCheckbox, EuiLoadingSpinner } from '@elastic/eui'; | ||
import React, { useCallback } from 'react'; | ||
import { ActionProps, HeaderActionProps } from '../../../../../common'; | ||
import * as i18n from './translations'; | ||
|
||
export const RowCheckBox = ({ | ||
eventId, | ||
onRowSelected, | ||
checked, | ||
ariaRowindex, | ||
columnValues, | ||
loadingEventIds, | ||
}: ActionProps) => { | ||
const handleSelectEvent = useCallback( | ||
(event: React.ChangeEvent<HTMLInputElement>) => | ||
onRowSelected({ | ||
eventIds: [eventId], | ||
isSelected: event.currentTarget.checked, | ||
}), | ||
[eventId, onRowSelected] | ||
); | ||
|
||
return loadingEventIds.includes(eventId) ? ( | ||
<EuiLoadingSpinner size="m" data-test-subj="event-loader" /> | ||
) : ( | ||
<EuiCheckbox | ||
data-test-subj="select-event" | ||
id={eventId} | ||
checked={checked} | ||
onChange={handleSelectEvent} | ||
aria-label={i18n.CHECKBOX_FOR_ROW({ ariaRowindex, columnValues, checked })} | ||
/> | ||
); | ||
}; | ||
|
||
export const HeaderCheckBox = ({ onSelectAll, isSelectAllChecked }: HeaderActionProps) => { | ||
const handleSelectPageChange = useCallback( | ||
(event: React.ChangeEvent<HTMLInputElement>) => { | ||
onSelectAll({ isSelected: event.currentTarget.checked }); | ||
}, | ||
[onSelectAll] | ||
); | ||
|
||
return ( | ||
<EuiCheckbox | ||
data-test-subj="select-all-events" | ||
id="select-all-events" | ||
checked={isSelectAllChecked} | ||
onChange={handleSelectPageChange} | ||
/> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/timelines/public/components/t_grid/body/control_columns/index.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,16 @@ | ||
/* | ||
* 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 { ControlColumnProps } from '../../../../../common'; | ||
import { HeaderCheckBox, RowCheckBox } from './checkbox'; | ||
|
||
export const checkBoxControlColumn: ControlColumnProps = { | ||
id: 'checkbox-control-column', | ||
width: 32, | ||
headerCellRender: HeaderCheckBox, | ||
rowCellRender: RowCheckBox, | ||
}; |
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/timelines/public/components/t_grid/body/control_columns/translations.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,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 { i18n } from '@kbn/i18n'; | ||
|
||
export const CHECKBOX_FOR_ROW = ({ | ||
ariaRowindex, | ||
columnValues, | ||
checked, | ||
}: { | ||
ariaRowindex: number; | ||
columnValues: string; | ||
checked: boolean; | ||
}) => | ||
i18n.translate('xpack.timelines.timeline.body.actions.checkboxForRowAriaLabel', { | ||
values: { ariaRowindex, checked, columnValues }, | ||
defaultMessage: | ||
'{checked, select, false {unchecked} true {checked}} checkbox for the alert or event in row {ariaRowindex}, with columns {columnValues}', | ||
}); |
Oops, something went wrong.