StorageMenuV2.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { IS_PLATFORM, useParams } from 'common'
  2. import Link from 'next/link'
  3. import { useRouter } from 'next/router'
  4. import { Badge, Menu } from 'ui'
  5. import { BUCKET_TYPES } from './Storage.constants'
  6. import { useStorageV2Page } from './Storage.utils'
  7. import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
  8. import {
  9. useIsAnalyticsBucketsEnabled,
  10. useIsVectorBucketsEnabled,
  11. } from '@/data/config/project-storage-config-query'
  12. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  13. import { SHORTCUT_IDS, type ShortcutId } from '@/state/shortcuts/registry'
  14. import { useShortcut } from '@/state/shortcuts/useShortcut'
  15. const BUCKET_TYPE_SHORTCUTS: Record<keyof typeof BUCKET_TYPES, ShortcutId> = {
  16. files: SHORTCUT_IDS.NAV_STORAGE_FILES,
  17. analytics: SHORTCUT_IDS.NAV_STORAGE_ANALYTICS,
  18. vectors: SHORTCUT_IDS.NAV_STORAGE_VECTORS,
  19. }
  20. export const StorageMenuV2 = () => {
  21. const router = useRouter()
  22. const { ref } = useParams()
  23. const page = useStorageV2Page()
  24. const { storageAnalytics, storageVectors } = useIsFeatureEnabled([
  25. 'storage:analytics',
  26. 'storage:vectors',
  27. ])
  28. const isAnalyticsBucketsEnabled = useIsAnalyticsBucketsEnabled({ projectRef: ref })
  29. const isVectorBucketsEnabled = useIsVectorBucketsEnabled({ projectRef: ref })
  30. const showAnalytics = IS_PLATFORM && storageAnalytics
  31. const showVectors = IS_PLATFORM && storageVectors
  32. useShortcut(SHORTCUT_IDS.NAV_STORAGE_FILES, () => router.push(`/project/${ref}/storage/files`))
  33. useShortcut(
  34. SHORTCUT_IDS.NAV_STORAGE_ANALYTICS,
  35. () => router.push(`/project/${ref}/storage/analytics`),
  36. { enabled: showAnalytics }
  37. )
  38. useShortcut(
  39. SHORTCUT_IDS.NAV_STORAGE_VECTORS,
  40. () => router.push(`/project/${ref}/storage/vectors`),
  41. { enabled: showVectors }
  42. )
  43. useShortcut(SHORTCUT_IDS.NAV_STORAGE_S3, () => router.push(`/project/${ref}/storage/s3`), {
  44. enabled: IS_PLATFORM,
  45. })
  46. const bucketTypes = Object.entries(BUCKET_TYPES).filter(([key]) => {
  47. if (key === 'analytics') return showAnalytics
  48. if (key === 'vectors') return showVectors
  49. return true
  50. })
  51. return (
  52. <Menu type="pills" className="my-2 md:my-4 flex grow flex-col">
  53. <div className="space-y-4">
  54. <div className="md:mx-3">
  55. <Menu.Group title={<span className="uppercase font-mono">Manage</span>} />
  56. {bucketTypes.map(([type, config]) => {
  57. const isSelected = page === type
  58. const isAlphaEnabled =
  59. (type === 'analytics' && isAnalyticsBucketsEnabled) ||
  60. (type === 'vectors' && isVectorBucketsEnabled)
  61. const shortcutId = BUCKET_TYPE_SHORTCUTS[type as keyof typeof BUCKET_TYPES]
  62. const item = (
  63. <Link href={`/project/${ref}/storage/${type}`}>
  64. <Menu.Item rounded active={isSelected}>
  65. <div className="flex items-center justify-between">
  66. <p className="truncate">{config.displayName}</p>
  67. {isAlphaEnabled && <Badge variant="success">New</Badge>}
  68. </div>
  69. </Menu.Item>
  70. </Link>
  71. )
  72. return (
  73. <div key={type}>
  74. {shortcutId ? (
  75. <ShortcutTooltip shortcutId={shortcutId} side="right" delayDuration={1000}>
  76. {item}
  77. </ShortcutTooltip>
  78. ) : (
  79. item
  80. )}
  81. </div>
  82. )
  83. })}
  84. </div>
  85. {IS_PLATFORM && (
  86. <>
  87. <div className="h-px w-[calc(100%-1.5rem)] mx-auto md:w-full bg-border" />
  88. <div className="md:mx-3">
  89. <Menu.Group title={<span className="uppercase font-mono">Configuration</span>} />
  90. <ShortcutTooltip
  91. shortcutId={SHORTCUT_IDS.NAV_STORAGE_S3}
  92. side="right"
  93. delayDuration={1000}
  94. >
  95. <Link href={`/project/${ref}/storage/s3`}>
  96. <Menu.Item rounded active={page === 's3'}>
  97. <p className="truncate">S3</p>
  98. </Menu.Item>
  99. </Link>
  100. </ShortcutTooltip>
  101. </div>
  102. </>
  103. )}
  104. </div>
  105. </Menu>
  106. )
  107. }