mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: directory files upload system, deferred restart model, cache invalidation consolidation, and misc improvements (#281)
* feat: show variant label on model picker and add folder upload for agents/commands
- Replace three-dot variant menu trigger with selected variant label
- Add POST /api/settings/opencode-directory-files/install endpoint
- Upload agents/commands markdown folders into .config/opencode/{agents,commands}/
- Reload OpenCode server after upload so files are picked up
* fix: revalidate branch/git caches when mobile sheet opens and on vcs.branch.updated SSE
- add shared invalidateRepoGitCaches() helper for consistent invalidation
- revalidate repo list when mobile repo quick-switch sheet opens
- revalidate current repo when mobile More drawer opens
- revalidate repo/git caches when Source Control dialog opens
- handle vcs.branch.updated SSE event with optimistic cache update
- use helper in branch create/switch mutations in useGit and BranchesTab
* style: make variant selector look more like a button with chevron and compact sizing
* refactor: consolidate settings editors, add folder upload support, and clean up unused code
* refactor: consolidate settings editors, add folder upload support, and clean up unused code
* feat: add opencode-directory-files listing service and consolidate settings editors
* fix: distinguish scroll from tap in suggestion popups on touch devices
* refactor: consolidate settings editors and add DirectoryFilesList component
* refactor: target repo status cache updates only to affected batch entries
* refactor: streamline settings, git hooks, and query invalidation logic
This commit is contained in:
1 parent
e53b4fd32c
commit
617962f2dd
48 files changed
+1522
-293
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { Command } from 'lucide-react'
|
||||
import type { components } from '@/api/opencode-types'
|
||||
import { useTouchTapSelect } from '@/hooks/useTouchTapSelect'
|
||||
|
||||
type CommandType = components['schemas']['Command']
|
||||
|
||||
@@ -22,6 +23,7 @@ export function CommandSuggestions({
|
||||
selectedIndex = 0
|
||||
}: CommandSuggestionsProps) {
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
const touchTapSelect = useTouchTapSelect(onSelect)
|
||||
|
||||
const filteredCommands = commands.filter(command =>
|
||||
command.name.toLowerCase().includes(query.toLowerCase())
|
||||
@@ -66,11 +68,10 @@ export function CommandSuggestions({
|
||||
<button
|
||||
key={command.name}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onTouchEnd={(e) => {
|
||||
e.preventDefault()
|
||||
onSelect(command)
|
||||
}}
|
||||
onClick={() => onSelect(command)}
|
||||
onTouchStart={touchTapSelect.onTouchStart}
|
||||
onTouchMove={touchTapSelect.onTouchMove}
|
||||
onTouchEnd={(e) => touchTapSelect.onTouchEnd(e, command)}
|
||||
onClick={() => touchTapSelect.onClick(command)}
|
||||
className={`w-full px-3 py-2 text-left transition-colors flex items-center gap-2 ${
|
||||
isSelected
|
||||
? 'bg-primary text-primary-foreground'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { Bot, FileText } from 'lucide-react'
|
||||
import { useTouchTapSelect } from '@/hooks/useTouchTapSelect'
|
||||
|
||||
export interface MentionItem {
|
||||
type: 'file' | 'agent'
|
||||
@@ -24,6 +25,7 @@ export function MentionSuggestions({
|
||||
selectedIndex = 0
|
||||
}: MentionSuggestionsProps) {
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
const touchTapSelect = useTouchTapSelect(onSelect)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return
|
||||
@@ -64,11 +66,10 @@ export function MentionSuggestions({
|
||||
<button
|
||||
key={`${item.type}-${item.value}`}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onTouchEnd={(e) => {
|
||||
e.preventDefault()
|
||||
onSelect(item)
|
||||
}}
|
||||
onClick={() => onSelect(item)}
|
||||
onTouchStart={touchTapSelect.onTouchStart}
|
||||
onTouchMove={touchTapSelect.onTouchMove}
|
||||
onTouchEnd={(e) => touchTapSelect.onTouchEnd(e, item)}
|
||||
onClick={() => touchTapSelect.onClick(item)}
|
||||
className={`w-full px-3 py-2 text-left transition-colors flex items-start gap-2 ${
|
||||
idx === selectedIndex
|
||||
? 'bg-primary text-primary-foreground'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useDeferredValue, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Check, ChevronLeft, ChevronRight, Clock, MoreVertical, Search, Star, Trash2, X } from 'lucide-react'
|
||||
import { Check, ChevronDown, ChevronLeft, ChevronRight, Clock, Search, Star, Trash2, X } from 'lucide-react'
|
||||
import { useModelSelection } from '@/hooks/useModelSelection'
|
||||
import { useVariants } from '@/hooks/useVariants'
|
||||
import { formatModelName, formatProviderName, getProviders } from '@/api/providers'
|
||||
@@ -535,6 +535,8 @@ export function ModelQuickSelect({
|
||||
)
|
||||
}
|
||||
|
||||
const selectedVariantLabel = currentVariant ? currentVariant : 'Default'
|
||||
|
||||
const handleMoreModelsBack = () => {
|
||||
if (selectedProviderId) {
|
||||
setSelectedProviderId(null)
|
||||
@@ -608,10 +610,11 @@ export function ModelQuickSelect({
|
||||
<button
|
||||
type="button"
|
||||
disabled={!model && !hasVariants}
|
||||
className="flex h-9 w-9 items-center justify-center rounded-full text-white/70 hover:bg-white/10 disabled:opacity-30"
|
||||
aria-label="Model actions"
|
||||
className="flex h-9 w-24 items-center justify-center gap-1 rounded-md border border-white/10 bg-white/5 px-1.5 text-sm font-medium capitalize text-white/70 hover:bg-white/10 disabled:opacity-30"
|
||||
aria-label={`Current variant: ${selectedVariantLabel}`}
|
||||
>
|
||||
<MoreVertical className="h-4 w-4" />
|
||||
<span className="truncate">{selectedVariantLabel}</span>
|
||||
<ChevronDown className="h-3.5 w-3.5 shrink-0 text-white/40" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="z-[350] min-w-56">
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getRepo } from '@/api/repos'
|
||||
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
|
||||
import { OPENCODE_API_ENDPOINT } from '@/config'
|
||||
import { SideDrawer, SideDrawerContent } from '@/components/ui/side-drawer'
|
||||
import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
|
||||
@@ -51,12 +52,14 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
}
|
||||
}, [isOpen, bind])
|
||||
|
||||
const { data: repo } = useQuery({
|
||||
const { data: repo, refetch: refetchRepo } = useQuery({
|
||||
queryKey: ['repo', repoId],
|
||||
queryFn: () => repoId ? getRepo(repoId) : null,
|
||||
enabled: !!repoId,
|
||||
})
|
||||
|
||||
useRefreshOnOpen(isOpen && repoId != null, () => { void refetchRepo() })
|
||||
|
||||
const currentBranch = repo?.currentBranch || repo?.branch
|
||||
const repoDisplayName = isAssistantRoute || isAssistantSession
|
||||
? 'Assistant'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useMemo } from 'react'
|
||||
import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { BottomSheet, BottomSheetHeader, BottomSheetContent } from '@/components/ui/bottom-sheet'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -30,12 +31,14 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
return match ? Number(match[1]) : null
|
||||
}, [location.pathname])
|
||||
|
||||
const { data: repos, isLoading } = useQuery({
|
||||
const { data: repos, isLoading, refetch } = useQuery({
|
||||
queryKey: ['repos'],
|
||||
queryFn: listRepos,
|
||||
enabled: isOpen,
|
||||
})
|
||||
|
||||
useRefreshOnOpen(isOpen, () => { void refetch() })
|
||||
|
||||
const regularRepos = useMemo(
|
||||
() => repos?.filter((r) => r.id !== ASSISTANT_REPO_ID) ?? null,
|
||||
[repos],
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/u
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { invalidateRepoListCaches } from '@/lib/queryInvalidation'
|
||||
import { getRepoBaseDirectoryName, getRepoDirectoryNameError, getRepoNameFromUrl, normalizeRepoUrlForCompare, sanitizeRepoDirectoryName } from '@opencode-manager/shared/utils'
|
||||
import type { DiscoverReposResponse } from '@opencode-manager/shared/types'
|
||||
import type { Repo } from '@/api/types'
|
||||
@@ -82,8 +83,7 @@ export function AddRepoDialog({ open, onOpenChange }: AddRepoDialogProps) {
|
||||
return { mode: 'single', repo }
|
||||
},
|
||||
onSuccess: (result) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repos'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['reposGitStatus'] })
|
||||
invalidateRepoListCaches(queryClient)
|
||||
setRepoUrl('')
|
||||
setLocalPath('')
|
||||
setFolderPath('')
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
|
||||
import { AlertCircle, GitBranch, Loader2 } from 'lucide-react'
|
||||
import { createRepo, listBranches } from '@/api/repos'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { invalidateRepoGitCaches } from '@/lib/queryInvalidation'
|
||||
|
||||
interface CreateWorktreeDialogProps {
|
||||
open: boolean
|
||||
@@ -66,8 +67,7 @@ export function CreateWorktreeDialog({
|
||||
baseBranch: payload.base,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repos'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['reposGitStatus'] })
|
||||
invalidateRepoGitCaches(queryClient, repoId)
|
||||
showToast.success('Worktree created')
|
||||
onCreated?.()
|
||||
onOpenChange(false)
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
type RepoSortMode,
|
||||
} from "./repo-list-state"
|
||||
import { RepoListControls } from "./RepoListControls"
|
||||
import { invalidateRepoListCaches } from "@/lib/queryInvalidation"
|
||||
import { ASSISTANT_REPO_ID } from "@opencode-manager/shared/utils"
|
||||
|
||||
function formatActivityLabel(timestamp: number): string {
|
||||
@@ -229,8 +230,7 @@ export function RepoList() {
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: deleteRepo,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["repos"] })
|
||||
queryClient.invalidateQueries({ queryKey: ["reposGitStatus"] })
|
||||
invalidateRepoListCaches(queryClient)
|
||||
setDeleteDialogOpen(false)
|
||||
setRepoToDelete(null)
|
||||
},
|
||||
@@ -241,8 +241,7 @@ export function RepoList() {
|
||||
await Promise.all(repoIds.map((id) => deleteRepo(id)))
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["repos"] })
|
||||
queryClient.invalidateQueries({ queryKey: ["reposGitStatus"] })
|
||||
invalidateRepoListCaches(queryClient)
|
||||
setDeleteDialogOpen(false)
|
||||
setSelectedRepos(new Set())
|
||||
setSelectionMode(false)
|
||||
@@ -270,8 +269,7 @@ export function RepoList() {
|
||||
queryClient.setQueryData(["repos"], context?.previousRepos)
|
||||
},
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["repos"] })
|
||||
queryClient.invalidateQueries({ queryKey: ["reposGitStatus"] })
|
||||
invalidateRepoListCaches(queryClient)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { AgentsEditor } from './AgentsEditor'
|
||||
|
||||
vi.mock('./AgentDialog', () => ({
|
||||
@@ -8,6 +9,13 @@ vi.mock('./AgentDialog', () => ({
|
||||
open ? <div data-testid="agent-dialog">{editingAgent ? 'Edit Agent' : 'Create Agent'}</div> : null,
|
||||
}))
|
||||
|
||||
const createWrapper = () => {
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
||||
return ({ children }: { children: React.ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
const mockAgents = {
|
||||
'code-reviewer': {
|
||||
description: 'Reviews code changes',
|
||||
@@ -27,7 +35,7 @@ describe('AgentsEditor', () => {
|
||||
|
||||
it('renders empty state when no agents configured', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<AgentsEditor agents={{}} onChange={onChange} />)
|
||||
render(<AgentsEditor agents={{}} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByText('No agents configured')).toBeInTheDocument()
|
||||
expect(screen.getByText('Add your first agent to get started.')).toBeInTheDocument()
|
||||
@@ -35,16 +43,33 @@ describe('AgentsEditor', () => {
|
||||
|
||||
it('renders agent names', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />)
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByText('code-reviewer')).toBeInTheDocument()
|
||||
expect(screen.getByText('helper')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders uploaded directory agent files', () => {
|
||||
const onChange = vi.fn()
|
||||
render(
|
||||
<AgentsEditor
|
||||
agents={{}}
|
||||
directoryAgents={[{ kind: 'agents', name: 'planner', relativePath: 'team/planner.md' }]}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
{ wrapper: createWrapper() },
|
||||
)
|
||||
|
||||
expect(screen.getByText('planner')).toBeInTheDocument()
|
||||
expect(screen.getByText('Uploaded file: team/planner.md')).toBeInTheDocument()
|
||||
expect(screen.getByText('File')).toBeInTheDocument()
|
||||
expect(screen.queryByText('No agents configured')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens AgentDialog when clicking Edit on a row', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />)
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
const editButtons = screen.getAllByText('Edit')
|
||||
await user.click(editButtons[0])
|
||||
@@ -56,7 +81,7 @@ describe('AgentsEditor', () => {
|
||||
it('opens AgentDialog when clicking row body', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />)
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
await user.click(screen.getByText('code-reviewer'))
|
||||
|
||||
@@ -66,7 +91,7 @@ describe('AgentsEditor', () => {
|
||||
it('opens AgentDialog and displays Create Agent text when clicking Add Agent button', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(<AgentsEditor agents={{}} onChange={onChange} />)
|
||||
render(<AgentsEditor agents={{}} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
await user.click(screen.getByText('Add Agent'))
|
||||
|
||||
@@ -77,7 +102,7 @@ describe('AgentsEditor', () => {
|
||||
it('calls onChange with agent removed when Delete is clicked from overflow menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />)
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
await user.click(screen.getByLabelText('Actions for code-reviewer'))
|
||||
await user.click(screen.getByText('Delete'))
|
||||
@@ -88,7 +113,7 @@ describe('AgentsEditor', () => {
|
||||
|
||||
it('renders mode and disabled badges for agents', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />)
|
||||
render(<AgentsEditor agents={mockAgents} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByText('subagent')).toBeInTheDocument()
|
||||
expect(screen.getByText('Disabled')).toBeInTheDocument()
|
||||
|
||||
@@ -5,6 +5,9 @@ import { Badge } from '@/components/ui/badge'
|
||||
import { Dialog, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { SettingsList, SettingsListRow } from '@/components/ui/settings-list'
|
||||
import { AgentDialog } from './AgentDialog'
|
||||
import { UploadFolderButton } from './UploadFolderButton'
|
||||
import { DirectoryFilesList } from './DirectoryFilesList'
|
||||
import type { OpenCodeDirectoryFileInfo } from '@/api/types/settings'
|
||||
|
||||
interface Agent {
|
||||
prompt?: string
|
||||
@@ -26,12 +29,14 @@ interface Agent {
|
||||
|
||||
interface AgentsEditorProps {
|
||||
agents: Record<string, Agent>
|
||||
directoryAgents?: OpenCodeDirectoryFileInfo[]
|
||||
onChange: (agents: Record<string, Agent>) => void
|
||||
}
|
||||
|
||||
export function AgentsEditor({ agents, onChange }: AgentsEditorProps) {
|
||||
export function AgentsEditor({ agents, directoryAgents = [], onChange }: AgentsEditorProps) {
|
||||
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false)
|
||||
const [editingAgent, setEditingAgent] = useState<{ name: string; agent: Agent } | null>(null)
|
||||
const hasAgents = Object.keys(agents).length > 0 || directoryAgents.length > 0
|
||||
|
||||
const handleAgentSubmit = (name: string, agent: Agent) => {
|
||||
if (editingAgent) {
|
||||
@@ -62,7 +67,8 @@ export function AgentsEditor({ agents, onChange }: AgentsEditorProps) {
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-end">
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<UploadFolderButton kind="agents" />
|
||||
<Dialog open={isCreateDialogOpen} onOpenChange={setIsCreateDialogOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button size="sm">
|
||||
@@ -79,7 +85,7 @@ export function AgentsEditor({ agents, onChange }: AgentsEditorProps) {
|
||||
</div>
|
||||
|
||||
<SettingsList
|
||||
isEmpty={Object.keys(agents).length === 0}
|
||||
isEmpty={!hasAgents}
|
||||
emptyTitle="No agents configured"
|
||||
emptyHint="Add your first agent to get started."
|
||||
maxHeightClassName="max-h-[calc(100dvh-300px)] sm:max-h-[420px]"
|
||||
@@ -101,6 +107,7 @@ export function AgentsEditor({ agents, onChange }: AgentsEditorProps) {
|
||||
actionsLabel={`Actions for ${name}`}
|
||||
/>
|
||||
))}
|
||||
<DirectoryFilesList kind="agents" files={directoryAgents} />
|
||||
</SettingsList>
|
||||
|
||||
<AgentDialog
|
||||
|
||||
@@ -1,13 +1,40 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { CommandsEditor } from './CommandsEditor'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
installOpenCodeDirectoryFiles: vi.fn(),
|
||||
toastError: vi.fn(),
|
||||
toastSuccess: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('./CommandDialog', () => ({
|
||||
CommandDialog: ({ open, editingCommand }: { open: boolean; editingCommand?: { name: string } | null }) =>
|
||||
open ? <div data-testid="command-dialog">{editingCommand ? 'Edit Command' : 'Create Command'}</div> : null,
|
||||
}))
|
||||
|
||||
vi.mock('@/api/settings', () => ({
|
||||
settingsApi: {
|
||||
installOpenCodeDirectoryFiles: mocks.installOpenCodeDirectoryFiles,
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('sonner', () => ({
|
||||
toast: {
|
||||
error: mocks.toastError,
|
||||
success: mocks.toastSuccess,
|
||||
},
|
||||
}))
|
||||
|
||||
const createWrapper = () => {
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
||||
return ({ children }: { children: React.ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
const mockCommands = {
|
||||
'review': {
|
||||
template: 'Review this code',
|
||||
@@ -23,11 +50,12 @@ const mockCommands = {
|
||||
describe('CommandsEditor', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.installOpenCodeDirectoryFiles.mockResolvedValue({ kind: 'commands', filesInstalled: ['git/commit.md'] })
|
||||
})
|
||||
|
||||
it('renders empty state when no commands configured', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={{}} onChange={onChange} />)
|
||||
render(<CommandsEditor commands={{}} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByText('No commands configured')).toBeInTheDocument()
|
||||
expect(screen.getByText('Add your first command to get started.')).toBeInTheDocument()
|
||||
@@ -35,16 +63,33 @@ describe('CommandsEditor', () => {
|
||||
|
||||
it('renders command names with leading slash', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />)
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByText('/review')).toBeInTheDocument()
|
||||
expect(screen.getByText('/build')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders uploaded directory command files', () => {
|
||||
const onChange = vi.fn()
|
||||
render(
|
||||
<CommandsEditor
|
||||
commands={{}}
|
||||
directoryCommands={[{ kind: 'commands', name: 'deploy', relativePath: 'project/deploy.md' }]}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
{ wrapper: createWrapper() },
|
||||
)
|
||||
|
||||
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()
|
||||
})
|
||||
|
||||
it('opens CommandDialog when clicking Edit on a row', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />)
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
const editButtons = screen.getAllByText('Edit')
|
||||
await user.click(editButtons[0])
|
||||
@@ -56,7 +101,7 @@ describe('CommandsEditor', () => {
|
||||
it('opens CommandDialog when clicking row body', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />)
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
await user.click(screen.getByText('/review'))
|
||||
|
||||
@@ -66,7 +111,7 @@ describe('CommandsEditor', () => {
|
||||
it('opens CommandDialog and displays Create Command text when clicking Add Command button', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={{}} onChange={onChange} />)
|
||||
render(<CommandsEditor commands={{}} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
await user.click(screen.getByText('Add Command'))
|
||||
|
||||
@@ -77,7 +122,7 @@ describe('CommandsEditor', () => {
|
||||
it('calls onChange with command removed when Delete is clicked from overflow menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />)
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
await user.click(screen.getByLabelText('Actions for /review'))
|
||||
await user.click(screen.getByText('Delete'))
|
||||
@@ -88,8 +133,40 @@ describe('CommandsEditor', () => {
|
||||
|
||||
it('renders agent badge when command has agent', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />)
|
||||
render(<CommandsEditor commands={mockCommands} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByText('code-reviewer')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('uploads only markdown files from a selected commands folder', async () => {
|
||||
const onChange = vi.fn()
|
||||
const markdownFile = new File(['commit body'], 'commit.md', { type: 'text/markdown' })
|
||||
const systemFile = new File(['metadata'], '.DS_Store')
|
||||
Object.defineProperty(markdownFile, 'webkitRelativePath', { value: 'commands/git/commit.md' })
|
||||
Object.defineProperty(systemFile, 'webkitRelativePath', { value: 'commands/.DS_Store' })
|
||||
|
||||
const { container } = render(<CommandsEditor commands={{}} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
const input = container.querySelector('input[type="file"]') as HTMLInputElement
|
||||
|
||||
fireEvent.change(input, { target: { files: [markdownFile, systemFile] } })
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mocks.installOpenCodeDirectoryFiles).toHaveBeenCalledWith({ kind: 'commands', files: [markdownFile] })
|
||||
})
|
||||
expect(mocks.toastSuccess).toHaveBeenCalledWith('Uploaded 1 command file')
|
||||
})
|
||||
|
||||
it('shows an error when a selected commands folder has no markdown files', async () => {
|
||||
const onChange = vi.fn()
|
||||
const systemFile = new File(['metadata'], '.DS_Store')
|
||||
Object.defineProperty(systemFile, 'webkitRelativePath', { value: 'commands/.DS_Store' })
|
||||
|
||||
const { container } = render(<CommandsEditor commands={{}} onChange={onChange} />, { wrapper: createWrapper() })
|
||||
const input = container.querySelector('input[type="file"]') as HTMLInputElement
|
||||
|
||||
fireEvent.change(input, { target: { files: [systemFile] } })
|
||||
|
||||
expect(mocks.installOpenCodeDirectoryFiles).not.toHaveBeenCalled()
|
||||
expect(mocks.toastError).toHaveBeenCalledWith('No markdown commands files found')
|
||||
})
|
||||
})
|
||||
@@ -5,6 +5,9 @@ import { Badge } from '@/components/ui/badge'
|
||||
import { Dialog, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { SettingsList, SettingsListRow } from '@/components/ui/settings-list'
|
||||
import { CommandDialog } from './CommandDialog'
|
||||
import { UploadFolderButton } from './UploadFolderButton'
|
||||
import { DirectoryFilesList } from './DirectoryFilesList'
|
||||
import type { OpenCodeDirectoryFileInfo } from '@/api/types/settings'
|
||||
|
||||
interface Command {
|
||||
template: string
|
||||
@@ -17,12 +20,14 @@ interface Command {
|
||||
|
||||
interface CommandsEditorProps {
|
||||
commands: Record<string, Command>
|
||||
directoryCommands?: OpenCodeDirectoryFileInfo[]
|
||||
onChange: (commands: Record<string, Command>) => void
|
||||
}
|
||||
|
||||
export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
export function CommandsEditor({ commands, directoryCommands = [], onChange }: CommandsEditorProps) {
|
||||
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false)
|
||||
const [editingCommand, setEditingCommand] = useState<{ name: string; command: Command } | null>(null)
|
||||
const hasCommands = Object.keys(commands).length > 0 || directoryCommands.length > 0
|
||||
|
||||
const handleCommandSubmit = (name: string, command: Command) => {
|
||||
if (editingCommand) {
|
||||
@@ -53,7 +58,8 @@ export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-end">
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<UploadFolderButton kind="commands" />
|
||||
<Dialog open={isCreateDialogOpen} onOpenChange={setIsCreateDialogOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button size="sm">
|
||||
@@ -70,7 +76,7 @@ export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
</div>
|
||||
|
||||
<SettingsList
|
||||
isEmpty={Object.keys(commands).length === 0}
|
||||
isEmpty={!hasCommands}
|
||||
emptyTitle="No commands configured"
|
||||
emptyHint="Add your first command to get started."
|
||||
maxHeightClassName="max-h-[calc(100dvh-300px)] sm:max-h-[420px]"
|
||||
@@ -89,6 +95,7 @@ export function CommandsEditor({ commands, onChange }: CommandsEditorProps) {
|
||||
actionsLabel={`Actions for /${name}`}
|
||||
/>
|
||||
))}
|
||||
<DirectoryFilesList kind="commands" files={directoryCommands} titlePrefix="/" />
|
||||
</SettingsList>
|
||||
|
||||
<CommandDialog
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import { useState } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { SettingsListRow } from '@/components/ui/settings-list'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import { invalidateConfigCaches } from '@/lib/queryInvalidation'
|
||||
import type { OpenCodeDirectoryFileInfo } from '@/api/types/settings'
|
||||
|
||||
interface DirectoryFilesListProps {
|
||||
kind: 'agents' | 'commands'
|
||||
files: OpenCodeDirectoryFileInfo[]
|
||||
titlePrefix?: string
|
||||
}
|
||||
|
||||
export function DirectoryFilesList({ kind, files, titlePrefix = '' }: DirectoryFilesListProps) {
|
||||
const queryClient = useQueryClient()
|
||||
const [editingFile, setEditingFile] = useState<OpenCodeDirectoryFileInfo | null>(null)
|
||||
const [deletingFile, setDeletingFile] = useState<OpenCodeDirectoryFileInfo | null>(null)
|
||||
const [content, setContent] = useState('')
|
||||
|
||||
const { isFetching: isLoadingContent } = useQuery({
|
||||
queryKey: ['opencode-directory-file', kind, editingFile?.relativePath],
|
||||
queryFn: async () => {
|
||||
const result = await settingsApi.getOpenCodeDirectoryFile(kind, editingFile!.relativePath)
|
||||
setContent(result.content)
|
||||
return result
|
||||
},
|
||||
enabled: !!editingFile,
|
||||
staleTime: 0,
|
||||
gcTime: 0,
|
||||
})
|
||||
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
settingsApi.updateOpenCodeDirectoryFile({
|
||||
kind,
|
||||
relativePath: editingFile!.relativePath,
|
||||
content,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
invalidateConfigCaches(queryClient)
|
||||
toast.success('File saved')
|
||||
setEditingFile(null)
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error instanceof Error ? error.message : 'Failed to save file')
|
||||
},
|
||||
})
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: () => settingsApi.deleteOpenCodeDirectoryFile(kind, deletingFile!.relativePath),
|
||||
onSuccess: () => {
|
||||
invalidateConfigCaches(queryClient)
|
||||
toast.success('File deleted')
|
||||
setDeletingFile(null)
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error instanceof Error ? error.message : 'Failed to delete file')
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
{files.map((file) => (
|
||||
<SettingsListRow
|
||||
key={`file:${file.relativePath}`}
|
||||
title={`${titlePrefix}${file.name}`}
|
||||
description={`Uploaded file: ${file.relativePath}`}
|
||||
badges={<Badge variant="secondary" className="shrink-0">File</Badge>}
|
||||
onClick={() => setEditingFile(file)}
|
||||
primaryAction={{ label: 'Edit', onClick: () => setEditingFile(file) }}
|
||||
actions={[{ label: 'Delete', destructive: true, onClick: () => setDeletingFile(file) }]}
|
||||
actionsLabel={`Actions for ${file.name}`}
|
||||
/>
|
||||
))}
|
||||
|
||||
<Dialog open={!!editingFile} onOpenChange={(open) => !open && setEditingFile(null)}>
|
||||
<DialogContent mobileFullscreen className="sm:max-w-2xl sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6 pb-safe">
|
||||
<DialogHeader className="p-4 sm:p-6 border-b">
|
||||
<DialogTitle className="truncate">{editingFile?.relativePath}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-2 sm:p-4">
|
||||
<Textarea
|
||||
value={content}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
disabled={isLoadingContent}
|
||||
rows={18}
|
||||
className="font-mono md:text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="flex flex-row gap-2 pt-2 border-t border-border sm:justify-end pb-4 p-3">
|
||||
<Button variant="outline" onClick={() => setEditingFile(null)} className="flex-1 sm:flex-none">
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => updateMutation.mutate()}
|
||||
disabled={isLoadingContent || updateMutation.isPending}
|
||||
className="flex-1 sm:flex-none"
|
||||
>
|
||||
{updateMutation.isPending ? 'Saving...' : 'Save'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<DeleteDialog
|
||||
open={!!deletingFile}
|
||||
onOpenChange={(open) => !open && setDeletingFile(null)}
|
||||
onConfirm={() => deleteMutation.mutate()}
|
||||
onCancel={() => setDeletingFile(null)}
|
||||
title="Delete File"
|
||||
description="Are you sure you want to delete this uploaded file?"
|
||||
itemName={deletingFile?.relativePath}
|
||||
isDeleting={deleteMutation.isPending}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach, beforeAll } from 'vitest'
|
||||
import { act, render, screen } from '@testing-library/react'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { OpenCodeConfigManager } from './OpenCodeConfigManager'
|
||||
@@ -11,16 +11,20 @@ const {
|
||||
mockRestartOpenCodeServer,
|
||||
mockGetOpenCodeImportStatus,
|
||||
mockListManagedSkills,
|
||||
mockListOpenCodeDirectoryFiles,
|
||||
healthState,
|
||||
} = vi.hoisted(() => ({
|
||||
mockGetOpenCodeConfigs: vi.fn(),
|
||||
mockUpdateOpenCodeConfig: vi.fn(),
|
||||
mockRestartOpenCodeServer: vi.fn(),
|
||||
mockGetOpenCodeImportStatus: vi.fn(),
|
||||
mockListManagedSkills: vi.fn(),
|
||||
mockListOpenCodeDirectoryFiles: vi.fn(),
|
||||
healthState: { data: { opencode: 'healthy', opencodeRestartPending: false } as Record<string, unknown> },
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useServerHealth', () => ({
|
||||
useServerHealth: () => ({ data: { opencode: 'healthy' } }),
|
||||
useServerHealth: () => healthState,
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/toast', () => ({
|
||||
@@ -34,6 +38,7 @@ vi.mock('@/api/settings', () => ({
|
||||
restartOpenCodeServer: mockRestartOpenCodeServer,
|
||||
getOpenCodeImportStatus: mockGetOpenCodeImportStatus,
|
||||
listManagedSkills: mockListManagedSkills,
|
||||
listOpenCodeDirectoryFiles: mockListOpenCodeDirectoryFiles,
|
||||
syncOpenCodeImport: vi.fn(),
|
||||
upgradeOpenCode: vi.fn(),
|
||||
},
|
||||
@@ -70,18 +75,45 @@ describe('OpenCodeConfigManager', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
healthState.data = { opencode: 'healthy', opencodeRestartPending: false }
|
||||
mockGetOpenCodeConfigs.mockResolvedValue({ configs: [defaultConfig] })
|
||||
mockGetOpenCodeImportStatus.mockResolvedValue({})
|
||||
mockListManagedSkills.mockResolvedValue([])
|
||||
mockListOpenCodeDirectoryFiles.mockImplementation((kind: 'agents' | 'commands') => {
|
||||
if (kind === 'commands') return Promise.resolve([])
|
||||
return Promise.resolve([])
|
||||
})
|
||||
mockUpdateOpenCodeConfig.mockResolvedValue(defaultConfig)
|
||||
mockRestartOpenCodeServer.mockResolvedValue({ success: true, message: 'ok' })
|
||||
})
|
||||
|
||||
it('optimistic delete + restart prompt', async () => {
|
||||
let resolveUpdate: (config: OpenCodeConfig) => void = () => {}
|
||||
mockUpdateOpenCodeConfig.mockImplementationOnce(() => new Promise<OpenCodeConfig>((resolve) => {
|
||||
resolveUpdate = resolve
|
||||
}))
|
||||
it('shows uploaded command and agent directory files in settings', async () => {
|
||||
mockListOpenCodeDirectoryFiles.mockImplementation((kind: 'agents' | 'commands') => {
|
||||
if (kind === 'commands') return Promise.resolve([{ kind, name: 'deploy', relativePath: 'project/deploy.md' }])
|
||||
return Promise.resolve([{ kind, name: 'planner', relativePath: 'team/planner.md' }])
|
||||
})
|
||||
|
||||
const user = userEvent.setup()
|
||||
renderWithQuery(<OpenCodeConfigManager hideHealthStatus />)
|
||||
|
||||
await screen.findByText('Commands')
|
||||
await vi.waitFor(() => {
|
||||
expect(screen.getAllByText('1 configured').length).toBeGreaterThanOrEqual(2)
|
||||
})
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /Commands/i }))
|
||||
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'))
|
||||
expect(agentsButton).toBeDefined()
|
||||
await user.click(agentsButton!)
|
||||
expect(await screen.findByText('planner')).toBeInTheDocument()
|
||||
expect(screen.getByText('Uploaded file: team/planner.md')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('optimistic delete saves without eager restart modal', async () => {
|
||||
mockUpdateOpenCodeConfig.mockResolvedValueOnce({ ...defaultConfig, restartRequired: true })
|
||||
|
||||
const user = userEvent.setup()
|
||||
renderWithQuery(<OpenCodeConfigManager hideHealthStatus />)
|
||||
@@ -98,17 +130,19 @@ describe('OpenCodeConfigManager', () => {
|
||||
expect(configName).toBe('default')
|
||||
expect(payload.content.provider.openai.models).not.toHaveProperty('gpt-4o')
|
||||
|
||||
expect(screen.queryByText('Restart OpenCode Server?')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('deferred restart banner triggers server restart', async () => {
|
||||
healthState.data = { opencode: 'healthy', opencodeRestartPending: true }
|
||||
|
||||
const user = userEvent.setup()
|
||||
renderWithQuery(<OpenCodeConfigManager hideHealthStatus />)
|
||||
|
||||
const restartNowButton = await screen.findByRole('button', { name: /restart now/i })
|
||||
await user.click(restartNowButton)
|
||||
|
||||
await screen.findByText('Restart OpenCode Server?')
|
||||
expect(screen.getByRole('button', { name: /saving/i })).toBeDisabled()
|
||||
|
||||
await act(async () => {
|
||||
resolveUpdate(defaultConfig)
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(screen.getByRole('button', { name: /restart now/i })).not.toBeDisabled()
|
||||
})
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /restart now/i }))
|
||||
|
||||
expect(mockRestartOpenCodeServer).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Loader2, Plus, Trash2, Edit, Download, RotateCcw, FileText, ArrowUpCircle, History, ChevronDown } from 'lucide-react'
|
||||
import { Loader2, Plus, Trash2, Edit, Download, RotateCcw, FileText, ArrowUpCircle, History, ChevronDown, AlertTriangle } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Label } from '@/components/ui/label'
|
||||
@@ -58,6 +58,8 @@ interface OpenCodeConfigManagerProps {
|
||||
hideHealthStatus?: boolean
|
||||
}
|
||||
|
||||
const EXPANDED_SECTION_CONTENT_CLASS = 'p-2 sm:p-4'
|
||||
|
||||
export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConfigManagerProps) {
|
||||
const queryClient = useQueryClient()
|
||||
const { data: health } = useServerHealth()
|
||||
@@ -100,11 +102,23 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
const { data: directoryCommands = [] } = useQuery({
|
||||
queryKey: ['opencode-directory-files', 'commands'],
|
||||
queryFn: () => settingsApi.listOpenCodeDirectoryFiles('commands'),
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
const { data: directoryAgents = [] } = useQuery({
|
||||
queryKey: ['opencode-directory-files', 'agents'],
|
||||
queryFn: () => settingsApi.listOpenCodeDirectoryFiles('agents'),
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
const scrollToSection = (ref: React.RefObject<HTMLButtonElement | null>) => {
|
||||
if (ref.current) {
|
||||
ref.current.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'start',
|
||||
block: 'nearest',
|
||||
inline: 'nearest'
|
||||
})
|
||||
}
|
||||
@@ -238,7 +252,6 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
const previousConfig = configs.find(c => c.name === configName)
|
||||
const previousContent = previousConfig?.content
|
||||
const previousSelectedConfig = selectedConfig
|
||||
const shouldPromptRestart = Boolean(previousConfig?.isDefault)
|
||||
const now = Date.now()
|
||||
|
||||
setConfigs(prev => prev.map(config =>
|
||||
@@ -247,15 +260,14 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
if (selectedConfig && selectedConfig.name === configName) {
|
||||
setSelectedConfig({ ...selectedConfig, content: newContent, updatedAt: now })
|
||||
}
|
||||
if (shouldPromptRestart) {
|
||||
setIsRestartPromptOpen(true)
|
||||
}
|
||||
|
||||
try {
|
||||
setIsUpdating(true)
|
||||
const result = await settingsApi.updateOpenCodeConfig(configName, { content: newContent })
|
||||
if (result.removedFields && result.removedFields.length > 0) {
|
||||
showToast.info(`Configuration updated after removing invalid fields: ${result.removedFields.join(', ')}`)
|
||||
} else if (result.restartRequired) {
|
||||
showToast.success('Configuration saved. Restart the server to apply changes.')
|
||||
} else {
|
||||
showToast.success('Configuration updated')
|
||||
}
|
||||
@@ -267,9 +279,6 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
if (previousSelectedConfig && previousSelectedConfig.name === configName) {
|
||||
setSelectedConfig(previousSelectedConfig)
|
||||
}
|
||||
if (shouldPromptRestart) {
|
||||
setIsRestartPromptOpen(false)
|
||||
}
|
||||
console.error('Failed to update config:', error)
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to update config'))
|
||||
} finally {
|
||||
@@ -413,7 +422,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
const activeConfig = configs.find((c) => c.name === activeConfigName) ?? null
|
||||
|
||||
return (
|
||||
<div className="space-y-6 overflow-y-auto">
|
||||
<div className="space-y-6 min-w-0">
|
||||
{!hideHealthStatus && health && (
|
||||
<Card className={cn('bg-transparent border-transparent', isUnhealthy && 'border-destructive')}>
|
||||
<CardContent className="p-3">
|
||||
@@ -500,6 +509,30 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{health?.opencodeRestartPending && (
|
||||
<div className="flex flex-col gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertTriangle className="h-4 w-4 shrink-0 text-amber-500" />
|
||||
<p className="text-sm">
|
||||
Configuration changes are saved but require a server restart to take effect.
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => setIsRestartPromptOpen(true)}
|
||||
disabled={restartServerMutation.isPending}
|
||||
className="shrink-0"
|
||||
>
|
||||
{restartServerMutation.isPending ? (
|
||||
<Loader2 className="h-3 w-3 mr-1 animate-spin" />
|
||||
) : (
|
||||
<RotateCcw className="h-3 w-3 mr-1" />
|
||||
)}
|
||||
Restart Now
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||
@@ -745,10 +778,10 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
if (!editingConfig) return
|
||||
showToast.loading('Saving configuration...', { id: 'edit-config' })
|
||||
try {
|
||||
await settingsApi.updateOpenCodeConfig(editingConfig.name, { content: rawContent })
|
||||
const result = await settingsApi.updateOpenCodeConfig(editingConfig.name, { content: rawContent })
|
||||
await fetchConfigs()
|
||||
const successMsg = editingConfig.isDefault
|
||||
? 'Configuration saved and server reloaded'
|
||||
const successMsg = result.restartRequired
|
||||
? 'Configuration saved. Restart the server to apply changes.'
|
||||
: 'Configuration saved'
|
||||
showToast.success(successMsg, { id: 'edit-config' })
|
||||
invalidateConfigCaches(queryClient)
|
||||
@@ -817,7 +850,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4 pb-20 min-w-0">
|
||||
<div className="flex flex-col gap-4 pb-4 min-w-0">
|
||||
{selectedConfig ? (
|
||||
<>
|
||||
{!selectedConfig.isValid && selectedConfig.validationIssues && selectedConfig.validationIssues.length > 0 && (
|
||||
@@ -856,15 +889,16 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">Commands</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{Object.keys((selectedConfig.content?.command as Record<string, Command> | undefined) ?? {}).length} configured
|
||||
{Object.keys((selectedConfig.content?.command as Record<string, Command> | undefined) ?? {}).length + directoryCommands.length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.commands ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.commands ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<CommandsEditor
|
||||
commands={(selectedConfig.content?.command as Record<string, Command> | undefined) ?? {}}
|
||||
directoryCommands={directoryCommands}
|
||||
onChange={(commands) => {
|
||||
const updatedContent = {
|
||||
...selectedConfig.content,
|
||||
@@ -893,15 +927,16 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">Agents</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{Object.keys((selectedConfig.content?.agent as Record<string, Agent> | undefined) ?? {}).length} configured
|
||||
{Object.keys((selectedConfig.content?.agent as Record<string, Agent> | undefined) ?? {}).length + directoryAgents.length} configured
|
||||
</span>
|
||||
</div>
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.agents ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.agents ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<AgentsEditor
|
||||
agents={(selectedConfig.content?.agent as Record<string, Agent> | undefined) ?? {}}
|
||||
directoryAgents={directoryAgents}
|
||||
onChange={(agents) => {
|
||||
const updatedContent = {
|
||||
...selectedConfig.content,
|
||||
@@ -935,7 +970,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.skills ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.skills ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<SkillsEditor
|
||||
managedSkills={managedSkills}
|
||||
/>
|
||||
@@ -965,7 +1000,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.mcp ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.mcp ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<McpManager
|
||||
config={selectedConfig}
|
||||
onUpdate={(content) => updateConfigContent(selectedConfig.name, content)}
|
||||
@@ -1004,7 +1039,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.models ? 'rotate-90' : ''}`} />
|
||||
</button>
|
||||
<div className={`${expandedSections.models ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<OpenCodeModelsEditor
|
||||
providers={(selectedConfig.content?.provider as Record<string, ConfigProvider> | undefined) ?? {}}
|
||||
onChange={(providers) => {
|
||||
@@ -1045,7 +1080,6 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<RestartServerDialog
|
||||
open={isRestartPromptOpen}
|
||||
onOpenChange={setIsRestartPromptOpen}
|
||||
isSaving={isUpdating && !restartServerMutation.isPending}
|
||||
isRestarting={restartServerMutation.isPending}
|
||||
onCancel={() => setIsRestartPromptOpen(false)}
|
||||
onConfirm={async () => {
|
||||
|
||||
@@ -52,14 +52,6 @@ describe('RestartServerDialog', () => {
|
||||
expect(screen.getByText('Restarting...')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('disables confirm button and shows Saving... when isSaving is true', () => {
|
||||
render(<RestartServerDialog {...baseProps} isSaving={true} />)
|
||||
|
||||
const confirmButton = screen.getByRole('button', { name: /saving/i })
|
||||
expect(confirmButton).toBeDisabled()
|
||||
expect(screen.getByText('Saving...')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('disables Later button when isRestarting is true', () => {
|
||||
render(<RestartServerDialog {...baseProps} isRestarting={true} />)
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ interface RestartServerDialogProps {
|
||||
onOpenChange: (open: boolean) => void
|
||||
onConfirm: () => void
|
||||
onCancel: () => void
|
||||
isSaving?: boolean
|
||||
isRestarting?: boolean
|
||||
}
|
||||
|
||||
@@ -16,10 +15,9 @@ export function RestartServerDialog({
|
||||
onOpenChange,
|
||||
onConfirm,
|
||||
onCancel,
|
||||
isSaving = false,
|
||||
isRestarting = false,
|
||||
}: RestartServerDialogProps) {
|
||||
const isConfirmDisabled = isSaving || isRestarting
|
||||
const isConfirmDisabled = isRestarting
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
@@ -35,12 +33,7 @@ export function RestartServerDialog({
|
||||
Later
|
||||
</Button>
|
||||
<Button onClick={onConfirm} disabled={isConfirmDisabled}>
|
||||
{isSaving ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-1 animate-spin" />
|
||||
Saving...
|
||||
</>
|
||||
) : isRestarting ? (
|
||||
{isRestarting ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-1 animate-spin" />
|
||||
Restarting...
|
||||
|
||||
@@ -153,7 +153,7 @@ export function SettingsDialog() {
|
||||
</TabsList>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
<div className="flex-1 min-h-0 overflow-y-auto">
|
||||
<div className="px-6 pb-6">
|
||||
<TabsContent key="account" value="account" className="mt-0"><AccountSettings /></TabsContent>
|
||||
<TabsContent key="general" value="general" className="mt-0"><GeneralSettings /></TabsContent>
|
||||
@@ -205,7 +205,7 @@ export function SettingsDialog() {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-h-0 overflow-y-auto p-3 pb-20">
|
||||
<div className="flex-1 min-h-0 overflow-y-auto p-3 pb-[calc(env(safe-area-inset-bottom)+1rem)]">
|
||||
{mobileView === 'menu' && (
|
||||
<div className="space-y-3">
|
||||
{menuItems.map((item) => (
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import { useRef, useState } from 'react'
|
||||
import { Upload, FileUp, FolderUp, ChevronDown } from 'lucide-react'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import { invalidateConfigCaches } from '@/lib/queryInvalidation'
|
||||
|
||||
const KIND_NOUN: Record<'agents' | 'commands', string> = {
|
||||
agents: 'agent',
|
||||
commands: 'command',
|
||||
}
|
||||
|
||||
const DIRECTORY_INPUT_PROPS = {
|
||||
webkitdirectory: '',
|
||||
directory: '',
|
||||
mozdirectory: '',
|
||||
} as React.InputHTMLAttributes<HTMLInputElement>
|
||||
|
||||
function isMarkdownFile(file: File): boolean {
|
||||
return (file.webkitRelativePath || file.name).toLowerCase().endsWith('.md')
|
||||
}
|
||||
|
||||
interface UploadFolderButtonProps {
|
||||
kind: 'agents' | 'commands'
|
||||
}
|
||||
|
||||
export function UploadFolderButton({ kind }: UploadFolderButtonProps) {
|
||||
const queryClient = useQueryClient()
|
||||
const [isUploading, setIsUploading] = useState(false)
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
const folderInputRef = useRef<HTMLInputElement>(null)
|
||||
const noun = KIND_NOUN[kind]
|
||||
|
||||
const openPicker = (inputRef: React.RefObject<HTMLInputElement | null>) => {
|
||||
requestAnimationFrame(() => inputRef.current?.click())
|
||||
}
|
||||
|
||||
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const selectedFiles = Array.from(event.target.files ?? [])
|
||||
event.target.value = ''
|
||||
if (selectedFiles.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const files = selectedFiles.filter(isMarkdownFile)
|
||||
if (files.length === 0) {
|
||||
toast.error(`No markdown ${kind} files found`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
setIsUploading(true)
|
||||
const result = await settingsApi.installOpenCodeDirectoryFiles({ kind, files })
|
||||
invalidateConfigCaches(queryClient)
|
||||
toast.success(`Uploaded ${result.filesInstalled.length} ${noun} file${result.filesInstalled.length === 1 ? '' : 's'}`)
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : `Failed to upload ${kind}`)
|
||||
} finally {
|
||||
setIsUploading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button size="sm" variant="outline" disabled={isUploading}>
|
||||
<Upload className="h-4 w-4 mr-1" />
|
||||
{isUploading ? 'Uploading...' : 'Upload'}
|
||||
<ChevronDown className="h-4 w-4 ml-1" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onSelect={() => openPicker(fileInputRef)}>
|
||||
<FileUp className="h-4 w-4 mr-2" />
|
||||
Upload File
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => openPicker(folderInputRef)}>
|
||||
<FolderUp className="h-4 w-4 mr-2" />
|
||||
Upload Folder
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".md,text/markdown"
|
||||
className="sr-only"
|
||||
multiple
|
||||
disabled={isUploading}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
<input
|
||||
ref={folderInputRef}
|
||||
type="file"
|
||||
accept=".md,text/markdown"
|
||||
className="sr-only"
|
||||
multiple
|
||||
disabled={isUploading}
|
||||
{...DIRECTORY_INPUT_PROPS}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { listBranches, switchBranch, GitAuthError, getRepo } from '@/api/repos'
|
||||
import { useGitStatus } from '@/api/git'
|
||||
import { fetchGitStatus, useGitStatus } from '@/api/git'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Loader2, GitBranch, GitBranchPlus, Check, Plus, AlertCircle, ArrowUp, ArrowDown, Globe } from 'lucide-react'
|
||||
@@ -10,6 +10,7 @@ import { showToast } from '@/lib/toast'
|
||||
import { useGit } from '@/hooks/useGit'
|
||||
import { GIT_UI_COLORS } from '@/lib/git-status-styles'
|
||||
import { CreateWorktreeDialog } from '@/components/repo/CreateWorktreeDialog'
|
||||
import { invalidateRepoGitCaches, setRepoGitStatusCaches } from '@/lib/queryInvalidation'
|
||||
|
||||
interface BranchesTabProps {
|
||||
repoId: number
|
||||
@@ -41,12 +42,15 @@ export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) {
|
||||
const isRepoWorktree = repo?.isWorktree ?? false
|
||||
|
||||
const switchBranchMutation = useMutation({
|
||||
mutationFn: (branch: string) => switchBranch(repoId, branch),
|
||||
onSuccess: (updatedRepo) => {
|
||||
mutationFn: async (branch: string) => {
|
||||
const updatedRepo = await switchBranch(repoId, branch)
|
||||
const status = await fetchGitStatus(repoId)
|
||||
return { updatedRepo, status }
|
||||
},
|
||||
onSuccess: ({ updatedRepo, status }) => {
|
||||
queryClient.setQueryData(['repo', repoId], updatedRepo)
|
||||
queryClient.invalidateQueries({ queryKey: ['repos'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['reposGitStatus'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['gitStatus', repoId] })
|
||||
setRepoGitStatusCaches(queryClient, repoId, status)
|
||||
invalidateRepoGitCaches(queryClient, repoId, { invalidateStatus: false })
|
||||
refetch()
|
||||
showToast.success(`Switched to branch: ${updatedRepo.currentBranch}`)
|
||||
},
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { FetchError } from '@opencode-manager/shared'
|
||||
import { useGitStatus, getApiErrorMessage } from '@/api/git'
|
||||
import { getRepo } from '@/api/repos'
|
||||
|
||||
import { useGit } from '@/hooks/useGit'
|
||||
import { ChangesTab } from './ChangesTab'
|
||||
@@ -26,6 +28,8 @@ import {
|
||||
} from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { invalidateRepoGitCaches } from '@/lib/queryInvalidation'
|
||||
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
|
||||
|
||||
interface SourceControlPanelProps {
|
||||
repoId: number
|
||||
@@ -51,8 +55,17 @@ export function SourceControlPanel({
|
||||
const [selectedCommit, setSelectedCommit] = useState<string | undefined>()
|
||||
const [selectedCommitFile, setSelectedCommitFile] = useState<string | undefined>()
|
||||
const [gitError, setGitError] = useState<{ summary: string; detail?: string } | null>(null)
|
||||
const queryClient = useQueryClient()
|
||||
const { data: status } = useGitStatus(repoId)
|
||||
const { data: repo } = useQuery({
|
||||
queryKey: ['repo', repoId],
|
||||
queryFn: () => getRepo(repoId),
|
||||
enabled: isOpen,
|
||||
})
|
||||
const isMobile = useMobile()
|
||||
const displayBranch = repo?.currentBranch || repo?.branch || currentBranch
|
||||
|
||||
useRefreshOnOpen(isOpen, () => { invalidateRepoGitCaches(queryClient, repoId) })
|
||||
|
||||
const handleGitError = (error: unknown) => {
|
||||
if (error instanceof FetchError) {
|
||||
@@ -100,7 +113,7 @@ export function SourceControlPanel({
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch className="w-4 h-4 text-muted-foreground" />
|
||||
<span className="text-sm font-medium">{currentBranch}</span>
|
||||
<span className="text-sm font-medium">{displayBranch}</span>
|
||||
</div>
|
||||
{status && (status.ahead > 0 || status.behind > 0) && (
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
@@ -220,7 +233,7 @@ export function SourceControlPanel({
|
||||
<CommitsTab repoId={repoId} onSelectCommit={handleSelectCommit} />
|
||||
)}
|
||||
{activeTab === 'branches' && currentView === 'default' && (
|
||||
<BranchesTab repoId={repoId} currentBranch={currentBranch} />
|
||||
<BranchesTab repoId={repoId} currentBranch={displayBranch} />
|
||||
)}
|
||||
|
||||
{currentView === 'commit-detail' && selectedCommit && (
|
||||
|
||||
@@ -13,6 +13,7 @@ describe('SettingsList', () => {
|
||||
expect(screen.getByText('Nothing here')).toBeInTheDocument()
|
||||
expect(screen.getByText('Try adding something')).toBeInTheDocument()
|
||||
expect(screen.queryByText('child')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Nothing here').parentElement).toHaveClass('max-h-40')
|
||||
})
|
||||
|
||||
it('renders loadingLabel when isLoading', () => {
|
||||
|
||||
@@ -77,7 +77,7 @@ export function SettingsList({
|
||||
|
||||
if (isEmpty) {
|
||||
return (
|
||||
<div className="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">
|
||||
<p className="text-sm font-medium text-foreground">{emptyTitle}</p>
|
||||
<p className="text-xs mt-1">{emptyHint}</p>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user