mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
refactor(settings): remove command slash prefix and collapse mobile row actions
- Drop the redundant slash prefix from command and uploaded file names - Move the row primary action into the overflow menu below sm in OpenCode settings - Align titles, badges, switches, and row controls on the first line
This commit is contained in:
1 parent
2a4fa956b4
commit
f175aa73a6
7 files changed
+111
-45
No files matched your search
@@ -61,12 +61,13 @@ describe('CommandsEditor', () => {
|
||||
expect(screen.getByText('Add your first command to get started.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders command names with leading slash', () => {
|
||||
it('renders command names without a leading slash', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByText('/review')).toBeInTheDocument()
|
||||
expect(screen.getByText('/build')).toBeInTheDocument()
|
||||
expect(screen.getByText('review')).toBeInTheDocument()
|
||||
expect(screen.getByText('build')).toBeInTheDocument()
|
||||
expect(screen.queryByText('/review')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders uploaded directory command files', () => {
|
||||
@@ -80,7 +81,7 @@ describe('CommandsEditor', () => {
|
||||
{ wrapper: createWrapper() },
|
||||
)
|
||||
|
||||
expect(screen.getByText('/deploy')).toBeInTheDocument()
|
||||
expect(screen.getByText('deploy')).toBeInTheDocument()
|
||||
expect(screen.getByText('Uploaded file: project/deploy.md')).toBeInTheDocument()
|
||||
expect(screen.getByText('File')).toBeInTheDocument()
|
||||
expect(screen.queryByText('No commands configured')).not.toBeInTheDocument()
|
||||
@@ -103,7 +104,7 @@ describe('CommandsEditor', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
await user.click(screen.getByText('/review'))
|
||||
await user.click(screen.getByText('review'))
|
||||
|
||||
expect(screen.getByTestId('command-dialog')).toBeInTheDocument()
|
||||
})
|
||||
@@ -124,7 +125,7 @@ describe('CommandsEditor', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
await user.click(screen.getByLabelText('Actions for /review'))
|
||||
await user.click(screen.getByLabelText('Actions for review'))
|
||||
await user.click(screen.getByText('Delete'))
|
||||
|
||||
expect(onChange).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -84,7 +84,7 @@ export function CommandsEditor({ commands, directoryCommands = [], onChange }: C
|
||||
{Object.entries(commands).map(([name, command]) => (
|
||||
<SettingsListRow
|
||||
key={name}
|
||||
title={`/${name}`}
|
||||
title={name}
|
||||
description={command.description}
|
||||
badges={
|
||||
command.agent && <Badge variant="outline" className="shrink-0">{command.agent}</Badge>
|
||||
@@ -92,10 +92,10 @@ export function CommandsEditor({ commands, directoryCommands = [], onChange }: C
|
||||
onClick={() => startEdit(name, command)}
|
||||
primaryAction={{ label: 'Edit', onClick: () => startEdit(name, command) }}
|
||||
actions={[{ label: 'Delete', destructive: true, onClick: () => deleteCommand(name) }]}
|
||||
actionsLabel={`Actions for /${name}`}
|
||||
actionsLabel={`Actions for ${name}`}
|
||||
/>
|
||||
))}
|
||||
<DirectoryFilesList kind="commands" files={directoryCommands} titlePrefix="/" />
|
||||
<DirectoryFilesList kind="commands" files={directoryCommands} />
|
||||
</SettingsList>
|
||||
|
||||
<CommandDialog
|
||||
|
||||
@@ -14,10 +14,9 @@ import type { OpenCodeDirectoryFileInfo } from '@/api/types/settings'
|
||||
interface DirectoryFilesListProps {
|
||||
kind: 'agents' | 'commands'
|
||||
files: OpenCodeDirectoryFileInfo[]
|
||||
titlePrefix?: string
|
||||
}
|
||||
|
||||
export function DirectoryFilesList({ kind, files, titlePrefix = '' }: DirectoryFilesListProps) {
|
||||
export function DirectoryFilesList({ kind, files }: DirectoryFilesListProps) {
|
||||
const queryClient = useQueryClient()
|
||||
const [editingFile, setEditingFile] = useState<OpenCodeDirectoryFileInfo | null>(null)
|
||||
const [deletingFile, setDeletingFile] = useState<OpenCodeDirectoryFileInfo | null>(null)
|
||||
@@ -71,7 +70,7 @@ export function DirectoryFilesList({ kind, files, titlePrefix = '' }: DirectoryF
|
||||
return (
|
||||
<SettingsListRow
|
||||
key={`file:${file.relativePath}`}
|
||||
title={<span title={file.relativePath}>{`${titlePrefix}${file.name}`}</span>}
|
||||
title={<span title={file.relativePath}>{file.name}</span>}
|
||||
description={isNested ? `Uploaded file: ${file.relativePath}` : undefined}
|
||||
badges={<Badge variant="secondary" className="shrink-0">File</Badge>}
|
||||
onClick={() => setEditingFile(file)}
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('OpenCodeConfigManager', () => {
|
||||
})
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /Commands/i }))
|
||||
expect(await screen.findByText('/deploy')).toBeInTheDocument()
|
||||
expect(await screen.findByText('deploy')).toBeInTheDocument()
|
||||
expect(screen.getByText('Uploaded file: project/deploy.md')).toBeInTheDocument()
|
||||
|
||||
const agentsButton = screen.getAllByRole('button', { name: /Agents/i }).find(button => button.textContent?.startsWith('Agents'))
|
||||
|
||||
@@ -15,6 +15,7 @@ import { VoiceSettings } from '@/components/settings/VoiceSettings'
|
||||
import { NotificationSettings } from '@/components/settings/NotificationSettings'
|
||||
import { VersionSelectDialog } from '@/components/settings/VersionSelectDialog'
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||
import { RowActionsMenuContext } from '@/components/ui/settings-list'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { Settings2, Keyboard, Code, ChevronLeft, Key, GitBranch, User, Volume2, Bell, X, ScrollText, type LucideIcon } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -28,19 +29,21 @@ function OpenCodeSettings({ onOpenVersionDialog }: { onOpenVersionDialog: () =>
|
||||
const toggleAuthSections = useCallback(() => setAuthSectionsOpen((open) => !open), [])
|
||||
|
||||
return (
|
||||
<div className="group/opencode-settings space-y-4" data-opencode-settings>
|
||||
<ServerHealthStatus onOpenVersionDialog={onOpenVersionDialog} />
|
||||
<OpenCodeConfigManager />
|
||||
<section className="space-y-4 border-t border-border pt-4" aria-label="Server maintenance">
|
||||
<h2 className="text-lg font-semibold">Server maintenance</h2>
|
||||
<div className="grid grid-cols-1 items-start gap-x-6 gap-y-4 @min-[1000px]:grid-cols-2">
|
||||
<OpenCodeServerAuthSettings isOpen={authSectionsOpen} onToggle={toggleAuthSections} />
|
||||
<ManagerTokenSettings isOpen={authSectionsOpen} onToggle={toggleAuthSections} />
|
||||
</div>
|
||||
<ServerEnvVarsSettings />
|
||||
<SandboxSettings />
|
||||
</section>
|
||||
</div>
|
||||
<RowActionsMenuContext.Provider value={true}>
|
||||
<div className="group/opencode-settings space-y-4" data-opencode-settings>
|
||||
<ServerHealthStatus onOpenVersionDialog={onOpenVersionDialog} />
|
||||
<OpenCodeConfigManager />
|
||||
<section className="space-y-4 border-t border-border pt-4" aria-label="Server maintenance">
|
||||
<h2 className="text-lg font-semibold">Server maintenance</h2>
|
||||
<div className="grid grid-cols-1 items-start gap-x-6 gap-y-4 @min-[1000px]:grid-cols-2">
|
||||
<OpenCodeServerAuthSettings isOpen={authSectionsOpen} onToggle={toggleAuthSections} />
|
||||
<ManagerTokenSettings isOpen={authSectionsOpen} onToggle={toggleAuthSections} />
|
||||
</div>
|
||||
<ServerEnvVarsSettings />
|
||||
<SandboxSettings />
|
||||
</section>
|
||||
</div>
|
||||
</RowActionsMenuContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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 { afterEach, describe, it, expect, vi } from 'vitest'
|
||||
import { RowActionsMenuContext, SettingsList, SettingsListRow } from './settings-list'
|
||||
import { DirectoryFilesList } from '@/components/settings/DirectoryFilesList'
|
||||
|
||||
vi.mock('@/api/settings', () => ({
|
||||
@@ -114,20 +114,40 @@ describe('SettingsListRow', () => {
|
||||
expect(actionClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('keeps primary and overflow actions reachable inside the compact settings scope', async () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
const mockViewport = (isDesktop: boolean) => {
|
||||
vi.stubGlobal('matchMedia', (query: string) => ({
|
||||
matches: query === '(min-width: 640px)' ? isDesktop : false,
|
||||
media: query,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
onchange: null,
|
||||
dispatchEvent: vi.fn(),
|
||||
}))
|
||||
}
|
||||
|
||||
it('keeps primary and overflow actions reachable inside the compact settings scope on desktop', async () => {
|
||||
const user = userEvent.setup()
|
||||
const primaryClick = vi.fn()
|
||||
const deleteClick = vi.fn()
|
||||
mockViewport(true)
|
||||
|
||||
render(
|
||||
<div data-opencode-settings>
|
||||
<SettingsListRow
|
||||
title="Row"
|
||||
primaryAction={{ label: 'Edit', onClick: primaryClick }}
|
||||
actionsLabel="More options"
|
||||
actions={[{ label: 'Delete', onClick: deleteClick, destructive: true }]}
|
||||
/>
|
||||
</div>,
|
||||
<RowActionsMenuContext.Provider value={true}>
|
||||
<div data-opencode-settings>
|
||||
<SettingsListRow
|
||||
title="Row"
|
||||
primaryAction={{ label: 'Edit', onClick: primaryClick }}
|
||||
actionsLabel="More options"
|
||||
actions={[{ label: 'Delete', onClick: deleteClick, destructive: true }]}
|
||||
/>
|
||||
</div>
|
||||
</RowActionsMenuContext.Provider>,
|
||||
)
|
||||
|
||||
await user.click(screen.getByText('Edit'))
|
||||
@@ -137,6 +157,36 @@ describe('SettingsListRow', () => {
|
||||
await user.click(screen.getByText('Delete'))
|
||||
expect(deleteClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('collapses the primary action into the overflow menu on mobile settings rows', async () => {
|
||||
const user = userEvent.setup()
|
||||
const primaryClick = vi.fn()
|
||||
const deleteClick = vi.fn()
|
||||
mockViewport(false)
|
||||
|
||||
render(
|
||||
<RowActionsMenuContext.Provider value={true}>
|
||||
<div data-opencode-settings>
|
||||
<SettingsListRow
|
||||
title="Row"
|
||||
primaryAction={{ label: 'Edit', onClick: primaryClick }}
|
||||
actionsLabel="More options"
|
||||
actions={[{ label: 'Delete', onClick: deleteClick, destructive: true }]}
|
||||
/>
|
||||
</div>
|
||||
</RowActionsMenuContext.Provider>,
|
||||
)
|
||||
|
||||
expect(screen.queryByText('Edit')).not.toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByLabelText('More options'))
|
||||
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', () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Fragment, type ReactNode } from 'react'
|
||||
import { createContext, Fragment, useContext, type ReactNode } from 'react'
|
||||
import { MoreHorizontal, Loader2, AlertCircle } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DESKTOP_MEDIA_QUERY, useMediaQuery } from '@/hooks/useMediaQuery'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -10,6 +11,8 @@ import {
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export const RowActionsMenuContext = createContext(false)
|
||||
|
||||
export interface SettingsListRowAction {
|
||||
label: string
|
||||
onClick: () => void
|
||||
@@ -104,18 +107,28 @@ export function SettingsListRow({
|
||||
onClick,
|
||||
className,
|
||||
}: SettingsListRowProps) {
|
||||
const inSettingsScope = useContext(RowActionsMenuContext)
|
||||
const isDesktop = useMediaQuery(DESKTOP_MEDIA_QUERY)
|
||||
const actionsInMenu = inSettingsScope && !isDesktop
|
||||
const overflowActions = primaryAction && actionsInMenu
|
||||
? [
|
||||
{ label: primaryAction.label, onClick: primaryAction.onClick },
|
||||
...(actions ?? []).map((action, index) => (index === 0 ? { ...action, separatorBefore: true } : action)),
|
||||
]
|
||||
: actions
|
||||
|
||||
return (
|
||||
<div
|
||||
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',
|
||||
'[[data-opencode-settings]_&]:flex-row [[data-opencode-settings]_&]:items-start [[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">
|
||||
<div className="min-w-0 flex-1 self-stretch sm:self-auto [[data-opencode-settings]_&]:self-auto">
|
||||
<div className="flex min-w-0 items-start gap-2 [[data-opencode-settings]_&]:items-center [[data-opencode-settings]_&]:max-sm:min-h-11 [[data-opencode-settings]_&]:sm:min-h-8">
|
||||
<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>
|
||||
@@ -127,17 +140,17 @@ export function SettingsListRow({
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{trailing}
|
||||
{primaryAction && (
|
||||
{primaryAction && !actionsInMenu && (
|
||||
<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"
|
||||
className="flex-1 sm:flex-none [[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 && (
|
||||
{overflowActions && overflowActions.length > 0 && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<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}>
|
||||
@@ -145,7 +158,7 @@ export function SettingsListRow({
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{actions.map((action, i) => (
|
||||
{overflowActions.map((action, i) => (
|
||||
<Fragment key={action.label}>
|
||||
{action.separatorBefore && i > 0 && <DropdownMenuSeparator />}
|
||||
<DropdownMenuItem
|
||||
|
||||
Reference in new issue
Block a user