From 905766398481b2caf69e0c83310836c6abbf9e04 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Wed, 4 Oct 2023 14:42:54 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20DRY=20out=20`cellHeightsType`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pass var(s) instead of re-getting it twice --- .../datagrid/body/data_grid_cell.tsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/datagrid/body/data_grid_cell.tsx b/src/components/datagrid/body/data_grid_cell.tsx index 1327a1fe15a..c90131e90f5 100644 --- a/src/components/datagrid/body/data_grid_cell.tsx +++ b/src/components/datagrid/body/data_grid_cell.tsx @@ -35,6 +35,7 @@ import { EuiDataGridCellValueElementProps, EuiDataGridCellValueProps, EuiDataGridCellPopoverElementProps, + EuiDataGridRowHeightOption, } from '../data_grid_types'; import { EuiDataGridCellActions, @@ -51,31 +52,28 @@ const EuiDataGridCellContent: FunctionComponent< isControlColumn: boolean; isFocused: boolean; ariaRowIndex: number; + rowHeight?: EuiDataGridRowHeightOption; + cellHeightType: string; } > = memo( ({ renderCellValue, column, setCellContentsRef, - rowHeightsOptions, rowIndex, colIndex, ariaRowIndex, + rowHeight, rowHeightUtils, isControlColumn, isFocused, + cellHeightType, ...rest }) => { // React is more permissible than the TS types indicate const CellElement = renderCellValue as JSXElementConstructor; - const rowHeightOption = rowHeightUtils?.getRowHeightOption( - rowIndex, - rowHeightsOptions - ); - const cellHeightType = rowHeightUtils?.getHeightType(rowHeightOption); - const classes = classNames( `euiDataGridRowCell__${cellHeightType}Height`, !isControlColumn && { @@ -101,7 +99,7 @@ const EuiDataGridCellContent: FunctionComponent< ); if (cellHeightType === 'lineCount' && !isControlColumn) { - const lines = rowHeightUtils!.getLineCount(rowHeightOption)!; + const lines = rowHeightUtils!.getLineCount(rowHeight)!; cellContent = ( {cellContent} @@ -678,24 +676,25 @@ export class EuiDataGridCell extends Component< rowHeightsOptions ); - const rowHeightOption = rowHeightUtils?.getRowHeightOption( + const rowHeight = rowHeightUtils?.getRowHeightOption( rowIndex, rowHeightsOptions ); const cellHeightType = - rowHeightUtils?.getHeightType(rowHeightOption) || 'default'; + rowHeightUtils?.getHeightType(rowHeight) || 'default'; const cellContentProps = { ...rest, setCellProps: this.setCellProps, column, columnType, + cellHeightType, isExpandable, isExpanded: popoverIsOpen, isDetails: false, isFocused: this.state.isFocused, setCellContentsRef: this.setCellContentsRef, - rowHeightsOptions, + rowHeight, rowHeightUtils, isControlColumn: cellClasses.includes( 'euiDataGridRowCell--controlColumn'