Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiDataGrid] Various row height fixes #8025

Merged
merged 11 commits into from
Sep 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('EuiDataGridCell', () => {
),
popoverContext: mockPopoverContext,
rowHeightUtils: mockRowHeightUtils,
gridStyles: {},
};

beforeEach(() => jest.clearAllMocks());
Expand Down Expand Up @@ -202,6 +203,12 @@ describe('EuiDataGridCell', () => {
it('rowHeightsOptions', () => {
component.setProps({ rowHeightsOptions: { defaultHeight: 'auto' } });
});
it('gridStyles.fontSize', () => {
component.setProps({ gridStyles: { fontSize: 's' } });
});
it('gridStyles.cellPadding', () => {
component.setProps({ gridStyles: { cellPadding: 'l' } });
});
it('renderCellValue', () => {
component.setProps({ renderCellValue: () => <div>test</div> });
});
Expand Down Expand Up @@ -254,7 +261,10 @@ describe('EuiDataGridCell', () => {
});

it('should not update for prop/state changes not specified above', () => {
component.setProps({ className: 'test' });
component.setProps({
className: 'test',
gridStyles: { header: 'underline' },
});
expect(shouldComponentUpdate).toHaveReturnedWith(false);
});
});
Expand Down Expand Up @@ -653,19 +663,41 @@ describe('EuiDataGridCell', () => {
});
});

it('recalculates when rowHeightsOptions.defaultHeight.lineCount changes', () => {
it('recalculates when props that affect row/line height change', () => {
const component = mount(
<EuiDataGridCell
{...requiredProps}
rowHeightsOptions={{ defaultHeight: { lineCount: 7 } }}
rowHeightsOptions={{ defaultHeight: { lineCount: 4 } }}
setRowHeight={setRowHeight}
/>
);
component.setProps({
rowHeightsOptions: { defaultHeight: { lineCount: 2 } },
});
expect(setRowHeight).toHaveBeenCalledTimes(1);

// Other props that can affect row heights

const rowHeightsOptionsWithLineHeight = {
defaultHeight: { lineCount: 2 },
lineHeight: '3',
};
component.setProps({
rowHeightsOptions: { defaultHeight: { lineCount: 6 } },
rowHeightsOptions: rowHeightsOptionsWithLineHeight,
});
expect(setRowHeight).toHaveBeenCalled();
expect(setRowHeight).toHaveBeenCalledTimes(2);

component.setProps({
rowHeightsOptions: rowHeightsOptionsWithLineHeight,
gridStyles: { cellPadding: 'l' },
});
expect(setRowHeight).toHaveBeenCalledTimes(3);

component.setProps({
rowHeightsOptions: rowHeightsOptionsWithLineHeight,
gridStyles: { cellPadding: 'l', fontSize: 'l' },
});
expect(setRowHeight).toHaveBeenCalledTimes(4);
});

it('calculates undefined heights as single rows with a lineCount of 1', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ export class EuiDataGridCell extends Component<

if (
this.props.rowHeightsOptions?.defaultHeight !==
prevProps.rowHeightsOptions?.defaultHeight
prevProps.rowHeightsOptions?.defaultHeight ||
this.props.rowHeightsOptions?.lineHeight !==
prevProps.rowHeightsOptions?.lineHeight ||
this.props.gridStyles?.fontSize !== prevProps.gridStyles?.fontSize ||
this.props.gridStyles?.cellPadding !== prevProps.gridStyles?.cellPadding
) {
this.recalculateLineHeight();
}
Expand Down Expand Up @@ -338,6 +342,12 @@ export class EuiDataGridCell extends Component<
if (nextProps.width !== this.props.width) return true;
if (nextProps.rowHeightsOptions !== this.props.rowHeightsOptions)
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
return true;
if (nextProps.gridStyles?.fontSize !== this.props.gridStyles?.fontSize)
return true;
if (
nextProps.gridStyles?.cellPadding !== this.props.gridStyles?.cellPadding
)
return true;
if (nextProps.renderCellValue !== this.props.renderCellValue) return true;
if (nextProps.renderCellPopover !== this.props.renderCellPopover)
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Cell', () => {
renderCellValue: () => null,
interactiveCellId: '',
rowHeightUtils: new RowHeightUtils(),
gridStyles: {},
schema: {},
schemaDetectors,
columns: [{ id: 'C' }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type CellProps = Pick<
| 'cellContext'
| 'renderCellPopover'
| 'interactiveCellId'
| 'gridStyles'
| 'rowHeightsOptions'
| 'rowHeightUtils'
| 'rowManager'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const EuiDataGridBodyCustomRender: FunctionComponent<
setRowHeight,
rowHeightsOptions,
rowHeightUtils,
gridStyles,
};
}, [
schema,
Expand All @@ -161,6 +162,7 @@ export const EuiDataGridBodyCustomRender: FunctionComponent<
setRowHeight,
rowHeightsOptions,
rowHeightUtils,
gridStyles,
]);

const Cell = useCallback<EuiDataGridCustomBodyProps['Cell']>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export const EuiDataGridBodyVirtualized: FunctionComponent<EuiDataGridBodyProps>
rowManager,
pagination,
headerRowHeight,
gridStyles,
};
}, [
schemaDetectors,
Expand All @@ -357,6 +358,7 @@ export const EuiDataGridBodyVirtualized: FunctionComponent<EuiDataGridBodyProps>
rowManager,
pagination,
headerRowHeight,
gridStyles,
]);

const rowWrapperContextValue = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const EuiDataGridFooterRow = memo(
visibleRowIndex,
interactiveCellId,
popoverContext,
gridStyles,
};

return (
Expand Down
1 change: 1 addition & 0 deletions packages/eui/src/components/datagrid/data_grid_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ export interface EuiDataGridCellProps {
rowHeightUtils?: RowHeightUtilsType;
rowManager?: EuiDataGridRowManager;
pagination?: Required<EuiDataGridPaginationProps>;
gridStyles: EuiDataGridStyle;
}

export interface EuiDataGridCellState {
Expand Down