-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[OneDiscover][Extension] DataTable Row Actions #188762
Merged
Merged
Changes from 41 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
2a9e7e4
[Discover] Allow to append row leading controls
jughosta 41397f1
[Discover] Hide the remaining actions under menu button
jughosta b1e58b0
[Discover] Restore `externalControlColumns` and `trailingControlColum…
jughosta 8e32755
[Discover] Update comment
jughosta 6e439b2
[Discover] Rename prop
jughosta e430f77
[Discover] Switch to renderControl
jughosta 57baf91
[Discover] Rename
jughosta 1224e71
[Discover] Switched to the new extension
jughosta cce6ea8
[Discover] Refactor logs explorer actions
jughosta 44579d3
[Discover] Move the i popover
jughosta 489ac2c
[Discover] Remove unused
jughosta 2897c35
[Discover] Refactor default control columns
jughosta 69bec46
[Discover] Update logs tests
jughosta 4f86540
[Discover] Update logs tests
jughosta 381c3be
[Discover] Revert to old behaviour by default
jughosta 55a6f3c
[Discover] Update tests
jughosta 17077f6
Merge branch 'main' into 186637-row-actions-extension
jughosta f943679
[Discover] Update screenshot
jughosta a2d91d9
[Discover] Fix types
jughosta 2bd6764
[Discover] Add functional tests for the extension
jughosta 670ad44
[Discover] Add unit tests for new components
jughosta 83045f8
[Discover] Extend tests
jughosta f3dd941
Merge branch 'main' into 186637-row-actions-extension
jughosta c094ac2
[Discover] Normalize control sizes
jughosta 4aee70a
Merge remote-tracking branch 'origin/186637-row-actions-extension' in…
jughosta ca230aa
Merge branch 'main' into 186637-row-actions-extension
jughosta a2a8eae
[CI] Auto-commit changed files from 'yarn openapi:bundle:endpoint-man…
kibanamachine 811e778
Merge branch 'main' into 186637-row-actions-extension
jughosta 622cde7
Merge branch 'main' into 186637-row-actions-extension
jughosta 7d11b73
Revert "[CI] Auto-commit changed files from 'yarn openapi:bundle:endp…
jughosta 589cd69
[CI] Auto-commit changed files from 'yarn openapi:bundle:endpoint-man…
kibanamachine d365425
Merge branch 'main' into 186637-row-actions-extension
jughosta 8669120
Merge branch 'main' into 186637-row-actions-extension
jughosta c350d07
Merge branch 'main' into 186637-row-actions-extension
jughosta 88da0c0
[Discover] Update popover id
jughosta a87dc0a
[Discover] Update popover items
jughosta 08fed40
[Discover] Update the comment
jughosta b79f15d
[Discover] Add click verification
jughosta b1a8db1
Merge branch 'main' into 186637-row-actions-extension
jughosta 2b90431
Merge branch 'main' into 186637-row-actions-extension
jughosta e616e7d
Merge branch 'main' into 186637-row-actions-extension
jughosta 33b74fe
[Discover] Drop size prop
jughosta 4ae9f11
Merge remote-tracking branch 'upstream/main' into 186637-row-actions-…
jughosta b8e8482
Merge branch 'main' into 186637-row-actions-extension
jughosta 17acb8b
Merge branch 'main' into 186637-row-actions-extension
jughosta 154eeac
[Discover] Permanently swap the default row controls
jughosta 4edef40
[Discover] Tmp lower the screenshot test threshold
jughosta b058278
[Discover] Update the screenshot for tests
jughosta c5bb1ef
Merge remote-tracking branch 'upstream/main' into 186637-row-actions-…
jughosta 4849c02
Merge branch 'main' into 186637-row-actions-extension
jughosta 848a1a6
[OneDiscover] Remove Actions popover from grid header
jughosta 78fd61a
[OneDiscover] Clean up translations
jughosta 499ab67
[OneDiscover] Update comment
jughosta e8f6fb8
Merge branch 'main' into 186637-row-actions-extension
jughosta 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 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
51 changes: 51 additions & 0 deletions
51
...custom_control_columns/additional_row_control/get_additional_row_control_columns.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,51 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getAdditionalRowControlColumns } from './get_additional_row_control_columns'; | ||
import { mockRowAdditionalLeadingControls } from '../../../../__mocks__/external_control_columns'; | ||
|
||
describe('getAdditionalRowControlColumns', () => { | ||
it('should work correctly for 0 controls', () => { | ||
const columns = getAdditionalRowControlColumns([]); | ||
|
||
expect(columns).toHaveLength(0); | ||
}); | ||
|
||
it('should work correctly for 1 control', () => { | ||
const columns = getAdditionalRowControlColumns([mockRowAdditionalLeadingControls[0]]); | ||
|
||
expect(columns.map((column) => column.id)).toEqual([ | ||
`additionalRowControl_${mockRowAdditionalLeadingControls[0].id}`, | ||
]); | ||
}); | ||
|
||
it('should work correctly for 2 controls', () => { | ||
const columns = getAdditionalRowControlColumns([ | ||
mockRowAdditionalLeadingControls[0], | ||
mockRowAdditionalLeadingControls[1], | ||
]); | ||
|
||
expect(columns.map((column) => column.id)).toEqual([ | ||
`additionalRowControl_${mockRowAdditionalLeadingControls[0].id}`, | ||
`additionalRowControl_${mockRowAdditionalLeadingControls[1].id}`, | ||
]); | ||
}); | ||
|
||
it('should work correctly for 3 and more controls', () => { | ||
const columns = getAdditionalRowControlColumns([ | ||
mockRowAdditionalLeadingControls[0], | ||
mockRowAdditionalLeadingControls[1], | ||
mockRowAdditionalLeadingControls[2], | ||
]); | ||
|
||
expect(columns.map((column) => column.id)).toEqual([ | ||
`additionalRowControl_${mockRowAdditionalLeadingControls[0].id}`, | ||
`additionalRowControl_menuControl`, | ||
]); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...nents/custom_control_columns/additional_row_control/get_additional_row_control_columns.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,25 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { EuiDataGridControlColumn } from '@elastic/eui'; | ||
import type { RowControlColumn } from '../../../types'; | ||
import { getRowControlColumn } from './row_control_column'; | ||
import { getRowMenuControlColumn } from './row_menu_control_column'; | ||
|
||
export const getAdditionalRowControlColumns = ( | ||
rowControlColumns: RowControlColumn[] | ||
): EuiDataGridControlColumn[] => { | ||
if (rowControlColumns.length <= 2) { | ||
return rowControlColumns.map(getRowControlColumn); | ||
} | ||
|
||
return [ | ||
getRowControlColumn(rowControlColumns[0]), | ||
getRowMenuControlColumn(rowControlColumns.slice(1)), | ||
]; | ||
}; |
9 changes: 9 additions & 0 deletions
9
...-unified-data-table/src/components/custom_control_columns/additional_row_control/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,9 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { getAdditionalRowControlColumns } from './get_additional_row_control_columns'; |
53 changes: 53 additions & 0 deletions
53
.../src/components/custom_control_columns/additional_row_control/row_control_column.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,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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import type { EuiDataGridCellValueElementProps } from '@elastic/eui'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { getRowControlColumn } from './row_control_column'; | ||
import { dataTableContextMock } from '../../../../__mocks__/table_context'; | ||
import { UnifiedDataTableContext } from '../../../table_context'; | ||
|
||
describe('getRowControlColumn', () => { | ||
const contextMock = { | ||
...dataTableContextMock, | ||
}; | ||
|
||
it('should render the component', () => { | ||
const mockClick = jest.fn(); | ||
const props = { | ||
id: 'test_row_control', | ||
headerAriaLabel: 'row control', | ||
renderControl: jest.fn((Control, rowProps) => ( | ||
<Control label={`test-${rowProps.rowIndex}`} iconType="heart" onClick={mockClick} /> | ||
)), | ||
}; | ||
const rowControlColumn = getRowControlColumn(props); | ||
const RowControlColumn = | ||
rowControlColumn.rowCellRender as React.FC<EuiDataGridCellValueElementProps>; | ||
render( | ||
<UnifiedDataTableContext.Provider value={contextMock}> | ||
<RowControlColumn | ||
rowIndex={1} | ||
setCellProps={jest.fn()} | ||
columnId={props.id} | ||
colIndex={0} | ||
isDetails={false} | ||
isExpandable={false} | ||
isExpanded={false} | ||
/> | ||
</UnifiedDataTableContext.Provider> | ||
); | ||
const button = screen.getByTestId('unifiedDataTable_rowControl_test_row_control'); | ||
expect(button).toBeInTheDocument(); | ||
|
||
button.click(); | ||
|
||
expect(mockClick).toHaveBeenCalledWith({ record: contextMock.rows[1], rowIndex: 1 }); | ||
}); | ||
}); |
77 changes: 77 additions & 0 deletions
77
...table/src/components/custom_control_columns/additional_row_control/row_control_column.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,77 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { useMemo } from 'react'; | ||
import { | ||
EuiButtonIcon, | ||
EuiDataGridCellValueElementProps, | ||
EuiDataGridControlColumn, | ||
EuiScreenReaderOnly, | ||
EuiToolTip, | ||
} from '@elastic/eui'; | ||
import { DataTableRowControl, Size } from '../../data_table_row_control'; | ||
import type { RowControlColumn, RowControlProps } from '../../../types'; | ||
import { DEFAULT_CONTROL_COLUMN_WIDTH } from '../../../constants'; | ||
import { useControlColumn } from '../../../hooks/use_control_column'; | ||
|
||
export const RowControlCell = ({ | ||
renderControl, | ||
...props | ||
}: EuiDataGridCellValueElementProps & { | ||
renderControl: RowControlColumn['renderControl']; | ||
}) => { | ||
const rowProps = useControlColumn(props); | ||
|
||
const Control: React.FC<RowControlProps> = useMemo( | ||
() => | ||
({ 'data-test-subj': dataTestSubj, color, disabled, label, iconType, onClick }) => { | ||
return ( | ||
<DataTableRowControl size={Size.normal}> | ||
<EuiToolTip content={label} delay="long"> | ||
<EuiButtonIcon | ||
data-test-subj={dataTestSubj ?? `unifiedDataTable_rowControl_${props.columnId}`} | ||
disabled={disabled} | ||
size="xs" | ||
jughosta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
iconSize="s" | ||
iconType={iconType} | ||
color={color ?? 'text'} | ||
aria-label={label} | ||
onClick={() => { | ||
onClick?.(rowProps); | ||
}} | ||
/> | ||
</EuiToolTip> | ||
</DataTableRowControl> | ||
); | ||
}, | ||
[props.columnId, rowProps] | ||
); | ||
|
||
return renderControl(Control, rowProps); | ||
davismcphee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export const getRowControlColumn = ( | ||
rowControlColumn: RowControlColumn | ||
): EuiDataGridControlColumn => { | ||
const { id, headerAriaLabel, headerCellRender, renderControl } = rowControlColumn; | ||
|
||
return { | ||
id: `additionalRowControl_${id}`, | ||
width: DEFAULT_CONTROL_COLUMN_WIDTH, | ||
headerCellRender: | ||
headerCellRender ?? | ||
(() => ( | ||
<EuiScreenReaderOnly> | ||
<span>{headerAriaLabel}</span> | ||
</EuiScreenReaderOnly> | ||
)), | ||
rowCellRender: (props) => { | ||
return <RowControlCell {...props} renderControl={renderControl} />; | ||
}, | ||
}; | ||
}; |
65 changes: 65 additions & 0 deletions
65
...components/custom_control_columns/additional_row_control/row_menu_control_column.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,65 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import type { EuiDataGridCellValueElementProps } from '@elastic/eui'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { getRowMenuControlColumn } from './row_menu_control_column'; | ||
import { dataTableContextMock } from '../../../../__mocks__/table_context'; | ||
import { mockRowAdditionalLeadingControls } from '../../../../__mocks__/external_control_columns'; | ||
import { UnifiedDataTableContext } from '../../../table_context'; | ||
|
||
describe('getRowMenuControlColumn', () => { | ||
const contextMock = { | ||
...dataTableContextMock, | ||
}; | ||
|
||
it('should render the component', () => { | ||
const mockClick = jest.fn(); | ||
const props = { | ||
id: 'test_row_menu_control', | ||
headerAriaLabel: 'row control', | ||
renderControl: jest.fn((Control, rowProps) => ( | ||
<Control label={`test-${rowProps.rowIndex}`} iconType="heart" onClick={mockClick} /> | ||
)), | ||
}; | ||
const rowMenuControlColumn = getRowMenuControlColumn([ | ||
props, | ||
mockRowAdditionalLeadingControls[0], | ||
mockRowAdditionalLeadingControls[1], | ||
]); | ||
const RowMenuControlColumn = | ||
rowMenuControlColumn.rowCellRender as React.FC<EuiDataGridCellValueElementProps>; | ||
render( | ||
<UnifiedDataTableContext.Provider value={contextMock}> | ||
<RowMenuControlColumn | ||
rowIndex={1} | ||
setCellProps={jest.fn()} | ||
columnId={props.id} | ||
colIndex={0} | ||
isDetails={false} | ||
isExpandable={false} | ||
isExpanded={false} | ||
/> | ||
</UnifiedDataTableContext.Provider> | ||
); | ||
const menuButton = screen.getByTestId('unifiedDataTable_test_row_menu_control'); | ||
expect(menuButton).toBeInTheDocument(); | ||
|
||
menuButton.click(); | ||
|
||
expect(screen.getByTestId('exampleRowControl-visBarVerticalStacked')).toBeInTheDocument(); | ||
expect(screen.getByTestId('exampleRowControl-heart')).toBeInTheDocument(); | ||
|
||
const button = screen.getByTestId('unifiedDataTable_rowMenu_test_row_menu_control'); | ||
expect(button).toBeInTheDocument(); | ||
|
||
button.click(); | ||
expect(mockClick).toHaveBeenCalledWith({ record: contextMock.rows[1], rowIndex: 1 }); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a nit but Do we need a configuration on how many controls are visible? I will add @paulewing to this conversation because security uses 2 controls before shifting others in the popover menu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is according to the provided design. For consistency, I would not introduce a custom configuration for items visible/hidden. We can still increase this number of visible actions as a follow up if becomes necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Thanks for your response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, here is the current design where we have space for 3 controls (including the default expand control):