mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
+8








e273d2b818
## What
- Moves the temporary "Switch to SQL Editor" button out of the Explorer
sidebar header into a footer section ("Looking for snippets?") with a
short explanation and an **Open SQL Editor** button.
- Replaces the header slot with a menu for the Explorer startup
preference (**Start page** / **SQL query**), instead of linking out to
account preferences.
## How to test
1. Enable the Explorer feature preview and open
`/project/<ref>/explorer`.
2. **Header menu:** click the ⋮ button next to the Explorer title. Pick
**SQL query**, then check that **Explorer startup** on `/account/me`
shows the same value (and vice versa).
3. **Footer:** click **Open SQL Editor**. You should land in the SQL
Editor with the **Back to Explorer** button in its title bar.
4. Open **Notebooks** or **Chats** in the sidebar and check that the
menu and footer are hidden there, like the old button was.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Choose whether the Explorer opens to the Start page or SQL query from
the Explorer preferences menu. Your selection is saved and retained when
you reopen the menu.
* Access the SQL Editor from the Explorer’s sidebar footer.
* Explorer preferences are available from the Explorer navigation
header.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Tyler <dshukertjr@gmail.com>
Co-authored-by: Nik Richers <nrichers@gmail.com>
Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Jordi Enric <37541088+jordienr@users.noreply.github.com>
Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
Co-authored-by: Katerina Skroumpelou <mandarini@users.noreply.github.com>
Co-authored-by: Franek <franek@ferly.co.uk>
Co-authored-by: Franek Richardson <franek@supabase.io>
Co-authored-by: Michał Olszewski <35968924+charconstpointer@users.noreply.github.com>
Co-authored-by: Steven Eubank <47563310+smeubank@users.noreply.github.com>
Co-authored-by: Anthony Lio <lionnet.ant@gmail.com>
Co-authored-by: Joey Lei <6957385+leizerbeam@users.noreply.github.com>
Co-authored-by: Ali Waseem <waseema393@gmail.com>
Co-authored-by: Samir Ketema <6003000+samirketema@users.noreply.github.com>
Co-authored-by: K-Dog (Kevin) <k.grueneberg1994@gmail.com>
116 lines
4.3 KiB
TypeScript
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>Explorer preferences</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('Explorer preferences')).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()
|
|
})
|
|
})
|