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

[OneDiscover][Extension] DataTable Row Actions #188762

Merged
merged 54 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
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 Jul 19, 2024
41397f1
[Discover] Hide the remaining actions under menu button
jughosta Jul 19, 2024
b1e58b0
[Discover] Restore `externalControlColumns` and `trailingControlColum…
jughosta Jul 23, 2024
8e32755
[Discover] Update comment
jughosta Jul 23, 2024
6e439b2
[Discover] Rename prop
jughosta Jul 23, 2024
e430f77
[Discover] Switch to renderControl
jughosta Jul 24, 2024
57baf91
[Discover] Rename
jughosta Jul 24, 2024
1224e71
[Discover] Switched to the new extension
jughosta Jul 24, 2024
cce6ea8
[Discover] Refactor logs explorer actions
jughosta Jul 24, 2024
44579d3
[Discover] Move the i popover
jughosta Jul 24, 2024
489ac2c
[Discover] Remove unused
jughosta Jul 25, 2024
2897c35
[Discover] Refactor default control columns
jughosta Jul 25, 2024
69bec46
[Discover] Update logs tests
jughosta Jul 25, 2024
4f86540
[Discover] Update logs tests
jughosta Jul 25, 2024
381c3be
[Discover] Revert to old behaviour by default
jughosta Jul 25, 2024
55a6f3c
[Discover] Update tests
jughosta Jul 25, 2024
17077f6
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 25, 2024
f943679
[Discover] Update screenshot
jughosta Jul 25, 2024
a2d91d9
[Discover] Fix types
jughosta Jul 25, 2024
2bd6764
[Discover] Add functional tests for the extension
jughosta Jul 25, 2024
670ad44
[Discover] Add unit tests for new components
jughosta Jul 26, 2024
83045f8
[Discover] Extend tests
jughosta Jul 26, 2024
f3dd941
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 26, 2024
c094ac2
[Discover] Normalize control sizes
jughosta Jul 26, 2024
4aee70a
Merge remote-tracking branch 'origin/186637-row-actions-extension' in…
jughosta Jul 26, 2024
ca230aa
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 26, 2024
a2a8eae
[CI] Auto-commit changed files from 'yarn openapi:bundle:endpoint-man…
kibanamachine Jul 26, 2024
811e778
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 26, 2024
622cde7
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 26, 2024
7d11b73
Revert "[CI] Auto-commit changed files from 'yarn openapi:bundle:endp…
jughosta Jul 26, 2024
589cd69
[CI] Auto-commit changed files from 'yarn openapi:bundle:endpoint-man…
kibanamachine Jul 26, 2024
d365425
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 27, 2024
8669120
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 29, 2024
c350d07
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 30, 2024
88da0c0
[Discover] Update popover id
jughosta Jul 30, 2024
a87dc0a
[Discover] Update popover items
jughosta Jul 30, 2024
08fed40
[Discover] Update the comment
jughosta Jul 30, 2024
b79f15d
[Discover] Add click verification
jughosta Jul 30, 2024
b1a8db1
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 30, 2024
2b90431
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 30, 2024
e616e7d
Merge branch 'main' into 186637-row-actions-extension
jughosta Jul 30, 2024
33b74fe
[Discover] Drop size prop
jughosta Jul 30, 2024
4ae9f11
Merge remote-tracking branch 'upstream/main' into 186637-row-actions-…
jughosta Jul 31, 2024
b8e8482
Merge branch 'main' into 186637-row-actions-extension
jughosta Aug 1, 2024
17acb8b
Merge branch 'main' into 186637-row-actions-extension
jughosta Aug 1, 2024
154eeac
[Discover] Permanently swap the default row controls
jughosta Aug 1, 2024
4edef40
[Discover] Tmp lower the screenshot test threshold
jughosta Aug 1, 2024
b058278
[Discover] Update the screenshot for tests
jughosta Aug 1, 2024
c5bb1ef
Merge remote-tracking branch 'upstream/main' into 186637-row-actions-…
jughosta Aug 5, 2024
4849c02
Merge branch 'main' into 186637-row-actions-extension
jughosta Aug 6, 2024
848a1a6
[OneDiscover] Remove Actions popover from grid header
jughosta Aug 6, 2024
78fd61a
[OneDiscover] Clean up translations
jughosta Aug 6, 2024
499ab67
[OneDiscover] Update comment
jughosta Aug 6, 2024
e8f6fb8
Merge branch 'main' into 186637-row-actions-extension
jughosta Aug 7, 2024
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
5 changes: 1 addition & 4 deletions packages/kbn-unified-data-table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ Props description:
| **configRowHeight** | (optional)number | Optional value for providing configuration setting for UnifiedDataTable rows height. |
| **showMultiFields** | (optional)boolean | Optional value for providing configuration setting for enabling to display the complex fields in the table. Default is true. |
| **maxDocFieldsDisplayed** | (optional)number | Optional value for providing configuration setting for maximum number of document fields to display in the table. Default is 50. |
| **externalControlColumns** | (optional)EuiDataGridControlColumn[] | Optional value for providing EuiDataGridControlColumn list of the additional leading control columns. UnifiedDataTable includes two control columns: Open Details and Select. |
| **rowAdditionalLeadingControls** | (optional)RowControlColumn[] | Optional value for providing an list of the additional leading control columns. UnifiedDataTable includes two control columns: Open Details and Select. |
| **totalHits** | (optional)number | Number total hits from ES. |
| **onFetchMoreRecords** | (optional)() => void | To fetch more. |
| **externalAdditionalControls** | (optional)React.ReactNode | Optional value for providing the additional controls available in the UnifiedDataTable toolbar to manage it's records or state. UnifiedDataTable includes Columns, Sorting and Bulk Actions. |
| **rowsPerPageOptions** | (optional)number[] | Optional list of number type values to set custom UnifiedDataTable paging options to display the records per page. |
| **renderCustomGridBody** | (optional)(args: EuiDataGridCustomBodyProps) => React.ReactNode; | An optional function called to completely customize and control the rendering of EuiDataGrid's body and cell placement. |
| **trailingControlColumns** | (optional)EuiDataGridControlColumn[] | An optional list of the EuiDataGridControlColumn type for setting trailing control columns standard for EuiDataGrid. |
| **visibleCellActions** | (optional)number | An optional value for a custom number of the visible cell actions in the table. By default is up to 3. |
| **externalCustomRenderers** | (optional)Record<string,(props: EuiDataGridCellValueElementProps) => React.ReactNode>; | An optional settings for a specified fields rendering like links. Applied only for the listed fields rendering. |
| **consumer** | (optional)string | Name of the UnifiedDataTable consumer component or application. |
Expand Down Expand Up @@ -141,9 +140,7 @@ Usage example:
[browserFields, handleOnPanelClosed, runtimeMappings, timelineId]
);
}
externalControlColumns={leadingControlColumns}
externalAdditionalControls={additionalControls}
trailingControlColumns={trailingControlColumns}
renderCustomGridBody={renderCustomGridBody}
rowsPerPageOptions={[10, 30, 40, 100]}
showFullScreenButton={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EuiSpacer,
EuiDataGridControlColumn,
} from '@elastic/eui';
import type { RowControlColumn } from '../src/types';

const SelectionHeaderCell = () => {
return (
Expand Down Expand Up @@ -116,3 +117,22 @@ export const testLeadingControlColumn: EuiDataGridControlColumn = {
rowCellRender: SelectionRowCell,
width: 100,
};

export const mockRowAdditionalLeadingControls = ['visBarVerticalStacked', 'heart', 'inspect'].map(
(iconType, index): RowControlColumn => ({
id: `exampleControl_${iconType}`,
headerAriaLabel: `Example Row Control ${iconType}`,
renderControl: (Control, rowProps) => {
return (
<Control
data-test-subj={`exampleRowControl-${iconType}`}
label={`Example ${iconType}`}
iconType={iconType}
onClick={() => {
alert(`Example "${iconType}" control clicked. Row index: ${rowProps.rowIndex}`);
}}
/>
);
},
})
);
2 changes: 1 addition & 1 deletion packages/kbn-unified-data-table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export { getRowsPerPageOptions } from './src/utils/rows_per_page';
export { popularizeField } from './src/utils/popularize_field';

export { useColumns } from './src/hooks/use_data_grid_columns';
export { OPEN_DETAILS, SELECT_ROW } from './src/components/data_table_columns';
export { OPEN_DETAILS, SELECT_ROW } from './src/components/data_table_columns'; // TODO: deprecate?
export { DataTableRowControl } from './src/components/data_table_row_control';

export type {
Expand Down
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`,
]);
});
});
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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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):

Screenshot 2024-08-07 at 14 26 19 Screenshot 2024-08-07 at 14 26 45

return rowControlColumns.map(getRowControlColumn);
}

return [
getRowControlColumn(rowControlColumns[0]),
getRowMenuControlColumn(rowControlColumns.slice(1)),
];
};
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';
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 });
});
});
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} />;
},
};
};
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 });
});
});
Loading