Skip to content

Commit

Permalink
Rename computeStylesForGridCell now that it's no longer computing sty…
Browse files Browse the repository at this point in the history
…les & remove getComputedCellStyles

- re: getComputedCellStyles - I'm not seeing this affect either numeric, lineCount, or auto heights when changing grid density, hence me removing this
  • Loading branch information
cee-chen committed Oct 29, 2021
1 parent 326e4e4 commit 51a3d2d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/components/datagrid/__mocks__/row_height_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EuiDataGridRowHeightOption } from '../data_grid_types';
import { RowHeightUtils } from '../row_height_utils';

export const mockRowHeightUtils = ({
computeStylesForGridCell: jest.fn(),
cacheStyles: jest.fn(),
setGrid: jest.fn(),
getStylesForCell: jest.fn(() => ({
wordWrap: 'break-word',
Expand All @@ -23,7 +23,6 @@ export const mockRowHeightUtils = ({
pruneHiddenColumnHeights: jest.fn(),
getRowHeight: jest.fn(() => 32),
getRowHeightOption: jest.fn(),
getComputedCellStyles: jest.fn(() => {}),
getCalculatedHeight: jest.fn(
(heightOption: EuiDataGridRowHeightOption, defaultHeight: number) => {
if (typeof heightOption === 'object') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ exports[`EuiDataGridCell renders 1`] = `
renderCellValue={[Function]}
rowHeightUtils={
Object {
"computeStylesForGridCell": [MockFunction],
"cacheStyles": [MockFunction],
"getCalculatedHeight": [MockFunction],
"getComputedCellStyles": [MockFunction],
"getRowHeight": [MockFunction],
"getRowHeightOption": [MockFunction] {
"calls": Array [
Expand Down Expand Up @@ -70,9 +69,8 @@ exports[`EuiDataGridCell renders 1`] = `
renderCellValue={[Function]}
rowHeightUtils={
Object {
"computeStylesForGridCell": [MockFunction],
"cacheStyles": [MockFunction],
"getCalculatedHeight": [MockFunction],
"getComputedCellStyles": [MockFunction],
"getRowHeight": [MockFunction],
"getRowHeightOption": [MockFunction] {
"calls": Array [
Expand Down
9 changes: 1 addition & 8 deletions src/components/datagrid/body/data_grid_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,21 +506,14 @@ export const EuiDataGridBody: FunctionComponent<EuiDataGridBodyProps> = (

const [minRowHeight, setRowHeight] = useState(DEFAULT_ROW_HEIGHT);

const computedCellStyles = rowHeightUtils.getComputedCellStyles();

const defaultHeight = useMemo(() => {
// @ts-ignore we need to re-run this when computedCellStyles changes,
// but it isn't used directly; so let's make the hooks lint rule see
// that it is used, but we need to tell eslint to ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _computedCellStyles = computedCellStyles;
return rowHeightsOptions?.defaultHeight
? rowHeightUtils.getCalculatedHeight(
rowHeightsOptions.defaultHeight,
minRowHeight
)
: minRowHeight;
}, [rowHeightsOptions, minRowHeight, rowHeightUtils, computedCellStyles]);
}, [rowHeightsOptions, minRowHeight, rowHeightUtils]);

const getRowHeight = useCallback(
(rowIndex) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/datagrid/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ export const EuiDataGrid: FunctionComponent<EuiDataGridProps> = (props) => {
}, [focusedCell, contentRef]);

useEffect(() => {
rowHeightUtils.computeStylesForGridCell({
rowHeightUtils.cacheStyles({
cellPadding: gridStyles.cellPadding,
});
}, [gridStyles.cellPadding, rowHeightUtils]);
Expand Down
6 changes: 1 addition & 5 deletions src/components/datagrid/row_height_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,13 @@ export class RowHeightUtils {
return false;
}

computeStylesForGridCell(gridStyles: EuiDataGridStyle) {
cacheStyles(gridStyles: EuiDataGridStyle) {
this.styles = {
paddingTop: cellPaddingsMap[gridStyles.cellPadding!],
paddingBottom: cellPaddingsMap[gridStyles.cellPadding!],
};
}

getComputedCellStyles() {
return this.styles;
}

getRowHeightOption(
rowIndex: number,
rowHeightsOptions?: EuiDataGridRowHeightsOptions
Expand Down

0 comments on commit 51a3d2d

Please sign in to comment.