Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3d3060e
feat: Implement dynamic row height measurement for table widget
jacquesikot Mar 6, 2025
034bba2
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
jacquesikot Mar 6, 2025
d645c32
feat: Enhance table widget row height handling with dynamic column me…
jacquesikot Mar 12, 2025
6a50d65
feat: Improve table row height calculation with dynamic data tracking
jacquesikot Mar 12, 2025
808d706
refactor: Simplify VirtualList component by extracting base implement…
jacquesikot Mar 12, 2025
f500054
refactor: Extract BodyContext to separate file to resolve import depe…
jacquesikot Mar 12, 2025
90d6218
fix: Initialize row height tracking for static and virtual tables
jacquesikot Mar 12, 2025
bdc2a31
fix: Improve type safety in TableV2 infinite scroll row height tests
jacquesikot Mar 12, 2025
5b8a9cc
chore: Remove unnecessary comment in BodyContext file
jacquesikot Mar 12, 2025
f32f509
feat: Implement dynamic row height measurement for table widget
jacquesikot Mar 13, 2025
69f64f7
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Mar 17, 2025
922f26a
refactor: implement variable row height support in virtual table
jacquesikot Mar 18, 2025
c724e0a
refactor: make row properties optional in TableWidgetV2 for improved …
jacquesikot Mar 18, 2025
a80cdae
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
jacquesikot Mar 19, 2025
8954902
refactor: optimize row rendering in BaseVirtualList with memoization
jacquesikot Mar 19, 2025
748542f
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
jacquesikot Mar 19, 2025
d8eddca
refactor: enhance row height measurement logic in VirtualTable
jacquesikot Mar 19, 2025
9f50f22
fix: Removed initialization of cellIndexesWithHTMLCell to improve cla…
jacquesikot Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 99 additions & 2 deletions app/client/src/widgets/TableWidgetV2/component/TableBody/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import type { CSSProperties, Key } from "react";
import React, { useContext } from "react";
import React, { useContext, useEffect, useRef } from "react";
import type { Row as ReactTableRowType } from "react-table";
import type { ListChildComponentProps } from "react-window";
import { BodyContext } from ".";
import { renderEmptyRows } from "../cellComponents/EmptyCell";
import { renderBodyCheckBoxCell } from "../cellComponents/SelectionCheckboxCell";
import { MULTISELECT_CHECKBOX_WIDTH, StickyType } from "../Constants";
import {
MULTISELECT_CHECKBOX_WIDTH,
StickyType,
TABLE_SIZES,
} from "../Constants";

