mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
Five layout fixes across Explorer chat, notebooks, and the sidebar. ### Chat - **Conversation fade overlapped the scrollbar.** The top and bottom gradients are positioned against the conversation's padding box, which includes the scroll container's scrollbar gutter, so `inset-x-0` painted them over the scrollbar. They now stop at the conversation's content gutter, which `Conversation` owns for both the content and the fades. - **Composer background bled past the input's radius.** The form paints the surface behind the textarea but had no radius of its own, so its square corners showed outside the `rounded-lg` input. It now shares the radius. - **Message parts used two different widths.** Wide parts come down to `max-w-3xl` so every part shares a column, matching `AssistantQueryCell` and `AssistantNotebookPreview`. `isWide` / `isWideMessagePart` stay in place with both widths equal, so a part can diverge again later without rebuilding the mechanism. ### Notebooks - **Cell controls sat at the container edge.** Each cell centred itself at its own max width while the grip and add-cell button stayed at the far left of the full-width row, leaving a large gap. `SortableSection` takes a `sectionWidth` and carries its control gutter twice — once as the controls, once as padding on the other side — so the section stays centred with its controls immediately beside it. Cell widths are unchanged (prose `48rem`, query `72rem`); set them equal and the two cell types' controls line up on their own. The controls stay in flow rather than floating in an outside gutter, so on a viewport narrower than the cap the row just fills the space instead of clipping the controls into the padding. ### Sidebar - **Search icon didn't line up with the menu row icons.** The row box already sits flush with the search input's box, so rows moved from `pl-3` to `pl-2` to put their icons on the same 8px offset the search icon uses. Spacing between the input and the list now matches the 12px side padding. ### Testing `pnpm --filter studio run typecheck`, Prettier, and 378 tests across `Explorer`, `ProjectHome`, `AIAssistantPanel`, and `ExplorerLayout` pass. ESLint warning counts are unchanged from master. These were reasoned from layout rather than checked in a browser, so they're worth a look on a preview before merge. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **UI Improvements** * Updated Explorer layouts with flexible, configurable widths for notebook and query sections. * Refined navigation spacing and padding across Explorer views. * Centered and standardized AI Assistant preview, query, and message content widths. * Improved chat form styling with rounded corners. * Adjusted conversation spacing and fade overlays to avoid overlapping the scrollbar. * Preserved full-width behavior where appropriate while keeping controls aligned. * **Tests** * Updated layout tests to reflect revised width and alignment behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
190 lines
7.1 KiB
TypeScript
190 lines
7.1 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { HttpResponse } from 'msw'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { AssistantNotebookPreview } from './AssistantNotebookPreview'
|
|
import type { components } from '@/data/api'
|
|
import type { NotebookCellDiffEntry } from '@/data/content/notebooks/notebook-operations'
|
|
import type { AgentCell, CellWire } from '@/data/content/notebooks/notebook-schema'
|
|
import { customRender as render } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
const wireMarkdownCell = (id: string, text: string): CellWire => ({
|
|
_tag: 'markdown_cell',
|
|
_id: id,
|
|
text,
|
|
})
|
|
|
|
const agentMarkdownCell = (text: string): AgentCell => ({ _tag: 'markdown_cell', text })
|
|
|
|
const wireDatabaseCell = (id: string, database_identifier?: string): CellWire => ({
|
|
_tag: 'database_cell',
|
|
_id: id,
|
|
sql: 'select 1',
|
|
row_limit: 100,
|
|
database_identifier,
|
|
})
|
|
|
|
const agentDatabaseCell = (database_identifier?: string): AgentCell => ({
|
|
_tag: 'database_cell',
|
|
sql: 'select 1',
|
|
row_limit: 100,
|
|
database_identifier,
|
|
})
|
|
|
|
describe('AssistantNotebookPreview', () => {
|
|
// The whole safety argument for this feature reduces to this: agent-authored markdown text
|
|
// is rendered as literal source (via CodeBlock), never interpreted into real DOM nodes. A
|
|
// future refactor that swaps in <Markdown> would break this silently.
|
|
it('never renders agent-authored cell content as real img/link/src DOM nodes', async () => {
|
|
const user = userEvent.setup()
|
|
const adversarialText =
|
|
' [y](https://evil.example/) <img src=x onerror=1>'
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'added', cell: agentMarkdownCell(adversarialText), operationIndex: 0 },
|
|
]
|
|
|
|
const { container } = render(<AssistantNotebookPreview entries={entries} mode="update" />)
|
|
await user.click(screen.getByRole('button', { name: 'Added Markdown cell' }))
|
|
|
|
expect(container.querySelectorAll('img')).toHaveLength(0)
|
|
expect(container.querySelectorAll('[href]')).toHaveLength(0)
|
|
expect(container.querySelectorAll('[src]')).toHaveLength(0)
|
|
})
|
|
|
|
it('renders the create-mode header summary', () => {
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'unchanged', cell: wireMarkdownCell('a', 'one') },
|
|
{ _tag: 'unchanged', cell: wireMarkdownCell('b', 'two') },
|
|
]
|
|
|
|
const { container } = render(<AssistantNotebookPreview entries={entries} mode="create" />)
|
|
|
|
expect(screen.getByRole('toolbar', { name: 'Notebook toolbar' })).toBeInTheDocument()
|
|
expect(screen.getByText('2 cells')).toBeInTheDocument()
|
|
expect(screen.getByText('New notebook')).toBeInTheDocument()
|
|
expect(container.firstElementChild).toHaveClass('max-w-3xl')
|
|
})
|
|
|
|
it('surfaces a metadata-only database change after resolving the target', async () => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/databases',
|
|
response: () =>
|
|
HttpResponse.json<components['schemas']['DatabaseDetailResponse_Output'][]>([
|
|
{
|
|
identifier: 'default',
|
|
region: 'us-east-1',
|
|
status: 'ACTIVE_HEALTHY',
|
|
cloud_provider: 'AWS',
|
|
db_host: 'db.default.supabase.co',
|
|
db_name: 'postgres',
|
|
db_port: 5432,
|
|
db_user: 'postgres',
|
|
inserted_at: '2026-01-01T00:00:00.000Z',
|
|
restUrl: 'https://default.supabase.co/rest/v1',
|
|
size: 't4g.micro',
|
|
connectionString: '',
|
|
connection_string_read_only: '',
|
|
},
|
|
{
|
|
identifier: 'default-replica-3',
|
|
region: 'us-east-1',
|
|
status: 'ACTIVE_HEALTHY',
|
|
cloud_provider: 'AWS',
|
|
db_host: 'db.default-replica-3.supabase.co',
|
|
db_name: 'postgres',
|
|
db_port: 5432,
|
|
db_user: 'postgres',
|
|
inserted_at: '2026-01-01T00:00:00.000Z',
|
|
restUrl: 'https://default-replica-3.supabase.co/rest/v1',
|
|
size: 't4g.micro',
|
|
connectionString: '',
|
|
connection_string_read_only: '',
|
|
},
|
|
]),
|
|
})
|
|
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{
|
|
_tag: 'replaced',
|
|
before: wireDatabaseCell('cell-1', 'default'),
|
|
after: agentDatabaseCell('default-replica-3'),
|
|
operationIndex: 0,
|
|
},
|
|
]
|
|
|
|
render(<AssistantNotebookPreview entries={entries} mode="update" />)
|
|
|
|
expect(screen.getByText('Loading database…')).toBeInTheDocument()
|
|
const metadata = await screen.findByText('Database: Primary → Database: Replica')
|
|
expect(metadata).toBeInTheDocument()
|
|
expect(
|
|
screen.getByRole('button', { name: 'Replaced Query: Untitled query' })
|
|
).toHaveTextContent('Database: Primary → Database: Replica')
|
|
})
|
|
|
|
it('hides entries past the limit behind a "Show N more" button', async () => {
|
|
const entries: NotebookCellDiffEntry[] = Array.from({ length: 7 }, (_, index) => ({
|
|
_tag: 'unchanged' as const,
|
|
cell: wireMarkdownCell(`cell-${index}`, `text-${index}`),
|
|
}))
|
|
|
|
render(<AssistantNotebookPreview entries={entries} mode="create" />)
|
|
|
|
expect(screen.getByText('Show 2 more cells')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders run results inside their matching minified notebook cell', () => {
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'unchanged', cell: wireDatabaseCell('cell-1') },
|
|
]
|
|
|
|
const { container } = render(
|
|
<AssistantNotebookPreview
|
|
entries={entries}
|
|
mode="run"
|
|
title="Signup funnel"
|
|
results={{ 'cell-1': { rows: [] } }}
|
|
/>
|
|
)
|
|
|
|
expect(screen.getByText('Signup funnel')).toBeInTheDocument()
|
|
expect(screen.getByText('1 cell')).toBeInTheDocument()
|
|
expect(screen.getByText('Success. No rows returned')).toBeInTheDocument()
|
|
expect(screen.getByText('0 rows')).toBeInTheDocument()
|
|
expect(container.querySelector('[data-slot="explorer-query-results"]')).toBeInTheDocument()
|
|
})
|
|
|
|
it('bases result rendering and layout on supplied results rather than preview mode', () => {
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'unchanged', cell: wireDatabaseCell('cell-1') },
|
|
]
|
|
|
|
const { container } = render(
|
|
<AssistantNotebookPreview
|
|
entries={entries}
|
|
mode="create"
|
|
results={{ 'cell-1': { rows: [{ value: 1 }] } }}
|
|
/>
|
|
)
|
|
|
|
expect(screen.getByText('1 row')).toBeInTheDocument()
|
|
expect(container.querySelector('[data-slot="explorer-query-results"]')).toBeInTheDocument()
|
|
expect(container.querySelector('.flex.flex-col.gap-2')).toBeInTheDocument()
|
|
expect(container.querySelector('.divide-y.divide-border')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('keeps a run preview without results in the grouped cell layout', () => {
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'unchanged', cell: wireDatabaseCell('cell-1') },
|
|
]
|
|
|
|
const { container } = render(<AssistantNotebookPreview entries={entries} mode="run" />)
|
|
|
|
expect(container.querySelector('[data-slot="explorer-query-results"]')).not.toBeInTheDocument()
|
|
expect(container.querySelector('.divide-y.divide-border')).toBeInTheDocument()
|
|
})
|
|
})
|