refactor(settings): redesign OpenCode settings with shared collapsible sections

- Replace bordered cards with compact flat rows and maintenance sections
- Add shared SettingsDisclosure for config, maintenance, and sandbox sections
- Auto-scroll expanded sections into view when outside the scrollport
- Make agent file editor and agent form full-height and keyboard-aware on mobile
This commit is contained in:
Chris Scott committed 2026-09-19 10:14:34 -04:00
1 parent 295d24ced7
commit 2a4fa956b4
18 files changed
+1013 -742

No files matched your search

@@ -1,7 +1,17 @@
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { describe, it, expect, vi } from 'vitest'
import { SettingsList, SettingsListRow } from './settings-list'
import { DirectoryFilesList } from '@/components/settings/DirectoryFilesList'
vi.mock('@/api/settings', () => ({
settingsApi: {
getOpenCodeDirectoryFile: vi.fn().mockResolvedValue({ content: '# file' }),
updateOpenCodeDirectoryFile: vi.fn().mockResolvedValue(undefined),
deleteOpenCodeDirectoryFile: vi.fn().mockResolvedValue(undefined),
},
}))
describe('SettingsList', () => {
it('renders emptyTitle and emptyHint when isEmpty and no children visible', () => {
@@ -103,4 +113,47 @@ describe('SettingsListRow', () => {
await user.click(deleteItem)
expect(actionClick).toHaveBeenCalledTimes(1)
})
it('keeps primary and overflow actions reachable inside the compact settings scope', async () => {
const user = userEvent.setup()
const primaryClick = vi.fn()
const deleteClick = vi.fn()
render(
<div data-opencode-settings>
<SettingsListRow
title="Row"
primaryAction={{ label: 'Edit', onClick: primaryClick }}
actionsLabel="More options"
actions={[{ label: 'Delete', onClick: deleteClick, destructive: true }]}
/>
</div>,
)
await user.click(screen.getByText('Edit'))
expect(primaryClick).toHaveBeenCalledTimes(1)
await user.click(screen.getByLabelText('More options'))
await user.click(screen.getByText('Delete'))
expect(deleteClick).toHaveBeenCalledTimes(1)
})
})
describe('DirectoryFilesList', () => {
it('labels the raw file editor with the full file path', async () => {
const user = userEvent.setup()
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
render(
<QueryClientProvider client={queryClient}>
<DirectoryFilesList
kind="agents"
files={[{ kind: 'agents', name: 'planner', relativePath: 'team/planner.md' }]}
/>
</QueryClientProvider>,
)
await user.click(screen.getByText('planner'))
expect(await screen.findByRole('textbox', { name: 'team/planner.md' })).toBeInTheDocument()
})
})
+14 -8
View File
@@ -77,7 +77,7 @@ export function SettingsList({
if (isEmpty) {
return (
<div className="h-auto max-h-40 min-h-24 rounded-lg border border-dashed border-border bg-card/50 p-6 text-center text-muted-foreground">
<div className="h-auto max-h-40 min-h-24 rounded-lg border border-dashed border-border bg-card/50 p-6 text-center text-muted-foreground [[data-opencode-settings]_&]:rounded-none [[data-opencode-settings]_&]:border-0 [[data-opencode-settings]_&]:bg-transparent">
<p className="text-sm font-medium text-foreground">{emptyTitle}</p>
<p className="text-xs mt-1">{emptyHint}</p>
</div>
@@ -85,8 +85,8 @@ export function SettingsList({
}
return (
<div className={cn(maxHeightClassName ?? 'max-h-[420px]', 'overflow-y-auto rounded-lg border border-border')}>
<div className="divide-y divide-border">{children}</div>
<div className={cn(maxHeightClassName ?? 'max-h-[420px]', 'overflow-y-auto rounded-lg border border-border [[data-opencode-settings]_&]:rounded-none [[data-opencode-settings]_&]:border-0')}>
<div className="divide-y divide-border [[data-opencode-settings]_&]:divide-y-0">{children}</div>
</div>
)
}
@@ -109,32 +109,38 @@ export function SettingsListRow({
onClick={onClick}
className={cn(
'group flex flex-col gap-2 bg-card px-3 py-3 hover:bg-accent/50 sm:flex-row sm:items-center sm:gap-3',
'[[data-opencode-settings]_&]:flex-row [[data-opencode-settings]_&]:items-center [[data-opencode-settings]_&]:gap-2 [[data-opencode-settings]_&]:bg-transparent [[data-opencode-settings]_&]:px-2 [[data-opencode-settings]_&]:py-2',
onClick && 'cursor-pointer',
className,
)}
>
<div className="min-w-0 flex-1 self-stretch sm:self-auto">
<div className="flex min-w-0 items-start gap-2">
<p className={cn('min-w-0 flex-1 truncate text-sm font-medium', titleClassName)}>{title}</p>
<p className={cn('min-w-0 flex-1 truncate text-sm font-medium [[data-opencode-settings]_&]:whitespace-normal [[data-opencode-settings]_&]:break-words', titleClassName)}>{title}</p>
{badges}
</div>
{description && <div className="mt-1 truncate text-xs text-muted-foreground">{description}</div>}
{description && <div className="mt-1 truncate text-xs text-muted-foreground [[data-opencode-settings]_&]:mt-0.5">{description}</div>}
{belowDescription}
</div>
<div
className="flex w-full shrink-0 items-center justify-end gap-1 sm:w-auto sm:justify-start"
className="flex w-full shrink-0 items-center justify-end gap-1 sm:w-auto sm:justify-start [[data-opencode-settings]_&]:w-auto"
onClick={(e) => e.stopPropagation()}
>
{trailing}
{primaryAction && (
<Button type="button" size="sm" onClick={primaryAction.onClick} className="flex-1 sm:flex-none">
<Button
type="button"
size="sm"
onClick={primaryAction.onClick}
className="flex-1 sm:flex-none [[data-opencode-settings]_&]:max-sm:h-11 [[data-opencode-settings]_&]:flex-none [[data-opencode-settings]_&]:bg-transparent [[data-opencode-settings]_&]:text-foreground [[data-opencode-settings]_&]:hover:bg-accent [[data-opencode-settings]_&]:hover:text-accent-foreground"
>
{primaryAction.label}
</Button>
)}
{actions && actions.length > 0 && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button type="button" variant="ghost" size="icon" className="h-8 w-8" aria-label={actionsLabel}>
<Button type="button" variant="ghost" size="icon" className="h-8 w-8 [[data-opencode-settings]_&]:max-sm:h-11 [[data-opencode-settings]_&]:max-sm:w-11" aria-label={actionsLabel}>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>