Files
supabase/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx
T
CharisandJoshen Lim 3eb7da7766 feat(preferences): allow disable hotkeys (#39573)
* feat(preferences): allow disable hotkeys

Add a section in /account/me for disabling hotkeys. Only added one
hotkey for now (Cmd + E for toggling editor side panel) but we can add
more with the same pattern.

* refactor: remove default export on ProjectLayout

* feat(hotkeys): allow toggling of command menu and ai assistant hotkeys

* Nit

* PRettier lint

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-10-17 08:09:38 -04:00

76 lines
2.9 KiB
TypeScript

import { useRouter } from 'next/router'
import { ReactNode, useEffect } from 'react'
import { useParams } from 'common'
import { useIsNewStorageUIEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { useSelectedBucket } from 'components/interfaces/Storage/StorageExplorer/useSelectedBucket'
import { StorageMenu } from 'components/interfaces/Storage/StorageMenu'
import { StorageMenuV2 } from 'components/interfaces/Storage/StorageMenuV2'
import { withAuth } from 'hooks/misc/withAuth'
import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
export interface StorageLayoutProps {
title: string
children: ReactNode
}
const StorageLayout = ({ title, children }: StorageLayoutProps) => {
const router = useRouter()
const isStorageV2 = useIsNewStorageUIEnabled()
const { ref, featurePreviewModal, bucketId } = useParams()
const { bucket } = useSelectedBucket()
// [Joshen] Handle redirects between existing UI and feature preview
useEffect(() => {
const { pathname } = router
const suffix = !!featurePreviewModal ? `?featurePreviewModal=${featurePreviewModal}` : ''
if (isStorageV2) {
// From old UI to new UI
if (pathname.endsWith('/storage/settings')) {
router.push(`/project/${ref}/storage/files/settings${suffix}`)
} else if (pathname.endsWith('/storage/policies')) {
router.push(`/project/${ref}/storage/files/policies${suffix}`)
} else if (pathname.endsWith('/storage/buckets/[bucketId]')) {
if (!!bucket && bucket.type === 'STANDARD') {
router.push(`/project/${ref}/storage/files/buckets/${bucketId}${suffix}`)
} else if (!!bucket && bucket.type === 'ANALYTICS') {
router.push(`/project/${ref}/storage/analytics/buckets/${bucketId}${suffix}`)
}
}
} else {
// From new UI to old UI
if (pathname.endsWith('/files/settings')) {
router.push(`/project/${ref}/storage/settings${suffix}`)
} else if (pathname.endsWith('/files/policies')) {
router.push(`/project/${ref}/storage/policies${suffix}`)
} else if (
pathname.endsWith('/files/buckets/[bucketId]') ||
pathname.endsWith('/analytics/buckets/[bucketId]')
) {
router.push(`/project/${ref}/storage/buckets/${bucketId}${suffix}`)
} else if (
pathname.endsWith('/storage/files') ||
pathname.endsWith('/storage/analytics') ||
pathname.endsWith('/storage/vectors')
) {
router.push(`/project/${ref}/storage/buckets`)
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isStorageV2])
return (
<ProjectLayout
stickySidebarBottom={isStorageV2 ? false : true}
title={title || 'Storage'}
product="Storage"
productMenu={isStorageV2 ? <StorageMenuV2 /> : <StorageMenu />}
>
{children}
</ProjectLayout>
)
}
export default withAuth(StorageLayout)