Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Pull master and resolve conflicts

Joshen Lim3d387ecfe508
diff --cc studio/components/layouts/AccountLayout/AccountLayout.tsx
index f25924a6652,6e56ab383c3..24dfbbaa732
--- a/studio/components/layouts/AccountLayout/AccountLayout.tsx
+++ b/studio/components/layouts/AccountLayout/AccountLayout.tsx
@@@ -3,20 -2,47 +3,22 @@@ import { FC, ReactNode } from 'react
import { useRouter } from 'next/router'
import { observer } from 'mobx-react-lite'
- import { IS_PLATFORM } from 'lib/constants'
-import { API_URL, IS_PLATFORM } from 'lib/constants'
++import { auth } from 'lib/gotrue'
import { useStore, withAuth, useFlag } from 'hooks'
++import { API_URL, IS_PLATFORM } from 'lib/constants'
import WithSidebar from './WithSidebar'
--import { auth } from 'lib/gotrue'
-import { ReactNode } from 'react'
--
- // Layout for dashboard homepage, account and org settings
-export type SidebarLink = {
- label: string
- href?: string
- key: string
- icon?: string
- external?: boolean
- isActive?: boolean
- subitemsKey?: string
- onClick?: () => Promise<void>
-}
++import { SidebarSection } from './AccountLayout.types'
-export type SidebarSection = {
- key: string
- heading?: string
- versionLabel?: string
- links: SidebarLink[]
-}
-
-type AccountLayoutProps = {
+interface Props {
title: string
- breadcrumbs: Object[]
+ breadcrumbs: {
+ key: string
+ label: string
+ }[]
children: ReactNode
}
-/**
- * layout for dashboard homepage, account and org settings
- *
- * @param {String} title
- * @param {JSX.Element|JSX.Element[]} children
- * @param {Array<Object>} breadcrumbs
- */
-const AccountLayout = ({ children, title, breadcrumbs }: AccountLayoutProps) => {
+const AccountLayout: FC<Props> = ({ children, title, breadcrumbs }) => {
const router = useRouter()
const { app, ui } = useStore()
@@@ -28,91 -54,100 +30,97 @@@
router.reload()
}
- const baseLogoutLink = {
- icon: '/icons/feather/power.svg',
- label: 'Logout',
- href: `${API_URL}/logout`,
- key: `${API_URL}/logout`,
- }
-
- const logoutLink = { ...baseLogoutLink, href: undefined, onClick: onClickLogout }
-
const organizationsLinks = app.organizations
.list()
- .map((x: any) => ({
- key: `${x.slug}-settings`,
- href: `/org/${x.slug}/settings`,
- label: x.name,
- isActive: router.pathname.startsWith('/org/') && ui.selectedOrganization?.slug === x.slug,
+ .map((organization) => ({
+ isActive:
- router.pathname.startsWith('/org/') && ui.selectedOrganization?.slug == organization.slug,
++ router.pathname.startsWith('/org/') && ui.selectedOrganization?.slug === organization.slug,
+ label: organization.name,
+ href: `/org/${organization.slug}/settings`,
+ key: organization.slug,
}))
.sort((a, b) => a.label.localeCompare(b.label))
- const sidebarLinks = [
- let sectionsWithHeaders: SidebarSection[] = [
++ const sectionsWithHeaders: SidebarSection[] = [
{
heading: 'Projects',
+ key: 'projects',
links: [
{
- key: 'all-projects',
- href: '/',
- label: 'All projects',
- isActive: router.pathname == '/',
+ isActive: router.pathname === '/',
+ label: 'All projects',
+ href: '/',
+ key: 'all-projects-item',
},
],
},
- ...(IS_PLATFORM && organizationsLinks.length > 0
- ]
-
- if (IS_PLATFORM) {
- sectionsWithHeaders.push(
- {
- heading: 'Organizations',
- key: 'organizations',
- links: organizationsLinks,
- },
- {
- heading: 'Account',
- key: 'account',
- links: [
++ ...(IS_PLATFORM && organizationsLinks?.length > 0
+ ? [
{
- isActive: router.pathname == `/account/me`,
- icon: '/img/user.svg',
- label: 'Preferences',
- href: `/account/me`,
- key: `/account/me`,
+ heading: 'Organizations',
++ key: 'organizations',
+ links: organizationsLinks,
},
+ ]
+ : []),
+ ...(IS_PLATFORM
+ ? [
{
- isActive: router.pathname == `/account/tokens`,
- icon: '/img/user.svg',
- label: 'Access Tokens',
- href: `/account/tokens`,
- key: `/account/tokens`,
+ heading: 'Account',
++ key: 'account',
+ links: [
+ {
- key: 'account-me',
- href: '/account/me',
++ isActive: router.pathname === `/account/me`,
+ icon: '/img/user.svg',
+ label: 'Preferences',
- isActive: router.pathname === '/account/me',
++ href: `/account/me`,
++ key: `/account/me`,
+ },
+ {
- key: 'account-tokens',
- href: '/account/tokens',
++ isActive: router.pathname === `/account/tokens`,
+ icon: '/img/user.svg',
+ label: 'Access Tokens',
- isActive: router.pathname === '/account/tokens',
++ href: `/account/tokens`,
++ key: `/account/tokens`,
+ },
+ ],
},
- ],
- }
- )
- }
-
- sectionsWithHeaders.push(
+ ]
+ : []),
{
heading: 'Documentation',
+ key: 'documentation',
links: [
{
key: 'ext-guides',
- href: 'https://supabase.com/docs',
icon: '/img/book.svg',
label: 'Guides',
+ href: 'https://supabase.com/docs',
- external: true,
+ isExternal: true,
},
{
key: 'ext-guides',
- href: 'https://supabase.com/docs/guides/api',
icon: '/img/book-open.svg',
label: 'API Reference',
+ href: 'https://supabase.com/docs/guides/api',
- external: true,
+ isExternal: true,
},
],
},
{
- heading: '',
+ key: 'logout-link',
- links: [logoutLink],
- }
- )
+ links: [
+ {
- key: 'logout',
++ key: `logout`,
+ icon: '/icons/feather/power.svg',
+ label: 'Logout',
++ href: undefined,
+ onClick: onClickLogout,
+ },
+ ],
+ },
+ ]
- if (!organizationsLinks?.length)
- sectionsWithHeaders = sectionsWithHeaders.filter((x) => x.heading != 'Organizations')
return (
<>
<Head>
diff --cc studio/components/layouts/AccountLayout/AccountLayout.types.ts
index 89144025c95,00000000000..fa7e6bb3059
mode 100644,000000..100644
--- a/studio/components/layouts/AccountLayout/AccountLayout.types.ts
+++ b/studio/components/layouts/AccountLayout/AccountLayout.types.ts
@@@ -1,15 -1,0 +1,17 @@@
- export interface SidebarLinkGroup {
- heading: string
- links: SidebarLink[]
- }
-
- export interface SidebarLink {
- key: string
++export type SidebarLink = {
+ label: string
- icon?: string
+ href?: string
- subitemsKey?: string // I dont think this is being used at all
- isActive?: boolean
++ key: string
++ icon?: string
+ isExternal?: boolean
- onClick?: () => void
++ isActive?: boolean
++ subitemsKey?: string // I dont think this is being used at all
++ onClick?: () => Promise<void>
++}
++
++export type SidebarSection = {
++ key: string
++ heading?: string
++ versionLabel?: string
++ links: SidebarLink[]
+}
diff --cc studio/components/layouts/AccountLayout/WithSidebar.tsx
index 036844fdbb2,63f15b51d88..b907ada3ff9
--- a/studio/components/layouts/AccountLayout/WithSidebar.tsx
+++ b/studio/components/layouts/AccountLayout/WithSidebar.tsx
@@@ -1,10 -1,10 +1,10 @@@
+ import Link from 'next/link'
import { FC, ReactNode } from 'react'
- import { Menu, Badge } from '@supabase/ui'
-
+ import { isUndefined } from 'lodash'
+ import { Menu, Typography, IconArrowUpRight, Badge, IconLogOut } from '@supabase/ui'
import { useFlag } from 'hooks'
import LayoutHeader from '../ProjectLayout/LayoutHeader'
- import SidebarItem from './SidebarItem'
- import { SidebarLink, SidebarLinkGroup } from './AccountLayout.types'
-import { SidebarLink, SidebarSection } from './AccountLayout'
++import { SidebarLink, SidebarSection } from './AccountLayout.types'
interface Props {
title: string
@@@ -17,7 -17,15 +17,16 @@@
customSidebarContent?: ReactNode
children: ReactNode
}
+
+ /*
+ The information heirarchy for WithSidebar is:
+ WithSidebar
+ SectionsWithHeaders
+ SidebarItem
+ SidebarLink
+ SidebarItem
+ SidebarLink
+ */
const WithSidebar: FC<Props> = ({
title,
header,
@@@ -55,20 -65,24 +66,24 @@@
<div className="-mt-1">
<Menu>
{customSidebarContent}
- {links && linksHaveHeaders ? (
- <LinksWithHeaders
- links={links as SidebarLinkGroup[]}
- subitems={subitems}
- subitemsParentKey={subitemsParentKey}
- />
- ) : null}
- {!linksHaveHeaders && links ? (
- <LinksWithoutHeaders
- links={links as SidebarLink[]}
- subitems={subitems}
- subitemsParentKey={subitemsParentKey}
- />
- ) : null}
+ {sections.map((section, i) => {
+ return Boolean(section.heading) ? (
+ <SectionWithHeaders
+ key={section.key}
+ section={section}
+ subitems={subitems}
+ subitemsParentKey={subitemsParentKey}
+ />
+ ) : (
+ <div className="dark:border-dark border-b py-5 px-6" key={section.key}>
- <SidebarItem
++ <SidebarItem
+ links={section.links}
+ subitems={subitems}
+ subitemsParentKey={subitemsParentKey}
+ />
+ </div>
+ )
+ })}
</Menu>
</div>
</div>
@@@ -106,33 -127,36 +128,36 @@@ interface SidebarItemProps
links: SidebarLink[]
subitems?: any[]
subitemsParentKey?: number
- }> = ({ links, subitems, subitemsParentKey }) => {
+ }
+
+ const SidebarItem: FC<SidebarItemProps> = ({ links, subitems, subitemsParentKey }) => {
return (
<ul className="space-y-1">
- {links.map((x: SidebarLink, i: number) => {
- // Disable active state for link with subitems
- const isActive = x.isActive && !subitems
+ {links.map((link, i: number) => {
+ // disable active state for link with subitems
+ const isActive = link.isActive && !subitems
+
let render: any = (
- <SidebarItem
- key={`${x.key}-${i}-sidebarItem`}
- id={`${x.key}-${i}`}
+ <SidebarLinkItem
+ key={`${link.key}-${i}-sidebarItem`}
+ id={`${link.key}-${i}`}
isActive={isActive}
- label={x.label}
- href={x.href}
- onClick={x.onClick}
- isExternal={x.isExternal || false}
+ label={link.label}
+ href={link.href}
+ onClick={link.onClick}
- external={link.external || false}
++ isExternal={link.isExternal || false}
/>
)
- if (subitems && x.subitemsKey === subitemsParentKey) {
+ if (subitems && link.subitemsKey === subitemsParentKey) {
const subItemsRender = subitems.map((y: any, i: number) => (
- <SidebarItem
+ <SidebarLinkItem
key={`${y.key || y.as}-${i}-sidebarItem`}
id={`${y.key || y.as}-${i}`}
+ isSubitem={true}
label={y.label}
onClick={y.onClick}
- isSubitem={true}
- isExternal={x.isExternal || false}
- external={link.external || false}
++ isExternal={link.isExternal || false}
/>
))
render = [render, ...subItemsRender]
@@@ -143,3 -166,67 +167,67 @@@
</ul>
)
}
+
+ interface SidebarLinkProps extends SidebarLink {
+ id: string
+ isSubitem?: boolean
+ }
+
+ const SidebarLinkItem: FC<SidebarLinkProps> = ({
+ id,
+ label,
+ href,
+ isActive,
+ isSubitem,
++ isExternal,
+ onClick,
- external,
+ }) => {
+ if (isUndefined(href)) {
+ let icon
- if (external) {
++ if (isExternal) {
+ icon = <IconArrowUpRight size={'tiny'} />
+ }
+
+ if (label === 'Logout') {
+ icon = <IconLogOut size={'tiny'} />
+ }
+
+ return (
+ <Menu.Item
+ rounded
+ key={id}
+ style={{
+ marginLeft: isSubitem ? '.5rem' : '0rem',
+ }}
+ active={isActive ? true : false}
+ onClick={onClick || (() => {})}
+ icon={icon}
+ >
+ {isSubitem ? <p className="text-sm">{label}</p> : label}
+ </Menu.Item>
+ )
+ }
+
+ return (
+ <Link href={href || ''}>
- <a className="block" target={external ? '_blank' : '_self'}>
++ <a className="block" target={isExternal ? '_blank' : '_self'}>
+ <button
+ className="ring-scale-1200 border-scale-500 group-hover:border-scale-900 group flex max-w-full cursor-pointer items-center space-x-2 py-1 font-normal outline-none focus-visible:z-10 focus-visible:ring-1"
+ onClick={onClick || (() => {})}
+ >
- {external && (
++ {isExternal && (
+ <span className="text-scale-900 group-hover:text-scale-1100 truncate text-sm transition">
+ <IconArrowUpRight size={'tiny'} />
+ </span>
+ )}
+ <span
+ title={label}
+ className="text-scale-1100 group-hover:text-scale-1200 w-full truncate text-sm transition"
+ >
+ {isSubitem ? <p>{label}</p> : label}
+ </span>
+ </button>
+ </a>
+ </Link>
+ )
+ }