Skip to content

Commit

Permalink
Clean up shared cell props
Browse files Browse the repository at this point in the history
- Pull out shared/same props into a single obj instead of repeating it 3x & making it less clear which props are different depending on the cell type

- remove getRowHeight fn from being passed down; it's not being used

- pass setRowHeight only to first column as a performance optimization; this will be used for lineCount heights and since lineCount heights are all the same, we really only need to run it once

- clean up footer row cells as well while we're here
  • Loading branch information
cee-chen committed Oct 29, 2021
1 parent aa856e6 commit f4a2923
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 52 deletions.
56 changes: 18 additions & 38 deletions src/components/datagrid/body/data_grid_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export const Cell: FunctionComponent<GridChildComponentProps> = ({
setRowHeight,
schemaDetectors,
rowHeightsOptions,
getRowHeight,
rowHeightUtils,
} = data;

Expand Down Expand Up @@ -119,30 +118,33 @@ export const Cell: FunctionComponent<GridChildComponentProps> = ({
[`euiDataGridRowCell--${textTransform}`]: textTransform,
});

const sharedCellProps = {
rowIndex,
visibleRowIndex,
colIndex: columnIndex,
interactiveCellId,
className: classes,
style: {
...style,
top: `${parseFloat(style.top as string) + headerRowHeight}px`,
},
rowHeightsOptions,
rowHeightUtils,
setRowHeight: isFirstColumn ? setRowHeight : undefined,
};

if (isLeadingControlColumn) {
const leadingColumn = leadingControlColumns[columnIndex];
const { id, rowCellRender } = leadingColumn;

cellContent = (
<EuiDataGridCell
rowIndex={rowIndex}
visibleRowIndex={visibleRowIndex}
colIndex={columnIndex}
{...sharedCellProps}
columnId={id}
popoverContent={DefaultColumnFormatter}
width={leadingColumn.width}
renderCellValue={rowCellRender}
interactiveCellId={interactiveCellId}
isExpandable={false}
className={classes}
setRowHeight={setRowHeight}
getRowHeight={getRowHeight}
rowHeightsOptions={rowHeightsOptions}
rowHeightUtils={rowHeightUtils}
style={{
...style,
top: `${parseFloat(style.top as string) + headerRowHeight}px`,
}}
/>
);
} else if (isTrailingControlColumn) {
Expand All @@ -153,23 +155,12 @@ export const Cell: FunctionComponent<GridChildComponentProps> = ({

cellContent = (
<EuiDataGridCell
rowIndex={rowIndex}
visibleRowIndex={visibleRowIndex}
colIndex={columnIndex}
{...sharedCellProps}
columnId={id}
popoverContent={DefaultColumnFormatter}
width={trailingColumn.width}
renderCellValue={rowCellRender}
interactiveCellId={interactiveCellId}
isExpandable={false}
className={classes}
rowHeightsOptions={rowHeightsOptions}
getRowHeight={getRowHeight}
rowHeightUtils={rowHeightUtils}
style={{
...style,
top: `${parseFloat(style.top as string) + headerRowHeight}px`,
}}
/>
);
} else {
Expand All @@ -188,9 +179,7 @@ export const Cell: FunctionComponent<GridChildComponentProps> = ({

cellContent = (
<EuiDataGridCell
rowIndex={rowIndex}
visibleRowIndex={visibleRowIndex}
colIndex={columnIndex}
{...sharedCellProps}
columnId={columnId}
column={column}
columnType={columnType}
Expand All @@ -199,14 +188,6 @@ export const Cell: FunctionComponent<GridChildComponentProps> = ({
renderCellValue={renderCellValue}
interactiveCellId={interactiveCellId}
isExpandable={isExpandable}
className={classes}
rowHeightsOptions={rowHeightsOptions}
getRowHeight={getRowHeight}
rowHeightUtils={rowHeightUtils}
style={{
...style,
top: `${parseFloat(style.top as string) + headerRowHeight}px`,
}}
/>
);
}
Expand Down Expand Up @@ -700,7 +681,6 @@ export const EuiDataGridBody: FunctionComponent<EuiDataGridBodyProps> = (
itemData={{
schemaDetectors,
setRowHeight,
getRowHeight,
getCorrectRowIndex,
rowMap,
rowOffset: pagination
Expand Down
2 changes: 0 additions & 2 deletions src/components/datagrid/body/data_grid_cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ describe('EuiDataGridCell', () => {

const component = mountEuiDataGridCellWithContext({
rowHeightsOptions: { defaultHeight: 'auto' },
getRowHeight: jest.fn(() => 50),
});

triggerUpdate(component);
Expand All @@ -188,7 +187,6 @@ describe('EuiDataGridCell', () => {

const component = mountEuiDataGridCellWithContext({
rowHeightsOptions: { defaultHeight: 34 },
getRowHeight: jest.fn(() => 50),
});

triggerUpdate(component);
Expand Down
22 changes: 10 additions & 12 deletions src/components/datagrid/body/data_grid_footer_row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ const EuiDataGridFooterRow = memo(
);
const dataTestSubj = classnames('dataGridRow', _dataTestSubj);

const sharedCellProps = {
rowIndex,
visibleRowIndex,
interactiveCellId,
isExpandable: true,
};

return (
<div
ref={ref}
Expand All @@ -50,16 +57,13 @@ const EuiDataGridFooterRow = memo(
>
{leadingControlColumns.map(({ id, width }, i) => (
<EuiDataGridCell
{...sharedCellProps}
key={`${id}-${rowIndex}`}
rowIndex={rowIndex}
visibleRowIndex={visibleRowIndex}
colIndex={i}
columnId={id}
popoverContent={DefaultColumnFormatter}
width={width}
renderCellValue={() => null}
interactiveCellId={interactiveCellId}
isExpandable={true}
className="euiDataGridFooterCell euiDataGridRowCell--controlColumn"
/>
))}
Expand All @@ -74,17 +78,14 @@ const EuiDataGridFooterRow = memo(

return (
<EuiDataGridCell
{...sharedCellProps}
key={`${id}-${rowIndex}`}
rowIndex={rowIndex}
visibleRowIndex={visibleRowIndex}
colIndex={columnPosition}
columnId={id}
columnType={columnType}
popoverContent={popoverContent}
width={width || undefined}
renderCellValue={renderCellValue}
interactiveCellId={interactiveCellId}
isExpandable={true}
className="euiDataGridFooterCell"
/>
);
Expand All @@ -94,16 +95,13 @@ const EuiDataGridFooterRow = memo(

return (
<EuiDataGridCell
{...sharedCellProps}
key={`${id}-${rowIndex}`}
rowIndex={rowIndex}
visibleRowIndex={visibleRowIndex}
colIndex={colIndex}
columnId={id}
popoverContent={DefaultColumnFormatter}
width={width}
renderCellValue={() => null}
interactiveCellId={interactiveCellId}
isExpandable={true}
className="euiDataGridFooterCell euiDataGridRowCell--controlColumn"
/>
);
Expand Down

0 comments on commit f4a2923

Please sign in to comment.