mirror of
https://github.com/supabase/supabase.git
synced 2026-09-11 04:21:47 +08:00
## What kind of change does this PR introduce? Studio UI consistency refactor. ## What is the current behaviour? Several Studio comboboxes still build their triggers from `Button` and supply their own double-chevron icon. This duplicates trigger styling and allows these controls to drift from selects and other comboboxes. ## What is the new behaviour? - Migrates the PITR timezone, AWS region, and account timezone controls to `ComboboxTrigger` - Migrates the shared `SchemaSelector` and `FunctionSelector`, updating their Studio callsites together - Preserves the globe icon in both timezone controls - Exposes the correct combobox role and open state through the shared trigger - Tightens the tiny schema selector end padding so its chevron aligns with adjacent controls - Leaves organisation and project context switchers unchanged | Before | After | | --- | --- | | <img width="504" height="490" alt="CleanShot 2026-09-09 at 13 56 56@2x" src="https://github.com/user-attachments/assets/117a9169-88bf-4f9e-8302-9df9b911a307" /> | <img width="496" height="512" alt="CleanShot 2026-09-09 at 11 31 26@2x" src="https://github.com/user-attachments/assets/bc98cded-2723-4d20-9d8c-49630ea018af" /> | | <img width="1250" height="394" alt="CleanShot 2026-09-09 at 13 58 34@2x" src="https://github.com/user-attachments/assets/9106f924-88fd-40d4-88e3-8d0ddbb61d12" /> | <img width="1246" height="376" alt="CleanShot 2026-09-09 at 13 58 09@2x" src="https://github.com/user-attachments/assets/7894a254-f6f9-40bb-a312-9f1a5079f096" /> | ## To test On the [Studio preview](https://studio-staging-git-dnywh-choremigrate-combobox-680102-supabase.vercel.app): 1. Open **Database > Tables** and use the schema selector above the table. It should use a single down chevron, open normally, and update the selected schema. 2. Open **Authentication > Hooks > Add hook**, then select **Postgres** as the hook type. The **Postgres schema** and **Postgres function** selectors should use a single down chevron and continue to open and select normally. The PITR, AWS region, and account timezone callsites require the relevant plan, integration, or feature flag. When available, their triggers should use the same single down chevron, and both timezone controls should retain the globe icon. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **UI Improvements** * Standardized timezone, AWS region, database backup, function, and schema selectors with a consistent combobox interface. * Added clear visual feedback for open and closed selector states. * Preserved contextual icons and labels, including globe icons for timezone selections. * Improved accessibility with appropriate combobox semantics, accessible names, and state information. * Timezone settings are now available without an optional feature flag. * **Tests** * Updated end-to-end coverage for the standardized combobox controls. * Added coverage confirming schema selectors expose the selected schema as an accessible name. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
114 lines
3.5 KiB
TypeScript
114 lines
3.5 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { mockAnimationsApi } from 'jsdom-testing-mocks'
|
|
import { HttpResponse } from 'msw'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import { SchemaSelector } from './SchemaSelector'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock, APIErrorBody } from '@/tests/lib/msw'
|
|
|
|
mockAnimationsApi()
|
|
|
|
const mockProjectAndSchemas = ({ highAvailability }: { highAvailability: boolean }) => {
|
|
// useSelectedProjectQuery
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref',
|
|
// @ts-expect-error partial project response
|
|
response: {
|
|
cloud_provider: 'localhost',
|
|
id: 1,
|
|
inserted_at: '2021-08-02T06:40:40.646Z',
|
|
name: 'Default Project',
|
|
organization_id: 1,
|
|
ref: 'default',
|
|
region: 'local',
|
|
status: 'ACTIVE_HEALTHY',
|
|
high_availability: highAvailability,
|
|
},
|
|
})
|
|
// useSchemasQuery (schemas list SQL via pg-meta)
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/pg-meta/:ref/query',
|
|
response: () =>
|
|
HttpResponse.json([
|
|
{ id: 1, name: 'public' },
|
|
{ id: 2, name: 'multigres' },
|
|
{ id: 3, name: 'other' },
|
|
]),
|
|
})
|
|
}
|
|
|
|
const mockProjectAndFailingSchemas = () => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref',
|
|
// @ts-expect-error partial project response
|
|
response: {
|
|
cloud_provider: 'localhost',
|
|
id: 1,
|
|
inserted_at: '2021-08-02T06:40:40.646Z',
|
|
name: 'Default Project',
|
|
organization_id: 1,
|
|
ref: 'default',
|
|
region: 'local',
|
|
status: 'ACTIVE_HEALTHY',
|
|
},
|
|
})
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/pg-meta/:ref/query',
|
|
response: () =>
|
|
HttpResponse.json<APIErrorBody>({ message: 'Service unavailable' }, { status: 503 }),
|
|
})
|
|
}
|
|
|
|
const renderAndOpenSelector = async () => {
|
|
customRender(<SchemaSelector selectedSchemaName="public" onSelectSchema={vi.fn()} />)
|
|
|
|
await userEvent.click(await screen.findByTestId('schema-selector'))
|
|
// Wait for the list to be populated before asserting absence
|
|
await screen.findByRole('option', { name: 'public' })
|
|
}
|
|
|
|
describe('SchemaSelector', () => {
|
|
it('gives the combobox an accessible name for the selected schema', async () => {
|
|
mockProjectAndSchemas({ highAvailability: false })
|
|
|
|
customRender(<SchemaSelector selectedSchemaName="public" onSelectSchema={vi.fn()} />)
|
|
|
|
expect(await screen.findByRole('combobox', { name: 'Schema public' })).toBeInTheDocument()
|
|
})
|
|
|
|
it('hides the multigres schema on high availability projects', async () => {
|
|
mockProjectAndSchemas({ highAvailability: true })
|
|
|
|
await renderAndOpenSelector()
|
|
|
|
expect(screen.getByRole('option', { name: 'other' })).toBeInTheDocument()
|
|
expect(screen.queryByRole('option', { name: 'multigres' })).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('shows the multigres schema on non high availability projects', async () => {
|
|
mockProjectAndSchemas({ highAvailability: false })
|
|
|
|
await renderAndOpenSelector()
|
|
|
|
expect(screen.getByRole('option', { name: 'multigres' })).toBeInTheDocument()
|
|
})
|
|
|
|
it('offers to restart the database when schemas fail to load', async () => {
|
|
mockProjectAndFailingSchemas()
|
|
|
|
customRender(<SchemaSelector selectedSchemaName="public" onSelectSchema={vi.fn()} />)
|
|
|
|
await userEvent.click(await screen.findByRole('button', { name: 'Restart database' }))
|
|
|
|
expect(
|
|
await screen.findByText(/are you sure you want to restart your database/i)
|
|
).toBeInTheDocument()
|
|
})
|
|
})
|