Files
Saxon Fletcher d9742d707f chore(studio): refine Explorer sidebar breadcrumbs (#50188)
Moves Explorer’s back navigation and create actions into a reusable
sidebar breadcrumb header. Reduces product-menu headings globally to
`text-sm` and keeps breadcrumb links free of padding, borders, and
backgrounds.

### How to test

1. Open `/project/<ref>/explorer` and confirm the header shows Explorer
and the SQL Editor switch action.
2. Open Notebooks and Chats. Confirm the header shows `Explorer >
Notebooks/Chats` and the corresponding create action works.
3. Return using the Explorer breadcrumb with a click or Tab + Enter.
Check that the label stays aligned and has no hover background.
4. Open another product, such as Database, and confirm its sidebar
heading uses the smaller font size.

5. At a mobile viewport, open the menu and repeat the notebook/chat
actions and back navigation without closing the sheet. Confirm the
header stays current and disappears when returning to the main menu or
opening another product.

Validation: 18 focused tests, typecheck, formatting, and lint ratchet
passed.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added a shared Explorer sidebar header with breadcrumbs and contextual
actions for creating notebooks and chats.
- Added keyboard-accessible navigation between the Explorer overview and
notebook or chat sections.
- Added support for customized product menu headers across project
layouts.

- **Improvements**
- Centralized Explorer navigation and actions in the shared sidebar
layout.
- Improved mobile menu updates when navigating between Explorer
resources.
- Refined Explorer home layout and drag-handle behavior across screen
sizes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-09-10 15:38:19 +08:00

116 lines
4.3 KiB
TypeScript

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()
})
})