BucketsTable.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { useRef } from 'react'
  2. import { Table, TableBody } from 'ui'
  3. import { LoadMoreRow } from './BucketsTable.LoadMoreRow'
  4. import type { BucketsTablePaginationProps } from './BucketsTable.types'
  5. import { BucketTableEmptyState, BucketTableHeader, BucketTableRow } from './BucketTable'
  6. import { VirtualizedTable, VirtualizedTableBody } from '@/components/ui/VirtualizedTable'
  7. import { Bucket } from '@/data/storage/buckets-query'
  8. type BucketsTableProps = {
  9. buckets: Bucket[]
  10. projectRef: string
  11. filterString: string
  12. formattedGlobalUploadLimit: string
  13. pagination: BucketsTablePaginationProps
  14. }
  15. export const BucketsTable = (props: BucketsTableProps) => {
  16. const isVirtualized = props.buckets.length > 50
  17. return isVirtualized ? (
  18. <BucketsTableVirtualized {...props} />
  19. ) : (
  20. <BucketsTableUnvirtualized {...props} />
  21. )
  22. }
  23. const BucketsTableUnvirtualized = ({
  24. buckets,
  25. projectRef,
  26. filterString,
  27. formattedGlobalUploadLimit,
  28. pagination: { hasMore = false, isLoadingMore = false, onLoadMore },
  29. }: BucketsTableProps) => {
  30. const showSearchEmptyState = buckets.length === 0 && filterString.length > 0
  31. return (
  32. <Table
  33. containerProps={{
  34. containerClassName: 'h-full overflow-auto',
  35. className: 'overflow-visible',
  36. }}
  37. >
  38. <BucketTableHeader mode="standard" hasBuckets={buckets.length > 0} />
  39. <TableBody>
  40. {showSearchEmptyState ? (
  41. <BucketTableEmptyState mode="standard" filterString={filterString} />
  42. ) : (
  43. buckets.map((bucket) => (
  44. <BucketTableRow
  45. mode="standard"
  46. key={bucket.id}
  47. bucket={bucket}
  48. projectRef={projectRef}
  49. formattedGlobalUploadLimit={formattedGlobalUploadLimit}
  50. />
  51. ))
  52. )}
  53. <LoadMoreRow
  54. mode="standard"
  55. colSpan={6}
  56. hasMore={hasMore}
  57. isLoadingMore={isLoadingMore}
  58. onLoadMore={onLoadMore}
  59. />
  60. </TableBody>
  61. </Table>
  62. )
  63. }
  64. const BucketsTableVirtualized = ({
  65. buckets,
  66. projectRef,
  67. filterString,
  68. formattedGlobalUploadLimit,
  69. pagination: { hasMore = false, isLoadingMore = false, onLoadMore },
  70. }: BucketsTableProps) => {
  71. const showSearchEmptyState = buckets.length === 0 && filterString.length > 0
  72. const scrollContainerRef = useRef<HTMLDivElement>(null)
  73. return (
  74. <VirtualizedTable
  75. data={buckets}
  76. estimateSize={() => 59}
  77. getItemKey={(bucket) => bucket.id}
  78. scrollContainerRef={scrollContainerRef}
  79. >
  80. <BucketTableHeader mode="virtualized" hasBuckets={buckets.length > 0} />
  81. <VirtualizedTableBody<Bucket>
  82. paddingColSpan={5}
  83. emptyContent={
  84. showSearchEmptyState ? (
  85. <BucketTableEmptyState mode="virtualized" filterString={filterString} />
  86. ) : undefined
  87. }
  88. trailingContent={
  89. <LoadMoreRow
  90. mode="virtualized"
  91. colSpan={6}
  92. hasMore={hasMore}
  93. isLoadingMore={isLoadingMore}
  94. onLoadMore={onLoadMore}
  95. />
  96. }
  97. >
  98. {(bucket) => (
  99. <BucketTableRow
  100. mode="virtualized"
  101. key={bucket.id}
  102. bucket={bucket}
  103. projectRef={projectRef}
  104. formattedGlobalUploadLimit={formattedGlobalUploadLimit}
  105. />
  106. )}
  107. </VirtualizedTableBody>
  108. </VirtualizedTable>
  109. )
  110. }