From 981ad1ef7262b06a451345bb6567e9c60e1a684e Mon Sep 17 00:00:00 2001 From: Cee Chen <549407+cee-chen@users.noreply.github.com> Date: Fri, 29 Mar 2024 16:16:02 -0700 Subject: [PATCH] Convert cell styles to Emotion (row cells, header/footer cells, & cell checkboxes) (#7631) Co-authored-by: Jason Stoltzfus --- changelogs/upcoming/7631.md | 3 + changelogs/upcoming/TBD.md | 2 + .../__snapshots__/basic_table.test.tsx.snap | 90 ++++++------- .../in_memory_table.test.tsx.snap | 18 +-- .../basic_table/basic_table.test.tsx | 34 +++++ src/components/basic_table/basic_table.tsx | 24 ++-- .../table/__snapshots__/table.test.tsx.snap | 8 +- .../table_footer_cell.test.tsx.snap | 16 +-- .../table_header_cell.test.tsx.snap | 28 ++-- .../table_header_cell_checkbox.test.tsx.snap | 10 +- .../__snapshots__/table_row.test.tsx.snap | 4 +- .../table_row_cell.test.tsx.snap | 36 ++--- .../table_row_cell_checkbox.test.tsx.snap | 2 +- src/components/table/_index.scss | 1 - src/components/table/_mixins.scss | 13 -- src/components/table/_responsive.scss | 51 ------- src/components/table/_table.scss | 76 +---------- src/components/table/table.styles.ts | 3 + .../table/table_cells_shared.styles.ts | 84 ++++++++++++ src/components/table/table_footer_cell.tsx | 14 +- src/components/table/table_header_cell.tsx | 25 ++-- .../table/table_header_cell_checkbox.tsx | 14 +- src/components/table/table_row.styles.ts | 39 +----- src/components/table/table_row.tsx | 2 - src/components/table/table_row_cell.styles.ts | 124 ++++++++++++++++++ src/components/table/table_row_cell.tsx | 28 +++- .../table/table_row_cell_checkbox.tsx | 15 ++- 27 files changed, 445 insertions(+), 319 deletions(-) create mode 100644 changelogs/upcoming/7631.md delete mode 100644 src/components/table/_mixins.scss create mode 100644 src/components/table/table_cells_shared.styles.ts create mode 100644 src/components/table/table_row_cell.styles.ts diff --git a/changelogs/upcoming/7631.md b/changelogs/upcoming/7631.md new file mode 100644 index 00000000000..f2647c0b2d3 --- /dev/null +++ b/changelogs/upcoming/7631.md @@ -0,0 +1,3 @@ +**DOM changes** + +- `EuiTableRowCell` now applies passed `className`s to the parent `` element, instead of to the inner cell content `
`. diff --git a/changelogs/upcoming/TBD.md b/changelogs/upcoming/TBD.md index 14e262d98d2..4cf75777eba 100644 --- a/changelogs/upcoming/TBD.md +++ b/changelogs/upcoming/TBD.md @@ -9,3 +9,5 @@ - `$euiTableFocusClickableColor` - Removed the following `EuiTable` Sass mixins: - `euiTableActionsBackgroundMobile` + - `euiTableCellCheckbox` + - `euiTableCell` diff --git a/src/components/basic_table/__snapshots__/basic_table.test.tsx.snap b/src/components/basic_table/__snapshots__/basic_table.test.tsx.snap index f7c7e222ae1..1a0bfd7b09a 100644 --- a/src/components/basic_table/__snapshots__/basic_table.test.tsx.snap +++ b/src/components/basic_table/__snapshots__/basic_table.test.tsx.snap @@ -17,7 +17,7 @@ exports[`EuiBasicTable renders (bare-bones) 1`] = `
Name
@@ -69,10 +69,10 @@ exports[`EuiBasicTable renders (bare-bones) 1`] = ` class="euiTableRow emotion-euiTableRow-desktop" >
Name
@@ -91,10 +91,10 @@ exports[`EuiBasicTable renders (bare-bones) 1`] = ` class="euiTableRow emotion-euiTableRow-desktop" >
Name
@@ -129,7 +129,7 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
@@ -254,7 +254,7 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin class="euiTableRow euiTableRow-isSelectable euiTableRow-hasActions emotion-euiTableRow-desktop" >
Name
@@ -291,10 +291,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
ID
@@ -309,10 +309,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
Age
@@ -327,10 +327,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
Name
@@ -412,10 +412,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
ID
@@ -430,10 +430,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
Age
@@ -448,10 +448,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
Name
@@ -533,10 +533,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
ID
@@ -551,10 +551,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
Age
@@ -569,10 +569,10 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
Name
@@ -310,10 +310,10 @@ exports[`EuiInMemoryTable with items 1`] = ` class="euiTableRow emotion-euiTableRow-desktop" >
Name
@@ -332,10 +332,10 @@ exports[`EuiInMemoryTable with items 1`] = ` class="euiTableRow emotion-euiTableRow-desktop" >
Name
diff --git a/src/components/basic_table/basic_table.test.tsx b/src/components/basic_table/basic_table.test.tsx index bf9513474ff..6239fdf69f1 100644 --- a/src/components/basic_table/basic_table.test.tsx +++ b/src/components/basic_table/basic_table.test.tsx @@ -692,6 +692,40 @@ describe('EuiBasicTable', () => { ); }); + test('custom item actions', () => { + const props: EuiBasicTableProps = { + items: basicItems, + columns: [ + ...basicColumns, + { + name: 'Actions', + actions: [ + { + render: ({ id }) => ( + + ), + available: ({ id }) => id !== '3', + }, + ], + }, + ], + responsiveBreakpoint: true, // Needs to be in mobile to render customAction cell CSS + }; + const { queryByTestSubject, container } = render( + + ); + + expect(queryByTestSubject('customAction-1')).toBeInTheDocument(); + expect(queryByTestSubject('customAction-2')).toBeInTheDocument(); + expect(queryByTestSubject('customAction-3')).not.toBeInTheDocument(); + + expect( + container.querySelector('.euiTableRowCell--hasActions')!.className + ).toContain('-customActions'); + }); + describe('are disabled on selection', () => { test('single action', () => { const props: EuiBasicTableProps = { diff --git a/src/components/basic_table/basic_table.tsx b/src/components/basic_table/basic_table.tsx index f3aeec4c963..d91076abe44 100644 --- a/src/components/basic_table/basic_table.tsx +++ b/src/components/basic_table/basic_table.tsx @@ -61,7 +61,7 @@ import { EuiI18n } from '../i18n'; import { EuiDelayRender } from '../delay_render'; import { htmlIdGenerator } from '../../services/accessibility'; -import { Action } from './action_types'; +import { Action, CustomItemAction } from './action_types'; import { EuiTableActionsColumnType, EuiTableComputedColumnType, @@ -1147,6 +1147,10 @@ export class EuiBasicTable extends Component< // Disable all actions if any row(s) are selected const allDisabled = this.state.selection.length > 0; + const hasCustomActions = column.actions.some( + (action: Action) => !!(action as CustomItemAction).render + ); + let actualActions = column.actions.filter( (action: Action) => !action.available || action.available(item) ); @@ -1181,15 +1185,6 @@ export class EuiBasicTable extends Component< }); } - const tools = ( - - ); - const key = `record_actions_${itemId}_${columnIndex}`; return ( extends Component< key={key} align="right" textOnly={false} - hasActions={true} + hasActions={hasCustomActions ? 'custom' : true} css={euiBasicTableActionsWrapper} > - {tools} + ); } diff --git a/src/components/table/__snapshots__/table.test.tsx.snap b/src/components/table/__snapshots__/table.test.tsx.snap index 8fa9470b448..a62b8b6a99a 100644 --- a/src/components/table/__snapshots__/table.test.tsx.snap +++ b/src/components/table/__snapshots__/table.test.tsx.snap @@ -10,7 +10,7 @@ exports[`EuiTable renders 1`] = ` @@ -26,7 +26,7 @@ exports[`EuiTable renders 1`] = ` @@ -48,7 +48,7 @@ exports[`EuiTable renders 1`] = ` class="euiTableRow emotion-euiTableRow-desktop" >
@@ -120,7 +120,7 @@ exports[`sorting does not render a button with readOnly 1`] = ` @@ -151,7 +151,7 @@ exports[`sorting is rendered with isSortAscending 1`] = ` @@ -182,7 +182,7 @@ exports[`sorting is rendered with isSorted 1`] = ` @@ -213,12 +213,12 @@ exports[`sorting renders a button with onSort 1`] = `