Skip to content

Commit f92e078

Browse files
Revert PR #537 (#548)
1 parent 977e547 commit f92e078

File tree

8 files changed

+25
-157
lines changed

8 files changed

+25
-157
lines changed

Diff for: src/components/Grid/Cell.tsx

+10-25
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import { memo, useEffect, useRef } from "react";
1+
import { memo } from "react";
22
import { GridChildComponentProps, areEqual } from "react-window";
33
import { ItemDataType } from "./types";
44
import { StyledCell } from "./StyledCell";
55

66
type CellProps = GridChildComponentProps<ItemDataType> & {
77
width: number;
8-
};
8+
}
99

1010
export const Cell = memo(
11-
({ data, rowIndex, columnIndex, style, ...props }: CellProps) => {
11+
({
12+
data,
13+
rowIndex,
14+
columnIndex,
15+
style,
16+
...props
17+
}: CellProps) => {
1218
const {
1319
cell: CellData,
1420
getSelectionType,
@@ -19,8 +25,6 @@ export const Cell = memo(
1925
showHeader,
2026
rowHeight,
2127
rowStart,
22-
rowAutoHeight,
23-
updateRowHeight,
2428
} = data;
2529

2630
const currentRowIndex = rowIndex + rowStart;
@@ -56,29 +60,11 @@ export const Cell = memo(
5660
const selectionBorderLeft = rightOfSelectionBorder || rightOfFocus || isFocused;
5761
const selectionBorderTop = belowSelectionBorder || belowFocus || isFocused;
5862

59-
const cellRef = useRef<HTMLDivElement>(null);
60-
61-
useEffect(() => {
62-
if (!rowAutoHeight) {
63-
return;
64-
}
65-
if (cellRef.current) {
66-
const height = cellRef.current.getBoundingClientRect().height;
67-
updateRowHeight(rowIndex, height);
68-
}
69-
}, [updateRowHeight, rowIndex, rowAutoHeight]);
70-
71-
const styleWithHeight = {
72-
...style,
73-
height: "auto",
74-
};
75-
7663
return (
7764
<div
78-
style={styleWithHeight}
65+
style={style}
7966
data-row={currentRowIndex}
8067
data-column={columnIndex}
81-
ref={cellRef}
8268
>
8369
<StyledCell
8470
as={CellData}
@@ -99,7 +85,6 @@ export const Cell = memo(
9985
data-grid-row={currentRowIndex}
10086
data-grid-column={columnIndex}
10187
$showBorder
102-
$rowAutoHeight={rowAutoHeight}
10388
{...props}
10489
/>
10590
</div>

Diff for: src/components/Grid/Grid.stories.tsx

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ import { useCallback, useEffect, useState } from "react";
22
import { CellProps, GridContextMenuItemProps, SelectedRegion, SelectionFocus } from "..";
33
import { Grid as CUIGrid } from "./Grid";
44

5-
const Cell: CellProps = ({
6-
type,
7-
rowIndex,
8-
columnIndex,
9-
isScrolling,
10-
width,
11-
...props
12-
}) => {
5+
const Cell: CellProps = ({ type, rowIndex, columnIndex, isScrolling, width, ...props }) => {
136
return (
147
<div
158
data-scrolling={isScrolling}
@@ -27,7 +20,6 @@ interface Props {
2720
row: number;
2821
column: number;
2922
};
30-
rowAutoHeight?: boolean;
3123
}
3224
const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
3325
const [focus, setFocus] = useState(focusProp);
@@ -79,7 +71,6 @@ const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
7971
});
8072
}}
8173
getMenuOptions={getMenuOptions}
82-
rowAutoHeight={props.rowAutoHeight}
8374
{...props}
8475
/>
8576
</div>

Diff for: src/components/Grid/Grid.test.tsx

+5-51
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
1-
import { CellProps, Grid, GridProps } from "@/components";
2-
import { renderCUI } from "@/utils/test-utils";
3-
import { SelectionFocus } from "./types";
4-
import { ReactNode } from "react";
1+
import {CellProps, Grid, GridProps} from "@/components";
2+
import {renderCUI} from "@/utils/test-utils";
3+
import {SelectionFocus} from "./types";
4+
import {ReactNode} from "react";
55

66
const Cell: CellProps = ({ type, rowIndex, columnIndex, isScrolling, ...props }) => {
7-
let content = `${rowIndex} ${columnIndex} - ${type}`;
8-
9-
if (rowIndex === 0 && columnIndex === 0) {
10-
content = `CREATE TABLE random_user_events (
11-
user_id UInt32,
12-
event_time DateTime,
13-
event_type Enum8('click' = 1, 'view' = 2, 'purchase' = 3),
14-
item_id String,
15-
price Decimal(10,2),
16-
quantity UInt16
17-
) ENGINE = MergeTree()
18-
ORDER BY (user_id, event_time)
19-
PARTITION BY toYYYYMM(event_time)
20-
SETTINGS index_granularity = 8192;`;
21-
}
22-
237
return (
248
<div
259
data-scrolling={isScrolling}
2610
{...props}
2711
data-testid={`${type}-${rowIndex ?? "x"}-${columnIndex ?? "x"}`}
2812
>
29-
{content}
13+
{rowIndex} {columnIndex} - {type}
3014
</div>
3115
);
3216
};
@@ -47,7 +31,6 @@ interface Props
4731
focus?: SelectionFocus;
4832
onFocusChange?: (rowIndex: number, columnIndex: number) => void;
4933
onColumnResize?: () => void;
50-
rowAutoHeight?: boolean;
5134
}
5235
type AutoSizerModule = typeof import("react-virtualized-auto-sizer");
5336

@@ -77,7 +60,6 @@ describe("Grid", () => {
7760
onColumnResize,
7861
focus,
7962
onFocusChange,
80-
rowAutoHeight,
8163
...props
8264
}: Props) =>
8365
renderCUI(
@@ -90,7 +72,6 @@ describe("Grid", () => {
9072
onColumnResize={onColumnResize ?? onColumnResizeTestFn}
9173
onFocusChange={onFocusChange ?? onFocusChangeTestFn}
9274
getMenuOptions={getMenuOptions}
93-
rowAutoHeight={rowAutoHeight}
9475
{...props}
9576
/>
9677
);
@@ -118,31 +99,4 @@ describe("Grid", () => {
11899
cell && expect(cell.dataset.selected).toEqual("true");
119100
cell && expect(cell.dataset.focused).toEqual("true");
120101
});
121-
122-
it("should set row height to default (33px) when rowAutoHeight is false", async () => {
123-
const { getByTestId } = renderGrid({
124-
rowCount: 10,
125-
columnCount: 10,
126-
rowAutoHeight: false,
127-
});
128-
129-
const cell = getByTestId("row-cell-0-0");
130-
131-
const computedHeight = window.getComputedStyle(cell).height;
132-
const heightValue = parseFloat(computedHeight);
133-
expect(heightValue).toBe(33);
134-
});
135-
136-
it("should expand row height to 100% when rowAutoHeight is true", async () => {
137-
const { getByTestId } = renderGrid({
138-
rowCount: 1,
139-
columnCount: 1,
140-
rowAutoHeight: true,
141-
});
142-
143-
const cell = getByTestId("row-cell-0-0");
144-
145-
const computedHeight = window.getComputedStyle(cell).height;
146-
expect(computedHeight).toBe("100%");
147-
});
148102
});

Diff for: src/components/Grid/Grid.tsx

+2-41
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
149149
onContextMenu: onContextMenuProp,
150150
forwardedGridRef,
151151
onItemsRendered: onItemsRenderedProp,
152-
rowAutoHeight,
153152
...props
154153
},
155154
forwardedRef
@@ -213,34 +212,6 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
213212
onCopyCallback,
214213
]);
215214

216-
const rowHeightsRef = useRef(new Map());
217-
218-
const getRowHeight = useCallback(
219-
(index: number) => {
220-
if (rowAutoHeight && rowHeightsRef.current.get(index)) {
221-
return rowHeightsRef.current.get(index) + rowHeight;
222-
}
223-
return rowHeight;
224-
},
225-
[rowHeight, rowAutoHeight]
226-
);
227-
228-
const updateRowHeight = useCallback(
229-
(rowIndex: number, height: number) => {
230-
if (!rowAutoHeight) {
231-
return;
232-
}
233-
const prevHeight = rowHeightsRef.current.get(rowIndex) ?? 0;
234-
if (height > prevHeight) {
235-
rowHeightsRef.current.set(rowIndex, height);
236-
if (gridRef.current) {
237-
gridRef.current.resetAfterRowIndex(rowIndex);
238-
}
239-
}
240-
},
241-
[rowAutoHeight]
242-
);
243-
244215
const customOnCopy: () => Promise<void> = useMemo(() => {
245216
const result = async () => {
246217
if (onCopyProp) {
@@ -434,9 +405,6 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
434405
headerHeight,
435406
rowNumberWidth,
436407
rowStart,
437-
rowAutoHeight,
438-
updateRowHeight,
439-
getRowHeight,
440408
};
441409

442410
const InnerElementType = forwardRef<HTMLDivElement, InnerElementTypeTypes>(
@@ -467,7 +435,6 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
467435
showHeader={showHeader}
468436
rowStart={rowStart}
469437
showBorder={showBorder}
470-
rowAutoHeight={rowAutoHeight}
471438
/>
472439
)}
473440

@@ -788,6 +755,7 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
788755
const onItemsRendered = useCallback(
789756
(props: GridOnItemsRenderedProps) => {
790757
lastItemsRenderedProps.current = props;
758+
791759
return onItemsRenderedProp?.({
792760
...props,
793761
visibleRowStartIndex: props.visibleRowStartIndex + rowStart,
@@ -818,13 +786,6 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
818786
);
819787
};
820788

821-
// Handles the case when rowCount/columnCount changes, rerenders styles
822-
useEffect(() => {
823-
if (gridRef.current) {
824-
gridRef.current.resetAfterRowIndex(0);
825-
}
826-
}, [rowCount, columnCount]);
827-
828789
return (
829790
<ContextMenu
830791
modal={false}
@@ -859,7 +820,7 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
859820
height={height}
860821
width={width}
861822
columnCount={columnCount}
862-
rowHeight={getRowHeight}
823+
rowHeight={() => rowHeight}
863824
useIsScrolling={useIsScrolling}
864825
innerElementType={InnerElementType}
865826
itemData={data}

Diff for: src/components/Grid/Header.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ const RowColumnContainer = styled(HeaderCellContainer)<{
9999
const RowColumn = styled(StyledCell)`
100100
width: 100%;
101101
text-align: right;
102-
overflow: hidden;
103102
`;
104103

105104
const Column = ({
@@ -131,7 +130,7 @@ const Column = ({
131130
(leftSelectionType === "selectDirect" || isSelected) &&
132131
leftSelectionType !== selectionType;
133132

134-
const columnWidth = getColumnWidth(columnIndex);
133+
const columnWidth = getColumnWidth(columnIndex)
135134
return (
136135
<HeaderCellContainer
137136
$width={columnWidth}
@@ -187,7 +186,7 @@ const Header = ({
187186
getColumnHorizontalPosition,
188187
getResizerPosition,
189188
showBorder,
190-
resizingState,
189+
resizingState
191190
}: HeaderProps) => {
192191
const selectedAllType = getSelectionType({
193192
type: "all",

0 commit comments

Comments
 (0)