From 41dec7866297dd7776439fbd2f8902bedb882098 Mon Sep 17 00:00:00 2001
From: Cee Chen
Date: Tue, 16 Jan 2024 19:23:22 -0800
Subject: [PATCH 1/5] [perf] Reduce EuiDataGridCell rerenders
- memoize all fns to class methods
- do not define jsx as const, this causes react to redefine a new component each rerender
---
.../datagrid/body/cell/data_grid_cell.tsx | 118 ++++++++++--------
1 file changed, 63 insertions(+), 55 deletions(-)
diff --git a/src/components/datagrid/body/cell/data_grid_cell.tsx b/src/components/datagrid/body/cell/data_grid_cell.tsx
index af9041848df..1cc80e45a04 100644
--- a/src/components/datagrid/body/cell/data_grid_cell.tsx
+++ b/src/components/datagrid/body/cell/data_grid_cell.tsx
@@ -501,10 +501,43 @@ export class EuiDataGridCell extends Component<
}
};
+ handleCellKeyDown = (event: KeyboardEvent) => {
+ if (this.isExpandable()) {
+ if (this.isPopoverOpen()) return;
+ const {
+ popoverContext: { openCellPopover },
+ visibleRowIndex,
+ colIndex,
+ } = this.props;
+
+ switch (event.key) {
+ case keys.ENTER:
+ case keys.F2:
+ event.preventDefault();
+ openCellPopover({ rowIndex: visibleRowIndex, colIndex });
+ break;
+ }
+ }
+ };
+
+ handleCellExpansionClick = () => {
+ const {
+ popoverContext: { openCellPopover, closeCellPopover },
+ visibleRowIndex,
+ colIndex,
+ } = this.props;
+
+ if (this.isPopoverOpen()) {
+ closeCellPopover();
+ } else {
+ openCellPopover({ rowIndex: visibleRowIndex, colIndex });
+ }
+ };
+
render() {
const {
width,
- popoverContext: { closeCellPopover, openCellPopover },
+ popoverContext,
interactiveCellId,
columnType,
className,
@@ -557,21 +590,6 @@ export class EuiDataGridCell extends Component<
...cellPropsStyle, // apply anything from setCellProps({ style })
};
- const handleCellKeyDown = (event: KeyboardEvent) => {
- if (isExpandable) {
- if (popoverIsOpen) {
- return;
- }
- switch (event.key) {
- case keys.ENTER:
- case keys.F2:
- event.preventDefault();
- openCellPopover({ rowIndex: visibleRowIndex, colIndex });
- break;
- }
- }
- };
-
const rowHeight = rowHeightUtils?.getRowHeightOption(
rowIndex,
rowHeightsOptions
@@ -595,43 +613,6 @@ export class EuiDataGridCell extends Component<
ariaRowIndex,
};
- const cellActions = isExpandable ? (
- <>
- {
- if (popoverIsOpen) {
- closeCellPopover();
- } else {
- openCellPopover({ rowIndex: visibleRowIndex, colIndex });
- }
- }}
- />
- {/* Give the cell expansion popover a separate div/ref - otherwise the
- extra popover wrappers mess up the absolute positioning and cause
- animation stuttering */}
-
- >
- ) : undefined;
-
- const cellContent = (
-
-
-
- );
-
const cell = (
- {cellContent}
+
+
+
+ {/* Give the cell expansion popover a separate div/ref - otherwise the
+ extra popover wrappers mess up the absolute positioning and cause
+ animation stuttering */}
+
+ >
+ )
+ }
+ />
+
-
B, column 2, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 1, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 2, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 1, row 3
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 2, row 3
- .
- Press the Enter key to expand this cell.
-
-
-
-
@@ -1360,31 +1216,7 @@ exports[`EuiDataGrid rendering renders control columns 1`] = `
>
-
A, column 2, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 3, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 2, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 3, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 2, row 3
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 3, row 3
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 1, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 2, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 1, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 2, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 1, row 3
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 2, row 3
- .
- Press the Enter key to expand this cell.
-
-
-
-
@@ -2628,31 +2196,7 @@ exports[`EuiDataGrid rendering renders with common and div attributes 1`] = `
>
-
A, column 1, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 2, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 1, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 2, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
A, column 1, row 3
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
B, column 2, row 3
- .
- Press the Enter key to expand this cell.
-
-
-
-
diff --git a/src/components/datagrid/body/__snapshots__/data_grid_body_custom.test.tsx.snap b/src/components/datagrid/body/__snapshots__/data_grid_body_custom.test.tsx.snap
index 73d35ea0a01..f5c3ea2d80a 100644
--- a/src/components/datagrid/body/__snapshots__/data_grid_body_custom.test.tsx.snap
+++ b/src/components/datagrid/body/__snapshots__/data_grid_body_custom.test.tsx.snap
@@ -143,31 +143,7 @@ exports[`EuiDataGridBodyCustomRender treats \`renderCustomGridBody\` as a render
>
-
columnA, column 1, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
columnB, column 2, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
columnA, column 1, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
columnB, column 2, row 2
- .
- Press the Enter key to expand this cell.
-
-
-
-
diff --git a/src/components/datagrid/body/__snapshots__/data_grid_body_virtualized.test.tsx.snap b/src/components/datagrid/body/__snapshots__/data_grid_body_virtualized.test.tsx.snap
index 776c1e879b4..3a2f6df3422 100644
--- a/src/components/datagrid/body/__snapshots__/data_grid_body_virtualized.test.tsx.snap
+++ b/src/components/datagrid/body/__snapshots__/data_grid_body_virtualized.test.tsx.snap
@@ -146,31 +146,7 @@ exports[`EuiDataGridBodyVirtualized renders 1`] = `
>
-
columnA, column 1, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
-
columnB, column 2, row 1
- .
- Press the Enter key to expand this cell.
-
-
-
-
diff --git a/src/components/datagrid/body/cell/__snapshots__/data_grid_cell.test.tsx.snap b/src/components/datagrid/body/cell/__snapshots__/data_grid_cell.test.tsx.snap
index 075243d94b9..b21135c6442 100644
--- a/src/components/datagrid/body/cell/__snapshots__/data_grid_cell.test.tsx.snap
+++ b/src/components/datagrid/body/cell/__snapshots__/data_grid_cell.test.tsx.snap
@@ -71,30 +71,6 @@ exports[`EuiDataGridCell renders 1`] = `
>
-
someColumn, column 1, row 1
- .
- Press the Enter key to expand this cell.
-