StoragePoliciesBucketRow.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { FilesBucket as FilesBucketIcon } from 'icons'
  2. import { noop } from 'lodash'
  3. import { forwardRef, type CSSProperties } from 'react'
  4. import {
  5. Badge,
  6. Button,
  7. Card,
  8. CardContent,
  9. CardHeader,
  10. CardTitle,
  11. Table,
  12. TableBody,
  13. TableHead,
  14. TableHeader,
  15. TableRow,
  16. Tooltip,
  17. TooltipContent,
  18. TooltipTrigger,
  19. } from 'ui'
  20. import { PolicyRow } from '@/components/interfaces/Auth/Policies/PolicyTableRow/PolicyRow'
  21. import type { Policy } from '@/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils'
  22. import { PUBLIC_BUCKET_TOOLTIP } from '@/components/interfaces/Storage/Storage.constants'
  23. import { Bucket } from '@/data/storage/buckets-query'
  24. interface StoragePoliciesBucketRowProps {
  25. table: string
  26. label: string
  27. bucket?: Bucket
  28. policies: Policy[]
  29. style?: CSSProperties
  30. onSelectPolicyAdd: (bucketName: string | undefined, table: string) => void
  31. onSelectPolicyEdit: (policy: Policy, bucketName: string, table: string) => void
  32. onSelectPolicyDelete: (policy: Policy) => void
  33. }
  34. export const StoragePoliciesBucketRow = forwardRef<HTMLDivElement, StoragePoliciesBucketRowProps>(
  35. (
  36. {
  37. table = '',
  38. label = '',
  39. bucket,
  40. policies = [],
  41. style,
  42. onSelectPolicyAdd = noop,
  43. onSelectPolicyEdit = noop,
  44. onSelectPolicyDelete = noop,
  45. },
  46. ref
  47. ) => {
  48. return (
  49. <Card ref={ref} style={style}>
  50. <CardHeader className="flex flex-row w-full items-center justify-between gap-2 space-y-0">
  51. <div className="flex flex-1 min-w-0 items-center gap-3">
  52. <FilesBucketIcon className="text-foreground-muted" size={16} strokeWidth={1.5} />
  53. <div className="flex flex-1 min-w-0 items-center gap-1.5">
  54. <CardTitle className="truncate">{label}</CardTitle>
  55. {bucket?.public && (
  56. <Tooltip>
  57. <TooltipTrigger asChild>
  58. <Badge variant="warning" className="flex">
  59. Public
  60. </Badge>
  61. </TooltipTrigger>
  62. <TooltipContent side="top">{PUBLIC_BUCKET_TOOLTIP}</TooltipContent>
  63. </Tooltip>
  64. )}
  65. </div>
  66. </div>
  67. <Button type="outline" onClick={() => onSelectPolicyAdd(bucket?.name, table)}>
  68. New policy
  69. </Button>
  70. </CardHeader>
  71. {policies.length === 0 ? (
  72. <CardContent>
  73. <p className="text-sm text-foreground-lighter">No policies created yet</p>
  74. </CardContent>
  75. ) : (
  76. <CardContent className="p-0">
  77. <Table className="table-fixed">
  78. <TableHeader>
  79. <TableRow>
  80. <TableHead className="w-[40%]">Name</TableHead>
  81. <TableHead className="w-[20%]">Command</TableHead>
  82. <TableHead className="w-[30%]">Applied to</TableHead>
  83. <TableHead className="text-right">
  84. <span className="sr-only">Actions</span>
  85. </TableHead>
  86. </TableRow>
  87. </TableHeader>
  88. <TableBody>
  89. {policies.map((policy) => (
  90. <PolicyRow
  91. key={policy.id ?? policy.name}
  92. policy={policy}
  93. onSelectEditPolicy={(p) => onSelectPolicyEdit(p, bucket?.name ?? '', table)}
  94. onSelectDeletePolicy={onSelectPolicyDelete}
  95. />
  96. ))}
  97. </TableBody>
  98. </Table>
  99. </CardContent>
  100. )}
  101. </Card>
  102. )
  103. }
  104. )
  105. StoragePoliciesBucketRow.displayName = 'StoragePoliciesBucketRow'