Skip to content

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

chore(studio): refine Explorer sidebar breadcrumbs (#50188)

Saxon Fletcherd9742d707f51
diff --git a/apps/studio/components/interfaces/Explorer/ExplorerHomeTab.tsx b/apps/studio/components/interfaces/Explorer/ExplorerHomeTab.tsx
index 80da4693f81..5deb147d84c 100644
--- a/apps/studio/components/interfaces/Explorer/ExplorerHomeTab.tsx
+++ b/apps/studio/components/interfaces/Explorer/ExplorerHomeTab.tsx
@@ -1,5 +1,6 @@
import { NotebookText, SquareCode } from 'lucide-react'
import { useState } from 'react'
+import { cn } from 'ui'
import { useCreateChat, useCreateNotebook, useCreateQuery } from './hooks'
import { NOTEBOOK_TEMPLATES } from './templates'
@@ -16,70 +17,77 @@ export const ExplorerHomeTab = () => {
const [value, setValue] = useState<string>('')
return (
- <div className="bg-surface-100 h-full flex flex-col items-center justify-center px-10">
- <div className="w-full max-w-2xl">
- <div className="text-center mb-6">
- <h1 className="heading-section">Run SQL. Chat with your project. Create a Notebook</h1>
- </div>
-
- <AssistantChatForm
- loading={false}
- className="bg"
- placeholder="Explore your data, check project health, create a notebook..."
- value={value}
- onValueChange={(e) => setValue(e.target.value)}
- onSubmit={(message) => createChat({ initialMessage: message })}
- />
- <AssistantAgentHarnessFooter />
-
- <section className="mt-6">
- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
- <ActionCard
- icon={<SquareCode className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
- title="Run SQL"
- description="Write and run an ad-hoc query"
- bgColor="bg-blue-500"
- onClick={() => createQuery()}
- />
- <ActionCard
- icon={<NotebookText className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
- title="Create a notebook"
- description="Combine notes, queries, and results"
- bgColor="bg-blue-500"
- onClick={() => createNotebook()}
- />
+ <div className="flex flex-col h-full">
+ <div
+ className={cn(
+ 'flex-grow min-h-0 overflow-y-auto bg-surface-100 h-full',
+ 'flex flex-col items-center px-10'
+ )}
+ >
+ <div className="w-full max-w-2xl my-auto py-10">
+ <div className="text-center mb-6">
+ <h1 className="heading-section">Run SQL. Chat with your project. Create a Notebook</h1>
</div>
- </section>
- <section className="mt-8 flex flex-col gap-y-3">
- <h2 className="text-sm font-medium text-foreground">Start with a template</h2>
+ <AssistantChatForm
+ loading={false}
+ className="bg"
+ placeholder="Explore your data, check project health, create a notebook..."
+ value={value}
+ onValueChange={(e) => setValue(e.target.value)}
+ onSubmit={(message) => createChat({ initialMessage: message })}
+ />
+ <AssistantAgentHarnessFooter />
- <div className="grid grid-cols-1 gap-3 sm:grid-cols-3">
- {NOTEBOOK_TEMPLATES.map((template) => (
+ <section className="mt-6">
+ <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
<ActionCard
- key={template.title}
- icon={<NotebookText className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
- title={template.title}
- description={template.description}
+ icon={<SquareCode className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
+ title="Run SQL"
+ description="Write and run an ad-hoc query"
bgColor="bg-blue-500"
- onClick={() =>
- createNotebook({ name: template.title, cells: template.buildCells() })
- }
+ onClick={() => createQuery()}
/>
- ))}
- {CHAT_TEMPLATES.map((template) => (
<ActionCard
- key={template.title}
- icon={<template.icon className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
- title={template.title}
+ icon={<NotebookText className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
+ title="Create a notebook"
+ description="Combine notes, queries, and results"
bgColor="bg-blue-500"
- onClick={() =>
- createChat({ name: template.title, initialMessage: template.initialMessage })
- }
+ onClick={() => createNotebook()}
/>
- ))}
- </div>
- </section>
+ </div>
+ </section>
+
+ <section className="mt-8 flex flex-col gap-y-3">
+ <h2 className="text-sm font-medium text-foreground">Start with a template</h2>
+
+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-3">
+ {NOTEBOOK_TEMPLATES.map((template) => (
+ <ActionCard
+ key={template.title}
+ icon={<NotebookText className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
+ title={template.title}
+ description={template.description}
+ bgColor="bg-blue-500"
+ onClick={() =>
+ createNotebook({ name: template.title, cells: template.buildCells() })
+ }
+ />
+ ))}
+ {CHAT_TEMPLATES.map((template) => (
+ <ActionCard
+ key={template.title}
+ icon={<template.icon className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
+ title={template.title}
+ bgColor="bg-blue-500"
+ onClick={() =>
+ createChat({ name: template.title, initialMessage: template.initialMessage })
+ }
+ />
+ ))}
+ </div>
+ </section>
+ </div>
</div>
</div>
)
diff --git a/apps/studio/components/interfaces/Explorer/MarkdownCell.tsx b/apps/studio/components/interfaces/Explorer/MarkdownCell.tsx
index c2629d153bf..42319c09ea4 100644
--- a/apps/studio/components/interfaces/Explorer/MarkdownCell.tsx
+++ b/apps/studio/components/interfaces/Explorer/MarkdownCell.tsx
@@ -55,7 +55,7 @@ export const MarkdownCell = ({ cell, onEdit }: MarkdownCellProps) => {
id={cell._id}
actions={<AddCellDropdown cellId={cell._id} />}
gripDropdownContent={<MoveCellDropdownContent cellId={cell._id} />}
- gripClassName="mt-1.5 opacity-0 group-hover:opacity-100 has-[[data-state=open]]:opacity-100 transition"
+ gripClassName="mt-1.5 sm:opacity-0 group-hover:opacity-100 has-[[data-state=open]]:opacity-100 transition"
>
{isEditing ? (
<div
diff --git a/apps/studio/components/interfaces/Explorer/QueryCell/index.tsx b/apps/studio/components/interfaces/Explorer/QueryCell/index.tsx
index 8dd4120afe2..6a04b126bfb 100644
--- a/apps/studio/components/interfaces/Explorer/QueryCell/index.tsx
+++ b/apps/studio/components/interfaces/Explorer/QueryCell/index.tsx
@@ -114,7 +114,7 @@ export const QueryCell = forwardRef<QueryEditorHandle, QueryCellProps>(function
id={cell._id}
actions={<AddCellDropdown cellId={cell._id} />}
gripDropdownContent={<MoveCellDropdownContent cellId={cell._id} />}
- gripClassName="mt-2 opacity-0 group-hover:opacity-100 has-[[data-state=open]]:opacity-100 transition"
+ gripClassName="mt-2 sm:opacity-0 group-hover:opacity-100 has-[[data-state=open]]:opacity-100 transition"
>
<QueryEditor
ref={ref}
diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerLayout.constants.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerLayout.constants.tsx
index 70bdf43bf6f..9efa4538449 100644
--- a/apps/studio/components/layouts/ExplorerLayout/ExplorerLayout.constants.tsx
+++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerLayout.constants.tsx
@@ -1,12 +1,9 @@
import { motion } from 'framer-motion'
-import { ChevronLeft, MessageSquare, NotebookText, Plus } from 'lucide-react'
+import { MessageSquare, NotebookText } from 'lucide-react'
import { type ComponentType, type PropsWithChildren } from 'react'
-import { Button, cn } from 'ui'
+import { cn } from 'ui'
import { InnerSideBarFilters, InnerSideBarFilterSearchInput } from 'ui-patterns/InnerSideMenu'
-import { useCreateChat, useCreateNotebook } from '@/components/interfaces/Explorer/hooks'
-import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
-
export type ExplorerResourceType = 'notebook' | 'chat'
export const LEVEL_OFFSET = 8
@@ -42,17 +39,13 @@ export const ExplorerNavResourceWrapper = ({
children,
search,
setSearch,
- onBack,
}: PropsWithChildren<{
type: ExplorerResourceType
label?: string
className?: string
search?: string
setSearch: (value: string) => void
- onBack: () => void
}>) => {
- const { createNotebook } = useCreateNotebook()
- const { createChat } = useCreateChat()
const searchPlaceholder = EXPLORER_SECTIONS.find((x) => x.type === type)?.searchPlaceholder
return (
@@ -65,15 +58,7 @@ export const ExplorerNavResourceWrapper = ({
transition={LEVEL_TRANSITION}
className={cn('absolute inset-0 flex flex-col', className)}
>
- <div className="flex items-center gap-2 p-3 pb-2">
- <Button
- size="tiny"
- variant="outline"
- aria-label="Back"
- onClick={onBack}
- className="size-7 shrink-0 px-0"
- icon={<ChevronLeft />}
- />
+ <div className="p-3 pb-2">
<span id="explorer-sidebar-search-label" className="sr-only">
{searchPlaceholder}
</span>
@@ -86,18 +71,6 @@ export const ExplorerNavResourceWrapper = ({
onChange={(event) => setSearch(event.target.value)}
/>
</InnerSideBarFilters>
- <ButtonTooltip
- size="tiny"
- variant="outline"
- aria-label={`New ${type}`}
- className="size-7 shrink-0 px-0"
- icon={<Plus />}
- tooltip={{ content: { side: 'bottom', text: `New ${type}` } }}
- onClick={() => {
- if (type === 'notebook') createNotebook()
- if (type === 'chat') createChat()
- }}
- />
</div>
{children}
</motion.div>
diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerLayout.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerLayout.tsx
index 5414ed312a6..4a77c9e9d5c 100644
--- a/apps/studio/components/layouts/ExplorerLayout/ExplorerLayout.tsx
+++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerLayout.tsx
@@ -17,6 +17,7 @@ import { ProjectLayoutWithAuth } from '../ProjectLayout'
import { EditorTabs } from '../Tabs/Tabs'
import { type ExplorerResourceType } from './ExplorerLayout.constants'
import { ExplorerNavChats } from './ExplorerNavChats'
+import { ExplorerNavHeader } from './ExplorerNavHeader'
import { ExplorerNavHome } from './ExplorerNavHome'
import { ExplorerNavNotebooks } from './ExplorerNavNotebooks'
import { ExplorerNotebookTabCoordinator } from '@/components/interfaces/Explorer/ExplorerNotebookTabCoordinator'
@@ -68,17 +69,19 @@ export const ExplorerLayout = ({ browserTitle, children, title }: ExplorerLayout
<ProjectLayoutWithAuth
product="Explorer"
browserTitle={mergedBrowserTitle}
- productMenuBadge={<BackToSqlEditorButton />}
+ productMenuHeader={
+ <ExplorerNavHeader
+ section={section}
+ onBack={() => setSection(undefined)}
+ rootAction={<BackToSqlEditorButton />}
+ />
+ }
productMenu={
<div className="relative h-full overflow-hidden">
<AnimatePresence mode="wait">
{section === undefined && <ExplorerNavHome key="home" onSelectSection={setSection} />}
- {section === 'notebook' && (
- <ExplorerNavNotebooks key="notebooks" onBack={() => setSection(undefined)} />
- )}
- {section === 'chat' && (
- <ExplorerNavChats key="chats" onBack={() => setSection(undefined)} />
- )}
+ {section === 'notebook' && <ExplorerNavNotebooks key="notebooks" />}
+ {section === 'chat' && <ExplorerNavChats key="chats" />}
</AnimatePresence>
</div>
}
diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavChats.test.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavChats.test.tsx
index 9678159e2cc..a8777fa202e 100644
--- a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavChats.test.tsx
+++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavChats.test.tsx
@@ -52,7 +52,7 @@ vi.mock('@/state/ai-assistant-state', () => ({
describe('ExplorerNavChats', () => {
it('filters support chats, safely sorts rehydrated chats, and marks the route active', () => {
- customRender(<ExplorerNavChats onBack={vi.fn()} />)
+ customRender(<ExplorerNavChats />)
const chatButtons = screen.getAllByRole('button')
expect(chatButtons.map((button) => button.textContent)).toEqual([
diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavChats.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavChats.tsx
index 1c5b84a4448..15e1e76582e 100644
--- a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavChats.tsx
+++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavChats.tsx
@@ -18,7 +18,7 @@ const getVisibleChats = (chats: ChatSession[], search: string): ChatSession[] =>
.sort((a, b) => (b.updatedAt?.getTime() ?? 0) - (a.updatedAt?.getTime() ?? 0))
}
-export const ExplorerNavChats = ({ onBack }: { onBack: () => void }) => {
+export const ExplorerNavChats = () => {
const [search, setSearch] = useState('')
const router = useRouter()
const { id } = useParams()
@@ -28,7 +28,7 @@ export const ExplorerNavChats = ({ onBack }: { onBack: () => void }) => {
const chats = getVisibleChats(chatList, search)
return (
- <ExplorerNavResourceWrapper type="chat" search={search} setSearch={setSearch} onBack={onBack}>
+ <ExplorerNavResourceWrapper type="chat" search={search} setSearch={setSearch}>
<div className="flex flex-1 flex-col gap-px overflow-y-auto px-3 pb-3">
{chats.length === 0 ? (
<p className="px-2 py-2 text-xs text-foreground-lighter">
diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHeader.test.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHeader.test.tsx
new file mode 100644
index 00000000000..6ef1b974d6a
--- /dev/null
+++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHeader.test.tsx
@@ -0,0 +1,85 @@
+import { screen, within } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+import type { ExplorerResourceType } from './ExplorerLayout.constants'
+import { ExplorerNavHeader } from './ExplorerNavHeader'
+import { ProductMenuBar } from '@/components/layouts/Navigation/ProductMenuBar'
+import { customRender } from '@/tests/lib/custom-render'
+
+const createNotebook = vi.fn()
+const createChat = vi.fn()
+vi.mock('@/components/interfaces/Explorer/hooks', () => ({
+ useCreateNotebook: () => ({ createNotebook }),
+ useCreateChat: () => ({ createChat }),
+}))
+
+function renderHeader(section?: ExplorerResourceType) {
+ const onBack = vi.fn()
+ customRender(
+ <ProductMenuBar
+ title="Explorer"
+ header={
+ <ExplorerNavHeader
+ section={section}
+ onBack={onBack}
+ rootAction={<span>Switch to SQL Editor</span>}
+ />
+ }
+ />
+ )
+ return { onBack }
+}
+
+describe('Explorer sidebar header', () => {
+ beforeEach(() => vi.clearAllMocks())
+
+ it('shows the smaller root title with the SQL action', () => {
+ renderHeader()
+ expect(screen.getAllByText('Explorer')).toHaveLength(1)
+ expect(screen.getByText('Explorer')).toHaveClass('text-sm')
+ expect(screen.getByText('Switch to SQL Editor')).toBeInTheDocument()
+ expect(screen.queryByRole('button')).not.toBeInTheDocument()
+ })
+
+ it.each([
+ { section: 'notebook', parent: 'Explorer', current: 'Notebooks' },
+ { section: 'chat', parent: 'Explorer', current: 'Chats' },
+ ] satisfies { section: ExplorerResourceType; parent: string; current: string }[])(
+ 'shows only $parent → $current and returns via the parent breadcrumb',
+ async ({ section, parent, current }) => {
+ const { onBack } = renderHeader(section)
+ const breadcrumb = screen.getByRole('navigation', { name: 'Explorer navigation' })
+ expect(within(breadcrumb).getByRole('button', { name: parent })).toBeInTheDocument()
+ expect(within(breadcrumb).getByRole('link', { name: current })).toHaveAttribute(
+ 'aria-current',
+ 'page'
+ )
+ expect(within(breadcrumb).getAllByRole('listitem')).toHaveLength(2)
+ expect(screen.queryByText('Switch to SQL Editor')).not.toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: 'Back' })).not.toBeInTheDocument()
+ const user = userEvent.setup()
+ await user.click(screen.getByRole('button', { name: parent }))
+ expect(onBack).toHaveBeenCalledOnce()
+ screen.getByRole('button', { name: parent }).focus()
+ await user.keyboard('{Enter}')
+ expect(onBack).toHaveBeenCalledTimes(2)
+ }
+ )
+
+ it.each(['notebook', 'chat'] as const)(
+ 'shows the create action only for the current %s level',
+ async (level) => {
+ renderHeader(level)
+ await userEvent.click(screen.getByRole('button', { name: `New ${level}` }))
+ expect(level === 'notebook' ? createNotebook : createChat).toHaveBeenCalledOnce()
+ expect(level === 'notebook' ? createChat : createNotebook).not.toHaveBeenCalled()
+ }
+ )
+
+ it('keeps the default title and badge for other product sidebars', () => {
+ customRender(<ProductMenuBar title="Database" titleBadge={<span>Preview</span>} />)
+ expect(screen.getByRole('heading', { name: 'Database' })).toHaveClass('text-sm')
+ expect(screen.getByText('Preview')).toBeInTheDocument()
+ })
+})
diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHeader.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHeader.tsx
new file mode 100644
index 00000000000..962bbc99a6f
--- /dev/null
+++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHeader.tsx
@@ -0,0 +1,48 @@
+import { Plus } from 'lucide-react'
+import type { ReactNode } from 'react'
+
+import { EXPLORER_SECTIONS, type ExplorerResourceType } from './ExplorerLayout.constants'
+import { useCreateChat, useCreateNotebook } from '@/components/interfaces/Explorer/hooks'
+import { SidebarBreadcrumb } from '@/components/layouts/Navigation/SidebarBreadcrumb'
+import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
+
+export const ExplorerNavHeader = ({
+ section,
+ onBack,
+ rootAction,
+}: {
+ section: ExplorerResourceType | undefined
+ onBack: () => void
+ rootAction?: ReactNode
+}) => {
+ const label = EXPLORER_SECTIONS.find((entry) => entry.type === section)?.label ?? 'Explorer'
+
+ return (
+ <SidebarBreadcrumb
+ aria-label="Explorer navigation"
+ label={label}
+ parent={section ? { label: 'Explorer', onClick: onBack } : undefined}
+ action={section ? <ExplorerResourceAction type={section} /> : rootAction}
+ />
+ )
+}
+
+const ExplorerResourceAction = ({ type }: { type: ExplorerResourceType }) => {
+ const { createNotebook } = useCreateNotebook()
+ const { createChat } = useCreateChat()
+
+ return (
+ <ButtonTooltip
+ size="tiny"
+ variant="outline"
+ aria-label={`New ${type}`}
+ className="size-7 shrink-0 px-0"
+ icon={<Plus />}
+ tooltip={{ content: { side: 'bottom', text: `New ${type}` } }}
+ onClick={() => {
+ if (type === 'notebook') createNotebook()
+ if (type === 'chat') createChat()
+ }}
+ />
+ )
+}
diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavNotebooks.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavNotebooks.tsx
index b9212107961..e605504e443 100644
--- a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavNotebooks.tsx
+++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavNotebooks.tsx
@@ -45,7 +45,7 @@ const NotebookListItem = ({
)
}
-export const ExplorerNavNotebooks = ({ onBack }: { onBack: () => void }) => {
+export const ExplorerNavNotebooks = () => {
const router = useRouter()
const { ref, id } = useParams()
@@ -74,12 +74,7 @@ export const ExplorerNavNotebooks = ({ onBack }: { onBack: () => void }) => {
const itemProps = useMemo(() => ({ projectRef: ref, activeNotebookId }), [ref, activeNotebookId])
return (
- <ExplorerNavResourceWrapper
- type="notebook"
- search={search}
- setSearch={setSearch}
- onBack={onBack}
- >
+ <ExplorerNavResourceWrapper type="notebook" search={search} setSearch={setSearch}>
<div className="flex flex-1 min-h-0 flex-col px-3 pb-3">
{isPending ? (
<GenericSkeletonLoader />
diff --git a/apps/studio/components/layouts/Navigation/ProductMenuBar.tsx b/apps/studio/components/layouts/Navigation/ProductMenuBar.tsx
index 3c28f74dcc3..bd8c736c9dc 100644
--- a/apps/studio/components/layouts/Navigation/ProductMenuBar.tsx
+++ b/apps/studio/components/layouts/Navigation/ProductMenuBar.tsx
@@ -4,12 +4,20 @@ import { cn } from 'ui'
interface ProductMenuBarProps {
title: string
titleBadge?: ReactNode
+ header?: ReactNode
className?: string
}
+export const ProductMenuBarHeader = ({ children }: PropsWithChildren) => (
+ <div className="border-default flex shrink-0 min-h-(--header-height) items-center gap-2 border-b px-6 justify-between">
+ {children}
+ </div>
+)
+
export const ProductMenuBar = ({
title,
titleBadge,
+ header,
children,
className,
}: PropsWithChildren<ProductMenuBarProps>) => {
@@ -24,10 +32,14 @@ export const ProductMenuBar = ({
'hide-scrollbar bg-dash-sidebar border-default'
)}
>
- <div className="border-default flex min-h-(--header-height) items-center gap-2 border-b px-6 justify-between">
- <h4 className="text-lg truncate min-w-0 flex-1">{title}</h4>
- {titleBadge}
- </div>
+ <ProductMenuBarHeader>
+ {header ?? (
+ <>
+ <h4 className="text-sm truncate min-w-0 flex-1">{title}</h4>
+ {titleBadge}
+ </>
+ )}
+ </ProductMenuBarHeader>
<div className={cn('grow overflow-y-auto', className)}>{children}</div>
</div>
)
diff --git a/apps/studio/components/layouts/Navigation/SidebarBreadcrumb.tsx b/apps/studio/components/layouts/Navigation/SidebarBreadcrumb.tsx
new file mode 100644
index 00000000000..c55c9aacd94
--- /dev/null
+++ b/apps/studio/components/layouts/Navigation/SidebarBreadcrumb.tsx
@@ -0,0 +1,60 @@
+import type { ReactNode } from 'react'
+import {
+ Breadcrumb,
+ BreadcrumbItem,
+ BreadcrumbLink,
+ BreadcrumbList,
+ BreadcrumbPage,
+ BreadcrumbSeparator,
+} from 'ui'
+
+interface SidebarBreadcrumbProps {
+ label: string
+ 'aria-label': string
+ parent?: { label: string; onClick: () => void }
+ action?: ReactNode
+}
+
+export const SidebarBreadcrumb = ({
+ label,
+ 'aria-label': ariaLabel,
+ parent,
+ action,
+}: SidebarBreadcrumbProps) => {
+ return (
+ <>
+ <Breadcrumb aria-label={ariaLabel} className="min-w-0 flex-1">
+ <BreadcrumbList className="flex-nowrap text-sm sm:gap-x-1">
+ {parent && (
+ <>
+ <BreadcrumbItem className="min-w-0 leading-none">
+ <BreadcrumbLink
+ role="button"
+ tabIndex={0}
+ onClick={parent.onClick}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter' || event.key === ' ') {
+ event.preventDefault()
+ parent.onClick()
+ }
+ }}
+ title={parent.label}
+ className="min-w-0 cursor-pointer truncate no-underline focus-ring"
+ >
+ {parent.label}
+ </BreadcrumbLink>
+ </BreadcrumbItem>
+ <BreadcrumbSeparator className="shrink-0" />
+ </>
+ )}
+ <BreadcrumbItem className="min-w-0">
+ <BreadcrumbPage className="truncate text-sm" title={label}>
+ {label}
+ </BreadcrumbPage>
+ </BreadcrumbItem>
+ </BreadcrumbList>
+ </Breadcrumb>
+ {action && <div className="flex shrink-0 items-center">{action}</div>}
+ </>
+ )
+}
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/MobileMenuContent.test.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/MobileMenuContent.test.tsx
new file mode 100644
index 00000000000..dfa9c030c41
--- /dev/null
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/MobileMenuContent.test.tsx
@@ -0,0 +1,115 @@
+import { screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { HttpResponse } from 'msw'
+import { useState } from 'react'
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+import { MobileMenuContent } from './MobileMenuContent'
+import type { ExplorerResourceType } from '@/components/layouts/ExplorerLayout/ExplorerLayout.constants'
+import { ExplorerNavHeader } from '@/components/layouts/ExplorerLayout/ExplorerNavHeader'
+import type { ProjectDetail } from '@/data/projects/project-detail-query'
+import { customRender } from '@/tests/lib/custom-render'
+import { addAPIMock } from '@/tests/lib/msw'
+
+const createNotebook = vi.fn()
+const createChat = vi.fn()
+vi.mock('@/components/interfaces/Explorer/hooks', () => ({
+ useCreateNotebook: () => ({ createNotebook }),
+ useCreateChat: () => ({ createChat }),
+}))
+
+vi.mock('@/components/layouts/Navigation/NavigationBar/NavigationBar.utils', () => ({
+ generateProductRoutes: () => [{ key: 'database', label: 'Database' }],
+ generateSettingsRoutes: () => [],
+ useGenerateOtherRoutes: () => [],
+ useGenerateToolRoutes: () => [],
+}))
+
+vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
+ useIsFeatureEnabled: () => ({}),
+}))
+
+vi.mock('./mobileProductMenuRegistry', () => ({
+ getProductMenuComponent: (key: string) =>
+ key === 'database' ? () => <span>Database menu</span> : null,
+}))
+
+const ExplorerMobileMenu = ({ initialSection }: { initialSection: ExplorerResourceType }) => {
+ const [section, setSection] = useState<ExplorerResourceType | undefined>(initialSection)
+ return (
+ <MobileMenuContent
+ currentProduct="Explorer"
+ currentSectionKey="explorer"
+ currentProductMenu={<span>{section ?? 'Home'} content</span>}
+ currentProductMenuHeader={
+ <ExplorerNavHeader
+ section={section}
+ onBack={() => setSection(undefined)}
+ rootAction={<span>Switch to SQL Editor</span>}
+ />
+ }
+ />
+ )
+}
+
+describe('Mobile product header', () => {
+ beforeEach(() => {
+ vi.clearAllMocks()
+ addAPIMock({
+ method: 'get',
+ path: '/platform/projects/:ref',
+ response: () =>
+ HttpResponse.json<ProjectDetail>({
+ cloud_provider: 'AWS',
+ connectionString: 'postgresql://postgres:password@localhost:5432/postgres',
+ db_host: 'localhost',
+ dbVersion: '15.1.0',
+ high_availability: false,
+ id: 1,
+ inserted_at: '2026-01-01T00:00:00Z',
+ updated_at: '2026-01-01T00:00:00Z',
+ integration_source: null,
+ is_branch_enabled: false,
+ is_physical_backups_enabled: false,
+ name: 'Test project',
+ organization_id: 1,
+ ref: 'default',
+ region: 'us-east-1',
+ restUrl: 'https://default.supabase.co',
+ status: 'ACTIVE_HEALTHY',
+ subscription_id: 'subscription-1',
+ }),
+ })
+ })
+
+ it.each(['notebook', 'chat'] as const)(
+ 'can create a %s and return to Explorer home',
+ async (section) => {
+ const user = userEvent.setup()
+ customRender(<ExplorerMobileMenu initialSection={section} />)
+
+ await user.click(screen.getByRole('button', { name: `New ${section}` }))
+ expect(section === 'notebook' ? createNotebook : createChat).toHaveBeenCalledOnce()
+ expect(section === 'notebook' ? createChat : createNotebook).not.toHaveBeenCalled()
+
+ screen.getByRole('button', { name: 'Explorer' }).focus()
+ await user.keyboard('{Enter}')
+ expect(screen.getByText('Home content')).toBeInTheDocument()
+ expect(screen.getByText('Switch to SQL Editor')).toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: `New ${section}` })).not.toBeInTheDocument()
+ }
+ )
+
+ it('hides the current product header in the top-level menu and other product sections', async () => {
+ const user = userEvent.setup()
+ customRender(<ExplorerMobileMenu initialSection="notebook" />)
+
+ await user.click(screen.getByRole('button', { name: 'Back to menu' }))
+ expect(
+ screen.queryByRole('navigation', { name: 'Explorer navigation' })
+ ).not.toBeInTheDocument()
+ await user.click(screen.getByRole('button', { name: 'Database' }))
+ expect(screen.getByText('Database menu')).toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: 'New notebook' })).not.toBeInTheDocument()
+ })
+})
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/MobileMenuContent.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/MobileMenuContent.tsx
index 30122bf5be7..ef6d311c48d 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/MobileMenuContent.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/MobileMenuContent.tsx
@@ -19,6 +19,7 @@ import {
useGenerateOtherRoutes,
useGenerateToolRoutes,
} from '@/components/layouts/Navigation/NavigationBar/NavigationBar.utils'
+import { ProductMenuBarHeader } from '@/components/layouts/Navigation/ProductMenuBar'
import type { Route } from '@/components/ui/ui.types'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
@@ -26,6 +27,7 @@ import { getPathnameWithoutQuery, getPathSegment } from '@/lib/pathname.utils'
export interface MobileMenuContentProps {
currentProductMenu: React.ReactNode
+ currentProductMenuHeader?: React.ReactNode
currentProduct: string
currentSectionKey: string | null
onCloseSheet?: () => void
@@ -33,6 +35,7 @@ export interface MobileMenuContentProps {
export function MobileMenuContent({
currentProductMenu,
+ currentProductMenuHeader,
currentProduct,
currentSectionKey,
onCloseSheet,
@@ -113,6 +116,8 @@ export function MobileMenuContent({
})
const SectionMenuContent = sectionKeyToShow ? getProductMenuComponent(sectionKeyToShow) : null
+ const hasCurrentProductHeader =
+ viewLevel === 'section' && sectionKeyToShow === currentSectionKey && !!currentProductMenuHeader
const pageSegment = getPathSegment(pathname, 4)
const renderRoute = (route: Route, isActive: boolean) => (
@@ -146,7 +151,15 @@ export function MobileMenuContent({
</Button>
</div>
)}
- <div className="flex-1 overflow-y-auto pb-8 text-sidebar-foreground">
+ {hasCurrentProductHeader && (
+ <ProductMenuBarHeader>{currentProductMenuHeader}</ProductMenuBarHeader>
+ )}
+ <div
+ className={cn(
+ 'flex-1 overflow-y-auto pb-8 text-sidebar-foreground',
+ hasCurrentProductHeader && 'min-h-0 flex flex-col'
+ )}
+ >
{viewLevel === 'top' && (
<nav className="flex flex-col gap-2 p-1" aria-label="Project menu">
<SidebarMenu>
@@ -174,7 +187,7 @@ export function MobileMenuContent({
</nav>
)}
{viewLevel === 'section' && sectionKeyToShow && (
- <div className="p-1">
+ <div className={cn('p-1', hasCurrentProductHeader && 'min-h-0 flex-1 p-0')}>
{sectionKeyToShow === currentSectionKey && currentProductMenu ? (
currentProductMenu
) : SectionMenuContent ? (
diff --git a/apps/studio/components/layouts/ProjectLayout/index.test.tsx b/apps/studio/components/layouts/ProjectLayout/index.test.tsx
index 13090a00efd..8c2f1e165e7 100644
--- a/apps/studio/components/layouts/ProjectLayout/index.test.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/index.test.tsx
@@ -1,10 +1,11 @@
-import { render, screen, waitFor } from '@testing-library/react'
+import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { LOCAL_STORAGE_KEYS } from 'common'
-import type { ReactNode } from 'react'
+import { useState, type ReactNode } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { MobileSheetProvider } from '../Navigation/NavigationBar/MobileSheetContext'
+import { MobileSheetProvider, useMobileSheet } from '../Navigation/NavigationBar/MobileSheetContext'
import { ProjectLayout } from './index'
+import type { MobileMenuContentProps } from './LayoutHeader/MobileMenuContent'
import { STUDIO_PAGE_TITLE_SEPARATOR } from '@/lib/page-title'
const { mockRouter, mockSetSelectedDatabaseId, mockSetMobileMenuOpen } = vi.hoisted(() => ({
@@ -226,6 +227,67 @@ vi.mock('@/state/database-selector', () => ({
}),
}))
+vi.mock('./LayoutHeader/MobileMenuContent', async (importOriginal) => {
+ const actual = await importOriginal<typeof import('./LayoutHeader/MobileMenuContent')>()
+ return {
+ ...actual,
+ MobileMenuContent: ({
+ currentProductMenuHeader,
+ currentProductMenu,
+ }: MobileMenuContentProps) => (
+ <div>
+ {currentProductMenuHeader}
+ {currentProductMenu}
+ </div>
+ ),
+ }
+})
+
+vi.mock('../Navigation/ProductMenuBar', () => ({
+ ProductMenuBar: () => null,
+}))
+
+const MobileSheetHarness = () => {
+ const { content, openMenu, setContent } = useMobileSheet()
+ return (
+ <>
+ <button tabIndex={0} onClick={openMenu}>
+ Open menu
+ </button>
+ <button tabIndex={0} onClick={() => setContent(<span>Other sheet</span>)}>
+ Open other sheet
+ </button>
+ <div data-testid="mobile-sheet">{content}</div>
+ </>
+ )
+}
+
+const ResourceMenuHarness = () => {
+ const [section, setSection] = useState('Explorer')
+ return (
+ <>
+ <button tabIndex={0} onClick={() => setSection('Chats')}>
+ Change section
+ </button>
+ <ProjectLayout
+ product="Explorer"
+ isBlocking={false}
+ productMenuHeader={<span>{section} header</span>}
+ productMenu={
+ <button
+ tabIndex={0}
+ onClick={() => setSection(section === 'Explorer' ? 'Notebooks' : 'Explorer')}
+ >
+ {section === 'Explorer' ? 'Open notebooks' : 'Return to Explorer'}
+ </button>
+ }
+ >
+ <div />
+ </ProjectLayout>
+ </>
+ )
+}
+
const renderLayout = () =>
render(
<MobileSheetProvider>
@@ -261,6 +323,25 @@ describe('ProjectLayout title', () => {
document.title = ''
})
+ it('updates the open mobile menu when resource navigation changes without replacing other sheets', () => {
+ render(
+ <MobileSheetProvider>
+ <ResourceMenuHarness />
+ <MobileSheetHarness />
+ </MobileSheetProvider>
+ )
+ expect(screen.getByTestId('mobile-sheet')).toBeEmptyDOMElement()
+ fireEvent.click(screen.getByRole('button', { name: 'Open menu' }))
+ expect(screen.getByText('Explorer header')).toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Open notebooks' }))
+ expect(screen.getByText('Notebooks header')).toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Return to Explorer' }))
+ expect(screen.getByText('Explorer header')).toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Open other sheet' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Change section' }))
+ expect(screen.getByTestId('mobile-sheet')).toHaveTextContent('Other sheet')
+ })
+
it('sets a composed document title and deduplicates identical section/surface labels', async () => {
render(
<MobileSheetProvider>
diff --git a/apps/studio/components/layouts/ProjectLayout/index.tsx b/apps/studio/components/layouts/ProjectLayout/index.tsx
index d03fe84dd62..764e0f23bce 100644
--- a/apps/studio/components/layouts/ProjectLayout/index.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/index.tsx
@@ -6,8 +6,10 @@ import { useRouter } from 'next/router'
import {
forwardRef,
Fragment,
+ isValidElement,
useEffect,
useLayoutEffect,
+ useRef,
type PropsWithChildren,
type ReactNode,
} from 'react'
@@ -107,6 +109,7 @@ export interface ProjectLayoutProps {
isBlocking?: boolean
product?: string
productMenuBadge?: ReactNode
+ productMenuHeader?: ReactNode
productMenu?: ReactNode
browserTitle?: {
entity?: string
@@ -126,6 +129,7 @@ export const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<Projec
isBlocking = true,
product = '',
productMenuBadge,
+ productMenuHeader,
productMenu,
browserTitle,
children,
@@ -174,7 +178,11 @@ export const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<Projec
)
const { showSidebar } = useAppStateSnapshot()
- const { setContent: setMobileSheetContent, registerOpenMenu } = useMobileSheet()
+ const {
+ content: mobileSheetContent,
+ setContent: setMobileSheetContent,
+ registerOpenMenu,
+ } = useMobileSheet()
const pathname = getPathnameWithoutQuery(router.asPath, router.pathname)
const currentSectionKey = getSectionKeyFromPathname(pathname)
@@ -253,19 +261,36 @@ export const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<Projec
})
}, [addBanner, isExplorerEnabled, isExplorerBannerDismissed, isLocalStorageReady])
+ const mobileSheetContentRef = useRef(mobileSheetContent)
useLayoutEffect(() => {
- const unregister = registerOpenMenu(() => {
- setMobileSheetContent(
- <MobileMenuContent
- currentProductMenu={productMenu ?? null}
- currentProduct={product}
- currentSectionKey={currentSectionKey}
- onCloseSheet={() => setMobileSheetContent(null)}
- />
- )
- })
+ mobileSheetContentRef.current = mobileSheetContent
+ }, [mobileSheetContent])
+
+ useLayoutEffect(() => {
+ const menu = (
+ <MobileMenuContent
+ currentProductMenu={productMenu ?? null}
+ currentProductMenuHeader={productMenuHeader}
+ currentProduct={product}
+ currentSectionKey={currentSectionKey}
+ onCloseSheet={() => setMobileSheetContent(null)}
+ />
+ )
+ const unregister = registerOpenMenu(() => setMobileSheetContent(menu))
+ // Keep resource navigation in an already open sheet in sync with the layout.
+ const currentContent = mobileSheetContentRef.current
+ if (isValidElement(currentContent) && currentContent.type === MobileMenuContent) {
+ setMobileSheetContent(menu)
+ }
return unregister
- }, [registerOpenMenu, productMenu, product, currentSectionKey, setMobileSheetContent])
+ }, [
+ registerOpenMenu,
+ productMenu,
+ productMenuHeader,
+ product,
+ currentSectionKey,
+ setMobileSheetContent,
+ ])
useLayoutEffect(() => {
mainScrollContainer?.scrollTo({ top: 0, left: 0 })
@@ -304,6 +329,7 @@ export const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<Projec
<ProductMenuBar
title={product}
titleBadge={productMenuBadge}
+ header={productMenuHeader}
className={productMenuClassName}
>
{productMenu}