-
-
- Loading more data
+import { Button } from "@unkey/ui";
+
+type LoadMoreFooterProps = {
+ onLoadMore?: () => void;
+ isFetchingNextPage?: boolean;
+ totalVisible: number;
+ totalCount: number;
+ className?: string;
+ itemLabel?: string;
+ buttonText?: string;
+ hasMore?: boolean;
+ hide?: boolean;
+ countInfoText?: React.ReactNode;
+};
+
+export const LoadMoreFooter = ({
+ onLoadMore,
+ isFetchingNextPage = false,
+ totalVisible,
+ totalCount,
+ itemLabel = "items",
+ buttonText = "Load more",
+ hasMore = true,
+ countInfoText,
+ hide,
+}: LoadMoreFooterProps) => {
+ const shouldShow = !!onLoadMore;
+
+ if (hide) {
+ return;
+ }
+
+ return (
+
+
+
+ {countInfoText &&
{countInfoText}
}
+ {!countInfoText && (
+
+ Viewing {totalVisible}
+ of
+ {totalCount}
+ {itemLabel}
+
+ )}
+
+
+
+
-
-);
+ );
+};
diff --git a/apps/dashboard/components/virtual-table/constants.ts b/apps/dashboard/components/virtual-table/constants.ts
index bb044d355f..51d99354fc 100644
--- a/apps/dashboard/components/virtual-table/constants.ts
+++ b/apps/dashboard/components/virtual-table/constants.ts
@@ -4,7 +4,6 @@ export const DEFAULT_CONFIG: TableConfig = {
rowHeight: 26,
loadingRows: 50,
overscan: 5,
- tableBorder: 1,
throttleDelay: 350,
headerHeight: 40,
} as const;
diff --git a/apps/dashboard/components/virtual-table/hooks/useTableHeight.ts b/apps/dashboard/components/virtual-table/hooks/useTableHeight.ts
index 08c2b8fe97..96f420f0a0 100644
--- a/apps/dashboard/components/virtual-table/hooks/useTableHeight.ts
+++ b/apps/dashboard/components/virtual-table/hooks/useTableHeight.ts
@@ -1,36 +1,27 @@
import { useEffect, useState } from "react";
-
-export const useTableHeight = (
- containerRef: React.RefObject
,
- headerHeight: number,
- tableBorder: number,
-) => {
+// Adds bottom spacing to prevent the table from extending to the edge of the viewport
+const BREATHING_SPACE = 20;
+export const useTableHeight = (containerRef: React.RefObject) => {
const [fixedHeight, setFixedHeight] = useState(0);
-
useEffect(() => {
const calculateHeight = () => {
if (!containerRef.current) {
return;
}
const rect = containerRef.current.getBoundingClientRect();
- const totalHeaderHeight = headerHeight + tableBorder;
- const availableHeight = window.innerHeight - rect.top - totalHeaderHeight;
+ const availableHeight = window.innerHeight - rect.top - BREATHING_SPACE;
setFixedHeight(Math.max(availableHeight, 0));
};
-
calculateHeight();
const resizeObserver = new ResizeObserver(calculateHeight);
window.addEventListener("resize", calculateHeight);
-
if (containerRef.current) {
resizeObserver.observe(containerRef.current);
}
-
return () => {
resizeObserver.disconnect();
window.removeEventListener("resize", calculateHeight);
};
- }, [containerRef, headerHeight, tableBorder]);
-
+ }, [containerRef]);
return fixedHeight;
};
diff --git a/apps/dashboard/components/virtual-table/index.tsx b/apps/dashboard/components/virtual-table/index.tsx
index d72216af0f..f34c275953 100644
--- a/apps/dashboard/components/virtual-table/index.tsx
+++ b/apps/dashboard/components/virtual-table/index.tsx
@@ -2,7 +2,7 @@ import { cn } from "@/lib/utils";
import { CaretDown, CaretExpandY, CaretUp, CircleCarretRight } from "@unkey/icons";
import { Fragment, type Ref, forwardRef, useImperativeHandle, useMemo, useRef } from "react";
import { EmptyState } from "./components/empty-state";
-import { LoadingIndicator } from "./components/loading-indicator";
+import { LoadMoreFooter } from "./components/loading-indicator";
import { DEFAULT_CONFIG } from "./constants";
import { useTableData } from "./hooks/useTableData";
import { useTableHeight } from "./hooks/useTableHeight";
@@ -48,6 +48,7 @@ export const VirtualTable = forwardRef>(
selectedClassName,
selectedItem,
isFetchingNextPage,
+ loadMoreFooterProps,
}: VirtualTableProps,
ref: Ref | undefined,
) {
@@ -55,7 +56,7 @@ export const VirtualTable = forwardRef>(
const parentRef = useRef(null);
const containerRef = useRef(null);
- const fixedHeight = useTableHeight(containerRef, config.headerHeight, config.tableBorder);
+ const fixedHeight = useTableHeight(containerRef);
const tableData = useTableData(realtimeData, historicData);
const virtualizer = useVirtualData({
@@ -276,7 +277,13 @@ export const VirtualTable = forwardRef>(
/>
- {isFetchingNextPage && }
+