diff --git a/components/object/list.tsx b/components/object/list.tsx index 1d4ae59..3a6b653 100644 --- a/components/object/list.tsx +++ b/components/object/list.tsx @@ -26,6 +26,7 @@ import { } from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { SearchInput } from "@/components/search-input" import { PageHeader } from "@/components/page-header" import { DataTable } from "@/components/data-table/data-table" @@ -44,6 +45,11 @@ import { shouldApplyObjectListResponse, shouldResetObjectListPagination, } from "@/lib/object-list-state" +import { + OBJECT_LIST_DEFAULT_PAGE_SIZE, + OBJECT_LIST_PAGE_SIZE_OPTIONS, + normalizeObjectListPageSize, +} from "@/lib/object-list-pagination" import { resolveBucketVersioningState, shouldForceDeleteObjects, @@ -82,7 +88,7 @@ export function ObjectList({ onOpenInfo, onUploadClick, canUpload = false, - pageSize = 25, + pageSize = OBJECT_LIST_DEFAULT_PAGE_SIZE, onRefresh, refreshTrigger = 0, onPreview, @@ -98,6 +104,10 @@ export function ObjectList({ const [searchTerm, setSearchTerm] = React.useState("") const [showDeleted, setShowDeleted] = useLocalStorage("object-list-show-deleted", false) + const [storedPageSize, setStoredPageSize] = useLocalStorage( + "object-list-page-size", + normalizeObjectListPageSize(pageSize), + ) const [loading, setLoading] = React.useState(false) const [data, setData] = React.useState([]) const [continuationToken, setContinuationToken] = React.useState() @@ -109,15 +119,16 @@ export function ObjectList({ const [deleteAllVersions, setDeleteAllVersions] = React.useState(false) const prefix = decodeURIComponent(path) + const resolvedPageSize = normalizeObjectListPageSize(storedPageSize) const listScope = React.useMemo( () => createObjectListScope({ bucket, prefix, - pageSize, + pageSize: resolvedPageSize, showDeleted, }), - [bucket, prefix, pageSize, showDeleted], + [bucket, prefix, resolvedPageSize, showDeleted], ) const canBulkDelete = canCapability("objects.bulkDelete", { bucket, prefix }) const canBulkDownload = canCapability("objects.download", { bucket, prefix }) @@ -139,7 +150,7 @@ export function ObjectList({ const requestScope = activeScopeRef.current setLoading(true) try { - const response = await listObject(bucket, prefix || undefined, pageSize, token, { + const response = await listObject(bucket, prefix || undefined, resolvedPageSize, token, { includeDeleted: showDeleted, }) @@ -192,7 +203,7 @@ export function ObjectList({ }, 200) } }, - [bucket, prefix, pageSize, continuationToken, showDeleted, listObject], + [bucket, prefix, resolvedPageSize, continuationToken, showDeleted, listObject], ) const prevRefreshTriggerRef = React.useRef(refreshTrigger) @@ -210,7 +221,7 @@ export function ObjectList({ } else { void fetchObjects() } - }, [listScope, bucket, prefix, pageSize, continuationToken, showDeleted, refreshTrigger, fetchObjects]) + }, [listScope, bucket, prefix, resolvedPageSize, continuationToken, showDeleted, refreshTrigger, fetchObjects]) const prevDeleteTaskIdsRef = React.useRef>(new Set()) @@ -590,6 +601,14 @@ export function ObjectList({ setTokenHistory((h) => h.slice(0, -1)) } + const handlePageSizeChange = (value: string) => { + const parsed = Number.parseInt(value, 10) + const nextPageSize = normalizeObjectListPageSize(Number.isNaN(parsed) ? undefined : parsed) + setStoredPageSize(nextPageSize) + setContinuationToken(undefined) + setTokenHistory([]) + } + React.useEffect(() => { const col = table.getColumn("object") if (col) col.setFilterValue(searchTerm || undefined) @@ -639,7 +658,7 @@ export function ObjectList({ @@ -657,15 +676,41 @@ export function ObjectList({ emptyDescription={t("Upload files or create folders to populate this bucket.")} /> -
- - +
+
+ + {t("Loaded {count} of up to {pageSize} keys on this page", { + count: data.length, + pageSize: resolvedPageSize, + })} + + {t("Filtering and sorting apply to the current page")} +
+ {t("Rows per page")} + +
+
+
+ + +
diff --git a/i18n/locales/ar-MA.json b/i18n/locales/ar-MA.json index 03ed6dd..375ab23 100644 --- a/i18n/locales/ar-MA.json +++ b/i18n/locales/ar-MA.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "حجم الملف يتجاوز الحد (10MB)", "Files": "الملفات", "Filter From This Page": "تصفية من هذه الصفحة", + "Filter current page": "تصفية الصفحة الحالية", + "Filtering and sorting apply to the current page": "تنطبق التصفية والفرز على الصفحة الحالية", "Finish rebalance successfully before retiring a pool.": "أكمل إعادة التوازن بنجاح قبل إخراج أي تجمع من الخدمة.", "First": "الأول", "First-time setup": "الإعداد لأول مرة", @@ -1038,6 +1040,7 @@ "System Setting": "إعدادات النظام", "Show Deleted Objects": "إظهار الكائنات المحذوفة", "Showing up to {count} keys per page": "عرض ما يصل إلى {count} مفتاحًا لكل صفحة", + "Loaded {count} of up to {pageSize} keys on this page": "تم تحميل {count} من أصل {pageSize} مفتاحًا كحد أقصى في هذه الصفحة", "Single Machine Multiple Disks": "جهاز واحد متعدد الأقراص", "Single Object": "كائن واحد", "Single file supports up to 512GB, use CLI for larger files.": "يدعم الملف الواحد حتى 512GB، استخدم CLI للملفات الأكبر.", diff --git a/i18n/locales/de-DE.json b/i18n/locales/de-DE.json index f9b32b4..4a53259 100644 --- a/i18n/locales/de-DE.json +++ b/i18n/locales/de-DE.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "Dateigröße überschreitet Limit (10MB)", "Files": "Dateien", "Filter From This Page": "Von dieser Seite filtern", + "Filter current page": "Aktuelle Seite filtern", + "Filtering and sorting apply to the current page": "Filterung und Sortierung gelten für die aktuelle Seite", "Finish rebalance successfully before retiring a pool.": "Schließen Sie den Neuausgleich erfolgreich ab, bevor Sie einen Pool stilllegen.", "First": "Erste", "First-time setup": "Ersteinrichtung", @@ -1038,6 +1040,7 @@ "System Setting": "Systemeinstellung", "Show Deleted Objects": "Gelöschte Objekte anzeigen", "Showing up to {count} keys per page": "Bis zu {count} Schlüssel pro Seite", + "Loaded {count} of up to {pageSize} keys on this page": "{count} von bis zu {pageSize} Schlüsseln auf dieser Seite geladen", "Single Machine Multiple Disks": "Einzelmaschine mehrere Festplatten", "Single Object": "Einzelnes Objekt", "Single file supports up to 512GB, use CLI for larger files.": "Einzelne Datei unterstützt bis zu 512GB, für größere Dateien CLI verwenden.", diff --git a/i18n/locales/en-US.json b/i18n/locales/en-US.json index 43c8643..0380b20 100644 --- a/i18n/locales/en-US.json +++ b/i18n/locales/en-US.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "File size exceeds limit (10MB)", "Files": "Files", "Filter From This Page": "Filter From This Page", + "Filter current page": "Filter current page", + "Filtering and sorting apply to the current page": "Filtering and sorting apply to the current page", "Finish rebalance successfully before retiring a pool.": "Finish rebalance successfully before retiring a pool.", "First": "First", "First-time setup": "First-time setup", @@ -1038,6 +1040,7 @@ "System Setting": "System Setting", "Show Deleted Objects": "Show Deleted Objects", "Showing up to {count} keys per page": "Showing up to {count} keys per page", + "Loaded {count} of up to {pageSize} keys on this page": "Loaded {count} of up to {pageSize} keys on this page", "Single Machine Multiple Disks": "Single Machine Multiple Disks", "Single Object": "Single Object", "Single file supports up to 512GB, use CLI for larger files.": "Single file supports up to 512GB, use CLI for larger files.", diff --git a/i18n/locales/es-ES.json b/i18n/locales/es-ES.json index 8e66521..3c8c564 100644 --- a/i18n/locales/es-ES.json +++ b/i18n/locales/es-ES.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "El tamaño del archivo excede el límite (10MB)", "Files": "Archivos", "Filter From This Page": "Filtrar Desde Esta Página", + "Filter current page": "Filtrar página actual", + "Filtering and sorting apply to the current page": "El filtrado y la ordenación se aplican a la página actual", "Finish rebalance successfully before retiring a pool.": "Completa correctamente el reequilibrio antes de retirar un pool.", "First": "Primero", "First-time setup": "Configuración inicial", @@ -1038,6 +1040,7 @@ "System Setting": "Configuración del sistema", "Show Deleted Objects": "Mostrar Objetos Eliminados", "Showing up to {count} keys per page": "Mostrando hasta {count} claves por página", + "Loaded {count} of up to {pageSize} keys on this page": "{count} de hasta {pageSize} claves cargadas en esta página", "Single Machine Multiple Disks": "Máquina Única Múltiples Discos", "Single Object": "Objeto Único", "Single file supports up to 512GB, use CLI for larger files.": "Un solo archivo admite hasta 512GB, use CLI para archivos más grandes.", diff --git a/i18n/locales/fr-FR.json b/i18n/locales/fr-FR.json index 9794e54..7d17daa 100644 --- a/i18n/locales/fr-FR.json +++ b/i18n/locales/fr-FR.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "La taille du fichier dépasse la limite (10 Mo)", "Files": "Fichiers", "Filter From This Page": "Filtrer depuis cette page", + "Filter current page": "Filtrer la page actuelle", + "Filtering and sorting apply to the current page": "Le filtrage et le tri s’appliquent à la page actuelle", "Finish rebalance successfully before retiring a pool.": "Terminez correctement le rééquilibrage avant de retirer un pool.", "First": "Premier", "First-time setup": "Première configuration", @@ -1038,6 +1040,7 @@ "System Setting": "Paramètre système", "Show Deleted Objects": "Afficher les objets supprimés", "Showing up to {count} keys per page": "Jusqu’à {count} clés par page", + "Loaded {count} of up to {pageSize} keys on this page": "{count} clés chargées sur {pageSize} maximum sur cette page", "Single Machine Multiple Disks": "Machine unique, plusieurs disques", "Single Object": "Objet unique", "Single file supports up to 512GB, use CLI for larger files.": "Un seul fichier prend en charge jusqu'à 512 Go, utilisez la CLI pour les fichiers plus volumineux.", diff --git a/i18n/locales/id-ID.json b/i18n/locales/id-ID.json index ddf7d93..3f3f1d5 100644 --- a/i18n/locales/id-ID.json +++ b/i18n/locales/id-ID.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "Ukuran file melebihi batas (10MB)", "Files": "File", "Filter From This Page": "Filter Dari Halaman Ini", + "Filter current page": "Filter halaman saat ini", + "Filtering and sorting apply to the current page": "Pemfilteran dan pengurutan berlaku untuk halaman saat ini", "Finish rebalance successfully before retiring a pool.": "Selesaikan penyeimbangan ulang dengan sukses sebelum memensiunkan pool.", "First": "Pertama", "First-time setup": "Pengaturan pertama kali", @@ -1038,6 +1040,7 @@ "System Setting": "Pengaturan Sistem", "Show Deleted Objects": "Tampilkan Objek Terhapus", "Showing up to {count} keys per page": "Menampilkan hingga {count} kunci per halaman", + "Loaded {count} of up to {pageSize} keys on this page": "Memuat {count} dari maksimal {pageSize} kunci di halaman ini", "Single Machine Multiple Disks": "Single Machine Multiple Disks", "Single Object": "Objek Tunggal", "Single file supports up to 512GB, use CLI for larger files.": "File tunggal mendukung hingga 512GB, gunakan CLI untuk file lebih besar.", diff --git a/i18n/locales/it-IT.json b/i18n/locales/it-IT.json index 2d0637d..fa468af 100644 --- a/i18n/locales/it-IT.json +++ b/i18n/locales/it-IT.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "La dimensione del file supera il limite (10MB)", "Files": "File", "Filter From This Page": "Filtra da questa pagina", + "Filter current page": "Filtra pagina corrente", + "Filtering and sorting apply to the current page": "Filtro e ordinamento si applicano alla pagina corrente", "Finish rebalance successfully before retiring a pool.": "Completa correttamente il ribilanciamento prima di ritirare un pool.", "First": "Primo", "First-time setup": "Configurazione iniziale", @@ -1038,6 +1040,7 @@ "System Setting": "Impostazione di sistema", "Show Deleted Objects": "Mostra oggetti eliminati", "Showing up to {count} keys per page": "Fino a {count} chiavi per pagina", + "Loaded {count} of up to {pageSize} keys on this page": "Caricate {count} di massimo {pageSize} chiavi in questa pagina", "Single Machine Multiple Disks": "Singola macchina più dischi", "Single Object": "Singolo oggetto", "Single file supports up to 512GB, use CLI for larger files.": "Singolo file supporta fino a 512GB, usare CLI per file più grandi.", diff --git a/i18n/locales/ja-JP.json b/i18n/locales/ja-JP.json index 6f8867a..a80c2f7 100644 --- a/i18n/locales/ja-JP.json +++ b/i18n/locales/ja-JP.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "ファイルサイズが制限(10MB)を超えています", "Files": "ファイル", "Filter From This Page": "このページからフィルター", + "Filter current page": "現在のページをフィルター", + "Filtering and sorting apply to the current page": "フィルターと並べ替えは現在のページに適用されます", "Finish rebalance successfully before retiring a pool.": "プールを廃止する前にリバランスを正常に完了してください。", "First": "最初", "First-time setup": "初回設定", @@ -1038,6 +1040,7 @@ "System Setting": "システム設定", "Show Deleted Objects": "削除されたオブジェクトを表示", "Showing up to {count} keys per page": "1 ページあたり最大 {count} 件のキー", + "Loaded {count} of up to {pageSize} keys on this page": "このページに最大 {pageSize} 件中 {count} 件のキーを読み込み済み", "Single Machine Multiple Disks": "単一マシン複数ディスク", "Single Object": "単一オブジェクト", "Single file supports up to 512GB, use CLI for larger files.": "1ファイル最大512GBまで対応、より大きなファイルはCLIをご利用ください。", diff --git a/i18n/locales/ko-KR.json b/i18n/locales/ko-KR.json index 1d1cb27c..16c8058 100644 --- a/i18n/locales/ko-KR.json +++ b/i18n/locales/ko-KR.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "파일 크기가 제한(10MB)을 초과합니다", "Files": "파일", "Filter From This Page": "이 페이지에서 필터링", + "Filter current page": "현재 페이지 필터링", + "Filtering and sorting apply to the current page": "필터링 및 정렬은 현재 페이지에 적용됩니다", "Finish rebalance successfully before retiring a pool.": "풀을 폐기하기 전에 리밸런스를 먼저 성공적으로 완료하세요.", "First": "첫 번째", "First-time setup": "최초 설정", @@ -1038,6 +1040,7 @@ "System Setting": "시스템 설정", "Show Deleted Objects": "삭제된 객체 표시", "Showing up to {count} keys per page": "페이지당 최대 {count}개 키", + "Loaded {count} of up to {pageSize} keys on this page": "이 페이지에 최대 {pageSize}개 중 {count}개 키 로드됨", "Single Machine Multiple Disks": "단일 머신 다중 디스크", "Single Object": "단일 객체", "Single file supports up to 512GB, use CLI for larger files.": "단일 파일 최대 512GB 지원, 더 큰 파일은 CLI를 사용하세요.", diff --git a/i18n/locales/pt-BR.json b/i18n/locales/pt-BR.json index 67fa94b..f1b9711 100644 --- a/i18n/locales/pt-BR.json +++ b/i18n/locales/pt-BR.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "O tamanho do arquivo excede o limite (10MB)", "Files": "Arquivos", "Filter From This Page": "Filtrar Desta Página", + "Filter current page": "Filtrar página atual", + "Filtering and sorting apply to the current page": "A filtragem e a ordenação se aplicam à página atual", "Finish rebalance successfully before retiring a pool.": "Conclua o rebalanceamento com sucesso antes de aposentar um pool.", "First": "Primeiro", "First-time setup": "Configuração inicial", @@ -1038,6 +1040,7 @@ "System Setting": "Configuração do sistema", "Show Deleted Objects": "Mostrar Objetos Excluídos", "Showing up to {count} keys per page": "Mostrando até {count} chaves por página", + "Loaded {count} of up to {pageSize} keys on this page": "{count} de até {pageSize} chaves carregadas nesta página", "Single Machine Multiple Disks": "Máquina Única Múltiplos Discos", "Single Object": "Objeto Único", "Single file supports up to 512GB, use CLI for larger files.": "Arquivo único suporta até 512GB, use CLI para arquivos maiores.", diff --git a/i18n/locales/ru-RU.json b/i18n/locales/ru-RU.json index aa5c531..0bd91fe 100644 --- a/i18n/locales/ru-RU.json +++ b/i18n/locales/ru-RU.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "Размер файла превышает лимит (10MB)", "Files": "Файлы", "Filter From This Page": "Фильтровать с этой страницы", + "Filter current page": "Фильтровать текущую страницу", + "Filtering and sorting apply to the current page": "Фильтрация и сортировка применяются к текущей странице", "Finish rebalance successfully before retiring a pool.": "Успешно завершите перебалансировку перед выводом пула из эксплуатации.", "First": "Первый", "First-time setup": "Первичная настройка", @@ -1038,6 +1040,7 @@ "System Setting": "Системная настройка", "Show Deleted Objects": "Показать удаленные объекты", "Showing up to {count} keys per page": "До {count} ключей на страницу", + "Loaded {count} of up to {pageSize} keys on this page": "На этой странице загружено {count} из максимум {pageSize} ключей", "Single Machine Multiple Disks": "Одна машина несколько дисков", "Single Object": "Один объект", "Single file supports up to 512GB, use CLI for larger files.": "Один файл поддерживает до 512 ГБ, используйте CLI для файлов большего размера.", diff --git a/i18n/locales/tr-TR.json b/i18n/locales/tr-TR.json index c5f4a22..eed410d 100644 --- a/i18n/locales/tr-TR.json +++ b/i18n/locales/tr-TR.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "Dosya boyutu sınırı aşıyor (10MB)", "Files": "Dosyalar", "Filter From This Page": "Bu sayfadan filtreleme yapın", + "Filter current page": "Geçerli sayfayı filtrele", + "Filtering and sorting apply to the current page": "Filtreleme ve sıralama geçerli sayfaya uygulanır", "Finish rebalance successfully before retiring a pool.": "Bir pool’u devreden çıkarmadan önce yeniden dengelemeyi başarıyla tamamlayın.", "First": "İlk", "First-time setup": "İlk kurulum", @@ -1038,6 +1040,7 @@ "System Setting": "Sistem Ayarı", "Show Deleted Objects": "Silinen Nesneleri Göster", "Showing up to {count} keys per page": "Sayfa başına en fazla {count} anahtar", + "Loaded {count} of up to {pageSize} keys on this page": "Bu sayfada en fazla {pageSize} anahtardan {count} tanesi yüklendi", "Single Machine Multiple Disks": "Tek Makine Çoklu Disk", "Single Object": "Tek Nesne", "Single file supports up to 512GB, use CLI for larger files.": "Tek dosya 512GB'a kadar destekler, daha büyük dosyalar için CLI kullanın.", diff --git a/i18n/locales/vi-VN.json b/i18n/locales/vi-VN.json index b37f2ff..a3ac442 100644 --- a/i18n/locales/vi-VN.json +++ b/i18n/locales/vi-VN.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "Kích thước tệp vượt quá giới hạn (10MB)", "Files": "Danh sách tệp", "Filter From This Page": "Lọc trên trang này", + "Filter current page": "Lọc trang hiện tại", + "Filtering and sorting apply to the current page": "Lọc và sắp xếp áp dụng cho trang hiện tại", "Finish rebalance successfully before retiring a pool.": "Hoàn tất cân bằng lại thành công trước khi ngừng sử dụng một pool.", "First": "Đầu tiên", "First-time setup": "Thiết lập lần đầu", @@ -1038,6 +1040,7 @@ "System Setting": "Cài đặt hệ thống", "Show Deleted Objects": "Hiển thị các đối tượng đã xóa", "Showing up to {count} keys per page": "Hiển thị tối đa {count} khóa mỗi trang", + "Loaded {count} of up to {pageSize} keys on this page": "Đã tải {count} trong tối đa {pageSize} khóa trên trang này", "Single Machine Multiple Disks": "Một máy chủ nhiều đĩa", "Single Object": "Đối tượng đơn", "Single file supports up to 512GB, use CLI for larger files.": "Tệp đơn hỗ trợ tối đa 512GB, sử dụng giao diện dòng lệnh (CLI) cho các tệp lớn hơn.", diff --git a/i18n/locales/zh-CN.json b/i18n/locales/zh-CN.json index ec85ad4..0899fa5 100644 --- a/i18n/locales/zh-CN.json +++ b/i18n/locales/zh-CN.json @@ -429,6 +429,8 @@ "File size exceeds limit (10MB)": "文件大小超出限制(10MB)", "Files": "文件", "Filter From This Page": "从本页筛选", + "Filter current page": "筛选当前页", + "Filtering and sorting apply to the current page": "筛选和排序仅作用于当前页", "Finish rebalance successfully before retiring a pool.": "请先成功完成再平衡,再退役存储池。", "First": "第一页", "First-time setup": "首次设置", @@ -1038,6 +1040,7 @@ "System Setting": "系统设置", "Show Deleted Objects": "显示已删除的对象", "Showing up to {count} keys per page": "每页最多显示 {count} 个密钥", + "Loaded {count} of up to {pageSize} keys on this page": "当前页已加载 {count} 个,最多 {pageSize} 个对象键", "Single Machine Multiple Disks": "单机多盘", "Single Object": "单个对象", "Single file supports up to 512GB, use CLI for larger files.": "单个文件最大支持 512GB,上传更大的文件请使用命令行工具", diff --git a/lib/object-list-pagination.js b/lib/object-list-pagination.js new file mode 100644 index 0000000..a3b525a --- /dev/null +++ b/lib/object-list-pagination.js @@ -0,0 +1,5 @@ +export { + OBJECT_LIST_DEFAULT_PAGE_SIZE, + OBJECT_LIST_PAGE_SIZE_OPTIONS, + normalizeObjectListPageSize, +} from "./object-list-pagination.ts" diff --git a/lib/object-list-pagination.ts b/lib/object-list-pagination.ts new file mode 100644 index 0000000..8777a4d --- /dev/null +++ b/lib/object-list-pagination.ts @@ -0,0 +1,13 @@ +export const OBJECT_LIST_DEFAULT_PAGE_SIZE = 100 + +export const OBJECT_LIST_PAGE_SIZE_OPTIONS = [25, 50, 100, 500, 1000] as const + +export type ObjectListPageSize = (typeof OBJECT_LIST_PAGE_SIZE_OPTIONS)[number] + +export function normalizeObjectListPageSize(value: unknown): ObjectListPageSize { + if (typeof value === "number" && OBJECT_LIST_PAGE_SIZE_OPTIONS.includes(value as ObjectListPageSize)) { + return value as ObjectListPageSize + } + + return OBJECT_LIST_DEFAULT_PAGE_SIZE +} diff --git a/tests/lib/object-list-pagination.test.ts b/tests/lib/object-list-pagination.test.ts new file mode 100644 index 0000000..6475194 --- /dev/null +++ b/tests/lib/object-list-pagination.test.ts @@ -0,0 +1,26 @@ +import test from "node:test" +import assert from "node:assert/strict" +import { + OBJECT_LIST_DEFAULT_PAGE_SIZE, + OBJECT_LIST_PAGE_SIZE_OPTIONS, + normalizeObjectListPageSize, +} from "../../lib/object-list-pagination.js" + +test("object list pagination defaults to 100 keys per page", () => { + assert.equal(OBJECT_LIST_DEFAULT_PAGE_SIZE, 100) +}) + +test("object list pagination supports S3-safe page size options", () => { + assert.deepEqual([...OBJECT_LIST_PAGE_SIZE_OPTIONS], [25, 50, 100, 500, 1000]) +}) + +test("normalizeObjectListPageSize keeps supported values", () => { + assert.equal(normalizeObjectListPageSize(25), 25) + assert.equal(normalizeObjectListPageSize(1000), 1000) +}) + +test("normalizeObjectListPageSize falls back for unsupported values", () => { + assert.equal(normalizeObjectListPageSize(10), OBJECT_LIST_DEFAULT_PAGE_SIZE) + assert.equal(normalizeObjectListPageSize("100"), OBJECT_LIST_DEFAULT_PAGE_SIZE) + assert.equal(normalizeObjectListPageSize(undefined), OBJECT_LIST_DEFAULT_PAGE_SIZE) +})