Skip to content

Commit

Permalink
🔥 DRY out cellHeightsType
Browse files Browse the repository at this point in the history
- pass var(s) instead of re-getting it twice
  • Loading branch information
cee-chen committed Oct 4, 2023
1 parent ad6894b commit 9057663
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/components/datagrid/body/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
EuiDataGridCellValueElementProps,
EuiDataGridCellValueProps,
EuiDataGridCellPopoverElementProps,
EuiDataGridRowHeightOption,
} from '../data_grid_types';
import {
EuiDataGridCellActions,
Expand All @@ -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<EuiDataGridCellValueElementProps>;

const rowHeightOption = rowHeightUtils?.getRowHeightOption(
rowIndex,
rowHeightsOptions
);
const cellHeightType = rowHeightUtils?.getHeightType(rowHeightOption);

const classes = classNames(
`euiDataGridRowCell__${cellHeightType}Height`,
!isControlColumn && {
Expand All @@ -101,7 +99,7 @@ const EuiDataGridCellContent: FunctionComponent<
</div>
);
if (cellHeightType === 'lineCount' && !isControlColumn) {
const lines = rowHeightUtils!.getLineCount(rowHeightOption)!;
const lines = rowHeightUtils!.getLineCount(rowHeight)!;
cellContent = (
<EuiTextBlockTruncate lines={lines} cloneElement>
{cellContent}
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 9057663

Please sign in to comment.