interface RowType {
className?: string;
Expand All @@ -14,20 +18,112 @@ interface RowType {
style?: ListChildComponentProps["style"];
}

interface CellWithColumnProps {
column: {
columnProperties?: {
allowCellWrapping?: boolean;
};
};
}

export function Row(props: RowType) {
const { index, row } = props;
const rowRef = useRef<HTMLDivElement>(null);
const {
accentColor,
borderRadius,
columns,
isAddRowInProgress,
listRef,
multiRowSelection,
prepareRow,
primaryColumnId,
rowHeights,
rowNeedsMeasurement,
selectedRowIndex,
selectedRowIndices,
selectTableRow,
} = useContext(BodyContext);

useEffect(() => {
Comment thread
jacquesikot marked this conversation as resolved.
Outdated
if (
rowNeedsMeasurement.current &&
rowNeedsMeasurement.current[index] === false
) {
return;
}

const element = rowRef.current;

if (!element || !row) return;

const cellIndexesWithAllowCellWrapping: number[] = [];
const cellIndexesWithHTMLCell: number[] = [0];

try {
row.cells.forEach((cell, index: number) => {
try {
const typedCell = cell as unknown as CellWithColumnProps;

if (typedCell.column.columnProperties?.allowCellWrapping) {
cellIndexesWithAllowCellWrapping.push(index);
}
} catch (e) {
// Handle potential errors
}
});
} catch (error) {}

// Get all child elements
const children = element.children;
let normalCellHeight = 0;
let htmlCellHeight = 0;

cellIndexesWithAllowCellWrapping.forEach((index: number) => {
const child = children[index] as HTMLElement;
const dynamicContent = child.querySelector(
".t--table-cell-tooltip-target",
);

if (dynamicContent) {
const styles = window.getComputedStyle(dynamicContent);

normalCellHeight +=
(dynamicContent as HTMLElement).offsetHeight +
parseFloat(styles.marginTop) +
parseFloat(styles.marginBottom) +
parseFloat(styles.paddingTop) +
parseFloat(styles.paddingBottom);
}
});

cellIndexesWithHTMLCell.forEach((index: number) => {
const child = children[index] as HTMLElement;
const dynamicContent = child.querySelector(
'[data-testid="t--table-widget-v2-html-cell"]>span',
);

if (dynamicContent) {
const styles = window.getComputedStyle(dynamicContent);

htmlCellHeight +=
(dynamicContent as HTMLElement).offsetHeight +
parseFloat(styles.marginTop) +
parseFloat(styles.marginBottom) +
parseFloat(styles.paddingTop) * 2 +
parseFloat(styles.paddingBottom) * 2;
}
});

const totalHeight =
Math.max(normalCellHeight, htmlCellHeight) +
TABLE_SIZES.DEFAULT.VERTICAL_PADDING * 2;

rowHeights.current && (rowHeights.current[index] = totalHeight);
rowNeedsMeasurement.current && (rowNeedsMeasurement.current[index] = false);
listRef && listRef.current?.resetAfterIndex(index);
}, [index, row]);

prepareRow?.(props.row);
const rowProps = {
...props.row.getRowProps(),
Expand Down Expand Up @@ -61,6 +157,7 @@ export function Row(props: RowType) {
selectTableRow?.(props.row);
e.stopPropagation();
}}
ref={rowRef}
>
{multiRowSelection &&
renderBodyCheckBoxCell(isRowSelected, accentColor, borderRadius)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import type { ListOnItemsRenderedProps, ReactElementType } from "react-window";
import { FixedSizeList, areEqual } from "react-window";
import React from "react";
import type { ListChildComponentProps } from "react-window";
import type { Row as ReactTableRowType } from "react-table";
import { WIDGET_PADDING } from "constants/WidgetConstants";
import { EmptyRow, Row } from "./Row";
import type { TableSizes } from "../Constants";
import React, { useCallback, useContext } from "react";
import type { Row as ReactTableRowType } from "react-table";
import type {
ListChildComponentProps,
ListOnItemsRenderedProps,
ReactElementType,
} from "react-window";
import { VariableSizeList, areEqual } from "react-window";
import type SimpleBar from "simplebar-react";
import { BodyContext } from ".";
import type { TableSizes } from "../Constants";
import { EmptyRow, Row } from "./Row";

const rowRenderer = React.memo((rowProps: ListChildComponentProps) => {
const { data, index, style } = rowProps;
Expand Down Expand Up @@ -35,7 +39,7 @@ interface BaseVirtualListProps {
innerElementType?: ReactElementType;
outerRef?: React.Ref<SimpleBar>;
onItemsRendered?: (props: ListOnItemsRenderedProps) => void;
infiniteLoaderListRef?: React.Ref<FixedSizeList>;
infiniteLoaderListRef?: React.Ref<VariableSizeList>;
itemCount: number;
pageSize: number;
}
Expand All @@ -50,9 +54,44 @@ const BaseVirtualList = React.memo(function BaseVirtualList({
rows,
tableSizes,
}: BaseVirtualListProps) {
const { listRef, rowHeights } = useContext(BodyContext);

const combinedRef = (list: VariableSizeList | null) => {
// Handle infiniteLoaderListRef
if (infiniteLoaderListRef) {
if (typeof infiniteLoaderListRef === "function") {
infiniteLoaderListRef(list);
} else {
(
infiniteLoaderListRef as React.MutableRefObject<VariableSizeList | null>
).current = list;
}
}

// Handle listRef - only if it's a mutable ref
if (listRef && "current" in listRef) {
(listRef as React.MutableRefObject<VariableSizeList | null>).current =
list;
}
};

const getItemSize = useCallback(
(index: number) => {
try {
return rowHeights.current?.[index]
? Math.max(rowHeights.current?.[index], tableSizes.ROW_HEIGHT)
: tableSizes.ROW_HEIGHT;
} catch (error) {
return tableSizes.ROW_HEIGHT;
}
},
[rowHeights.current, tableSizes.ROW_HEIGHT],
);

return (
<FixedSizeList
<VariableSizeList
className="virtual-list simplebar-content"
estimatedItemSize={tableSizes.ROW_HEIGHT}
height={
height -
tableSizes.TABLE_HEADER_HEIGHT -
Expand All @@ -61,14 +100,14 @@ const BaseVirtualList = React.memo(function BaseVirtualList({
innerElementType={innerElementType}
itemCount={itemCount}
itemData={rows}
itemSize={tableSizes.ROW_HEIGHT}
itemSize={getItemSize}
onItemsRendered={onItemsRendered}
outerRef={outerRef}
ref={infiniteLoaderListRef}
ref={combinedRef}
width={`calc(100% + ${2 * WIDGET_PADDING}px)`}
>
{rowRenderer}
</FixedSizeList>
</VariableSizeList>
);
});

Expand Down
22 changes: 20 additions & 2 deletions app/client/src/widgets/TableWidgetV2/component/TableBody/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Ref } from "react";
import React from "react";
import React, { useEffect, type Ref, type RefObject, useRef } from "react";
import type {
Row as ReactTableRowType,
TableBodyPropGetter,
TableBodyProps,
} from "react-table";
import type { VariableSizeList } from "react-window";
import { type ReactElementType } from "react-window";
import type SimpleBar from "simplebar-react";
import type { ReactTableColumnProps, TableSizes } from "../Constants";
Expand Down Expand Up @@ -33,6 +33,9 @@ export type BodyContextType = {
propGetter?: TableBodyPropGetter<Record<string, unknown>> | undefined,
): TableBodyProps;
totalColumnsWidth?: number;
rowHeights: RefObject<{ [key: number]: number }>;
rowNeedsMeasurement: RefObject<{ [key: number]: boolean }>;
listRef: RefObject<VariableSizeList> | null;
} & Partial<HeaderComponentProps>;

export const BodyContext = React.createContext<BodyContextType>({
Expand All @@ -47,6 +50,9 @@ export const BodyContext = React.createContext<BodyContextType>({
primaryColumnId: "",
isAddRowInProgress: false,
totalColumnsWidth: 0,
rowHeights: { current: {} },
rowNeedsMeasurement: { current: {} },
listRef: null,
});

interface BodyPropsType {
Expand Down Expand Up @@ -133,6 +139,15 @@ export const TableBody = React.forwardRef(
...restOfProps
} = props;

const listRef = useRef<VariableSizeList>(null);
const rowHeights = useRef<{ [key: number]: number }>({});
// Keep track of which rows need measurement
const rowNeedsMeasurement = useRef<{ [key: number]: boolean }>({});

useEffect(() => {
rowNeedsMeasurement.current = {};
}, [rows]);

return (
<BodyContext.Provider
value={{
Expand Down Expand Up @@ -164,6 +179,9 @@ export const TableBody = React.forwardRef(
rows,
getTableBodyProps: props.getTableBodyProps,
totalColumnsWidth: props.totalColumnsWidth,
rowHeights: rowHeights,
rowNeedsMeasurement: rowNeedsMeasurement,
listRef: listRef,
}}
>
{isInfiniteScrollEnabled ? (
Expand Down