fix: load more rows if the existing ones do not fill the space (#17874)

This commit is contained in:
Eunjae Lee authored and GitHub committed 2024-11-27 07:08:28 -07:00
1 parent 877e4199e7
commit 08a92b46f9
2 files changed
+17 -4

No files matched your search

@@ -4,7 +4,7 @@ import type { Row } from "@tanstack/react-table";
import { flexRender } from "@tanstack/react-table";
import type { Table as ReactTableType } from "@tanstack/react-table";
import { useVirtualizer } from "@tanstack/react-virtual";
import { useMemo } from "react";
import { useMemo, useEffect } from "react";
import classNames from "@calcom/lib/classNames";
import { Icon, TableNew, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@calcom/ui";
@@ -14,7 +14,7 @@ export interface DataTableProps<TData, TValue> {
tableContainerRef: React.RefObject<HTMLDivElement>;
isPending?: boolean;
onRowMouseclick?: (row: Row<TData>) => void;
onScroll?: (e: React.UIEvent<HTMLDivElement, UIEvent>) => void;
onScroll?: (e: Pick<React.UIEvent<HTMLDivElement, UIEvent>, "target">) => void;
tableOverlay?: React.ReactNode;
variant?: "default" | "compact";
"data-testid"?: string;
@@ -45,6 +45,19 @@ export function DataTable<TData, TValue>({
overscan: 10,
});
useEffect(() => {
if (rowVirtualizer.getVirtualItems().length >= rows.length && tableContainerRef.current) {
const target = tableContainerRef.current;
// Right after the last row is rendered, tableContainer's scrollHeight is
// temporarily larger than the actual height of the table, so we need to
// wait for a short time before calling onScroll to ensure the scrollHeight
// is correct.
setTimeout(() => {
onScroll?.({ target });
}, 100);
}
}, [rowVirtualizer.getVirtualItems().length, rows.length, tableContainerRef.current]);
const virtualRows = rowVirtualizer.getVirtualItems();
const columnSizeVars = useMemo(() => {
@@ -152,7 +165,7 @@ export function DataTable<TData, TValue>({
width: `calc(var(--col-${cell.column.id}-size) * 1px)`,
}}
className={classNames(
"flex shrink-0 items-center overflow-auto",
"flex shrink-0 items-center overflow-hidden",
variant === "compact" && "p-1.5",
meta?.sticky && "group-hover:bg-muted bg-default sticky"
)}>
@@ -262,7 +262,7 @@ export function RoutingFormResponsesTable({
routingFormId: selectedRoutingFormId ?? undefined,
bookingStatus: selectedBookingStatus ?? undefined,
fieldFilter: selectedRoutingFormFilter ?? undefined,
limit: 10,
limit: 30,
},
{
getNextPageParam: (lastPage) => lastPage.nextCursor,