Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

pagination rag

ahmedcoder01bd3d8d213701
diff --git a/packages/app/src/react/features/data-pool/pages/DataPoolPage.tsx b/packages/app/src/react/features/data-pool/pages/DataPoolPage.tsx
index 29f24f11..fae9105d 100644
--- a/packages/app/src/react/features/data-pool/pages/DataPoolPage.tsx
+++ b/packages/app/src/react/features/data-pool/pages/DataPoolPage.tsx
@@ -10,6 +10,7 @@ import TableRowSkeleton from '@src/react/shared/components/ui/table/table.row.sk
import { useScreenSize } from '@src/react/shared/hooks/useScreenSize';
import { errorToast, successToast } from '@src/shared/components/toast';
import { SMYTHOS_DOCS_URL } from '@src/shared/constants/general';
+import { Loader2 } from 'lucide-react';
import { ChangeEvent, FC, useCallback, useEffect, useMemo, useState } from 'react';
import { dataPoolClient } from '../client/datapool.client';
import { CreateNamespaceModal } from '../components/CreateNamespaceModal';
@@ -22,9 +23,10 @@ import { DEFAULT_PAGINATION_LIMIT } from '../types';
const DataPoolPageContent: FC = () => {
const [namespaces, setNamespaces] = useState<Namespace[]>([]);
const [loading, setLoading] = useState<boolean>(false);
+ const [loadingMore, setLoadingMore] = useState<boolean>(false);
const [searchQuery, setSearchQuery] = useState<string>('');
const [page, setPage] = useState<number>(1);
- const [hasMore, setHasMore] = useState<boolean>(true);
+ const [total, setTotal] = useState<number>(0);
const [isCreateModalOpen, setIsCreateModalOpen] = useState<boolean>(false);
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState<boolean>(false);
const [namespaceToDelete, setNamespaceToDelete] = useState<NamespaceWithProvider | null>(null);
@@ -37,24 +39,31 @@ const DataPoolPageContent: FC = () => {
*/
const fetchNamespaces = useCallback(
async (currentPage: number = 1) => {
+ const isInitialLoad = currentPage === 1;
try {
- setLoading(true);
+ if (isInitialLoad) {
+ setLoading(true);
+ } else {
+ setLoadingMore(true);
+ }
+
const response = await dataPoolClient.listNamespaces({
page: currentPage,
limit: DEFAULT_PAGINATION_LIMIT,
});
- const { namespaces: fetchedNamespaces } = response;
+ const { namespaces: fetchedNamespaces, total: fetchedTotal } = response;
setNamespaces((prev) =>
- currentPage === 1 ? fetchedNamespaces : [...prev, ...fetchedNamespaces],
+ isInitialLoad ? fetchedNamespaces : [...prev, ...fetchedNamespaces],
);
- setHasMore(fetchedNamespaces.length === DEFAULT_PAGINATION_LIMIT);
+ setTotal(fetchedTotal);
} catch (error: unknown) {
const errorMessage = (error as Error)?.message || 'Failed to fetch data spaces. Please try again.';
errorToast(errorMessage);
} finally {
setLoading(false);
+ setLoadingMore(false);
}
},
[],
@@ -115,8 +124,8 @@ const DataPoolPageContent: FC = () => {
// Call API to delete
await dataPoolClient.deleteNamespace(namespaceToDelete.label);
- // Manually remove from list without refetching
setNamespaces((prev) => prev.filter((ns) => ns.label !== namespaceToDelete.label));
+ setTotal((prev) => Math.max(0, prev - 1));
successToast('Data space deleted successfully');
handleCloseDeleteDialog();
@@ -248,16 +257,30 @@ const DataPoolPageContent: FC = () => {
{/* Loading State */}
{loading && renderSkeletonLoading()}
- {/* Load More */}
- {!searchQuery && hasMore && !loading && namespaces.length > 0 && (
- <div className="px-6 py-4 text-center border-t">
- <button
- onClick={handleLoadMore}
- type="button"
- className="text-gray-500 hover:underline"
- >
- Load More
- </button>
+ {/* Pagination Footer */}
+ {!loading && namespaces.length > 0 && (
+ <div className="px-6 py-3 border-t bg-gray-50 flex items-center justify-between">
+ <span className="text-xs text-gray-500">
+ Showing {namespaces.length} of {total} data space{total !== 1 ? 's' : ''}
+ </span>
+
+ {!searchQuery && namespaces.length < total && (
+ <button
+ onClick={handleLoadMore}
+ disabled={loadingMore}
+ type="button"
+ className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 hover:border-gray-400 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
+ >
+ {loadingMore ? (
+ <>
+ <Loader2 className="h-3 w-3 animate-spin" />
+ Loading...
+ </>
+ ) : (
+ `Load More`
+ )}
+ </button>
+ )}
</div>
)}
</div>
diff --git a/packages/app/src/react/features/data-pool/pages/DatasourcesPage.tsx b/packages/app/src/react/features/data-pool/pages/DatasourcesPage.tsx
index ae94230d..3530209f 100644
--- a/packages/app/src/react/features/data-pool/pages/DatasourcesPage.tsx
+++ b/packages/app/src/react/features/data-pool/pages/DatasourcesPage.tsx
@@ -10,6 +10,7 @@ import TableRowSkeleton from '@src/react/shared/components/ui/table/table.row.sk
import { useScreenSize } from '@src/react/shared/hooks/useScreenSize';
import { errorToast, successToast } from '@src/shared/components/toast';
import { Breadcrumb } from 'flowbite-react';
+import { Loader2 } from 'lucide-react';
import { ChangeEvent, FC, useCallback, useEffect, useMemo, useState } from 'react';
import { HiHome } from 'react-icons/hi';
import { Link, useParams } from 'react-router-dom';
@@ -20,11 +21,14 @@ import { UploadDatasourceDialog } from '../components/UploadDatasourceDialog';
import { ViewDatasourceDialog } from '../components/ViewDatasourceDialog';
import type { Datasource } from '../types/datasource.types';
+const DATASOURCES_PAGE_SIZE = 10;
+
const DatasourcesPage: FC = () => {
const { namespaceLabel } = useParams<{ namespaceLabel: string }>();
const [datasources, setDatasources] = useState<Datasource[]>([]);
const [loading, setLoading] = useState<boolean>(false);
const [searchQuery, setSearchQuery] = useState<string>('');
+ const [visibleCount, setVisibleCount] = useState<number>(DATASOURCES_PAGE_SIZE);
const [isUploadDialogOpen, setIsUploadDialogOpen] = useState<boolean>(false);
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState<boolean>(false);
const [isViewDialogOpen, setIsViewDialogOpen] = useState<boolean>(false);
@@ -57,10 +61,13 @@ const DatasourcesPage: FC = () => {
}, [fetchDatasources]);
/**
- * Handle search change
+ * Handle search change — reset visible count when clearing search
*/
const handleSearchChange = (value: string) => {
setSearchQuery(value);
+ if (!value) {
+ setVisibleCount(DATASOURCES_PAGE_SIZE);
+ }
};
/**
@@ -138,6 +145,18 @@ const DatasourcesPage: FC = () => {
);
}, [datasources, searchQuery]);
+ /** Progressively reveal items to avoid rendering huge lists at once */
+ const visibleDatasources: Datasource[] = useMemo(
+ () => (searchQuery ? filteredDatasources : filteredDatasources.slice(0, visibleCount)),
+ [filteredDatasources, visibleCount, searchQuery],
+ );
+
+ const totalFiltered = filteredDatasources.length;
+
+ const handleLoadMore = useCallback(() => {
+ setVisibleCount((prev) => prev + DATASOURCES_PAGE_SIZE);
+ }, []);
+
/**
* Render skeleton loading rows
*/
@@ -204,9 +223,9 @@ const DatasourcesPage: FC = () => {
{/* Main Content */}
<div className="bg-white rounded-lg overflow-hidden border border-gray-200">
{/* Table */}
- {filteredDatasources.length > 0 && (
+ {visibleDatasources.length > 0 && (
<DatasourcesTable
- datasources={filteredDatasources}
+ datasources={visibleDatasources}
onDelete={handleDeleteClick}
onView={handleViewClick}
/>
@@ -247,6 +266,25 @@ const DatasourcesPage: FC = () => {
{/* Loading State */}
{loading && renderSkeletonLoading()}
+
+ {/* Pagination Footer */}
+ {!loading && visibleDatasources.length > 0 && (
+ <div className="px-6 py-3 border-t bg-gray-50 flex items-center justify-between">
+ <span className="text-xs text-gray-500">
+ Showing {visibleDatasources.length} of {totalFiltered} datasource{totalFiltered !== 1 ? 's' : ''}
+ </span>
+ {!searchQuery && visibleCount < totalFiltered && (
+ <button
+ onClick={handleLoadMore}
+ type="button"
+ className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 hover:border-gray-400 transition-colors"
+ >
+ <Loader2 className="h-3 w-3 hidden" />
+ Load More
+ </button>
+ )}
+ </div>
+ )}
</div>
{/* Upload Datasource Dialog */}