From 08a92b46f94043d229e3f099030b617500b9c4d4 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Wed, 27 Nov 2024 15:08:28 +0100 Subject: [PATCH] fix: load more rows if the existing ones do not fill the space (#17874) --- .../data-table/components/DataTable.tsx | 19 ++++++++++++++++--- .../components/RoutingFormResponsesTable.tsx | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/features/data-table/components/DataTable.tsx b/packages/features/data-table/components/DataTable.tsx index 07f27a03c8..229666b986 100644 --- a/packages/features/data-table/components/DataTable.tsx +++ b/packages/features/data-table/components/DataTable.tsx @@ -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 { tableContainerRef: React.RefObject; isPending?: boolean; onRowMouseclick?: (row: Row) => void; - onScroll?: (e: React.UIEvent) => void; + onScroll?: (e: Pick, "target">) => void; tableOverlay?: React.ReactNode; variant?: "default" | "compact"; "data-testid"?: string; @@ -45,6 +45,19 @@ export function DataTable({ 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({ 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" )}> diff --git a/packages/features/insights/components/RoutingFormResponsesTable.tsx b/packages/features/insights/components/RoutingFormResponsesTable.tsx index 8baccbcbfb..b9d9328d2e 100644 --- a/packages/features/insights/components/RoutingFormResponsesTable.tsx +++ b/packages/features/insights/components/RoutingFormResponsesTable.tsx @@ -262,7 +262,7 @@ export function RoutingFormResponsesTable({ routingFormId: selectedRoutingFormId ?? undefined, bookingStatus: selectedBookingStatus ?? undefined, fieldFilter: selectedRoutingFormFilter ?? undefined, - limit: 10, + limit: 30, }, { getNextPageParam: (lastPage) => lastPage.nextCursor,