Files
Alaister YoungandKevin Grüneberg 70da0f1d1d chore: cleanup packages (#27770)
* chore: cleanup packages

- Avoid circular imports
- Export API-types as types
- pg-format without depending on Node internal Buffer (not browser-compatible)
- Avoid importing from barrel files in ui dir

* chore: avoid barrel file imports in studio (#27771)

* chore: avoid barrel file imports

- Removes some unused imports
- Avoids barrel file import for faster builds + less memory

* add eslint rule

* type fixes

* delete layouts barrel

* delete components/grid barrel file

* delete components/grid/utils barrel file

* delete components/grid/components/common barrel file

* delete components/grid/components/editor barrel file

* delete components/grid/components/formatter barrel file

* delete components/grid/components/grid barrel file

* delete components/grid/components/header/filter barrel file

* remote components/grid/store barrel file

* remove components/interfaces/Auth/Policies barrel file

* delete components/interfaces/Settings/Logs barrel file

* delete components/ui/CodeEditor barrel file

* delete components/ui/Forms barrel file

* delete components/ui/Shimmers barrel file

* delete data/analytics barrel file

* delete hooks barrel file

* cleanup lib/common/fetch barrel file

* final * barral files cleanup

* global react-data-grid styles

* remove console.log

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>

* fix build

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
2024-07-04 14:48:10 +08:00

176 lines
4.8 KiB
TypeScript

import Head from 'next/head'
import { useRouter } from 'next/router'
import { PropsWithChildren, useEffect } from 'react'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { withAuth } from 'hooks/misc/withAuth'
import { useFlag } from 'hooks/ui/useFlag'
import { useSignOut } from 'lib/auth'
import { IS_PLATFORM } from 'lib/constants'
import SettingsLayout from '../SettingsLayout/SettingsLayout'
import type { SidebarSection } from './AccountLayout.types'
import WithSidebar from './WithSidebar'
export interface AccountLayoutProps {
title: string
breadcrumbs: {
key: string
label: string
}[]
}
const AccountLayout = ({ children, title, breadcrumbs }: PropsWithChildren<AccountLayoutProps>) => {
const router = useRouter()
const { data: organizations } = useOrganizationsQuery()
const selectedOrganization = useSelectedOrganization()
const navLayoutV2 = useFlag('navigationLayoutV2')
const signOut = useSignOut()
const onClickLogout = async () => {
await signOut()
await router.push('/sign-in')
}
useEffect(() => {
if (!IS_PLATFORM) {
router.push('/project/default')
}
}, [router])
const organizationsLinks = (organizations ?? [])
.map((organization) => ({
isActive:
router.pathname.startsWith('/org/') && selectedOrganization?.slug === organization.slug,
label: organization.name,
href: `/org/${organization.slug}/general`,
key: organization.slug,
}))
.sort((a, b) => a.label.localeCompare(b.label))
const sectionsWithHeaders: SidebarSection[] = [
{
heading: 'Projects',
key: 'projects',
links: [
{
isActive: router.pathname === '/projects',
label: 'All projects',
href: '/projects',
key: 'all-projects-item',
},
],
},
...(IS_PLATFORM && organizationsLinks?.length > 0
? [
{
heading: 'Organizations',
key: 'organizations',
links: organizationsLinks,
},
]
: []),
...(IS_PLATFORM
? [
{
heading: 'Account',
key: 'account',
links: [
{
isActive: router.pathname === `/account/me`,
icon: `${router.basePath}/img/user.svg`,
label: 'Preferences',
href: `/account/me`,
key: `/account/me`,
},
{
isActive: router.pathname === `/account/tokens`,
icon: `${router.basePath}/img/user.svg`,
label: 'Access Tokens',
href: `/account/tokens`,
key: `/account/tokens`,
},
{
isActive: router.pathname === `/account/security`,
icon: `${router.basePath}/img/user.svg`,
label: 'Security',
href: `/account/security`,
key: `/account/security`,
},
{
isActive: router.pathname === `/account/audit`,
icon: `${router.basePath}/img/user.svg`,
label: 'Audit Logs',
href: `/account/audit`,
key: `/account/audit`,
},
],
},
]
: []),
{
heading: 'Documentation',
key: 'documentation',
links: [
{
key: 'ext-guides',
icon: `${router.basePath}/img/book.svg`,
label: 'Guides',
href: 'https://supabase.com/docs',
isExternal: true,
},
{
key: 'ext-guides',
icon: `${router.basePath}/img/book-open.svg`,
label: 'API Reference',
href: 'https://supabase.com/docs/guides/api',
isExternal: true,
},
],
},
...(IS_PLATFORM
? [
{
key: 'logout-link',
links: [
{
key: `logout`,
icon: '/icons/feather/power.svg',
label: 'Log out',
href: undefined,
onClick: onClickLogout,
},
],
},
]
: []),
]
if (navLayoutV2) {
return <SettingsLayout>{children}</SettingsLayout>
}
return (
<>
<Head>
<title>{title ? `${title} | Supabase` : 'Supabase'}</title>
<meta name="description" content="Supabase Studio" />
</Head>
<div className="h-screen min-h-[0px] basis-0 flex-1">
<WithSidebar
hideSidebar={navLayoutV2}
title={title}
breadcrumbs={breadcrumbs}
sections={sectionsWithHeaders}
>
{children}
</WithSidebar>
</div>
</>
)
}
export default withAuth(AccountLayout)