mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-03-17 19:03:09 +00:00
feat: fix tooltip shortcuts and add dev server config dialog
Tooltip fixes (PR #177 follow-up): - Remove duplicate title attr on Settings button that caused double-tooltip - Restore keyboard shortcut hints in tooltip text: Settings (,), Reset (R) - Clean up spurious peer markers in package-lock.json Dev server config dialog: - Add DevServerConfigDialog component for custom dev commands - Open config dialog automatically when start fails with "no dev command" - Add useDevServerConfig/useUpdateDevServerConfig hooks - Add updateDevServerConfig API function - Add config gear button next to dev server start Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -302,13 +302,12 @@ function App() {
|
||||
onClick={() => setShowSettings(true)}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
title="Settings (,)"
|
||||
aria-label="Open Settings"
|
||||
>
|
||||
<Settings size={18} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Settings</TooltipContent>
|
||||
<TooltipContent>Settings (,)</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
@@ -323,7 +322,7 @@ function App() {
|
||||
<RotateCcw size={18} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Reset</TooltipContent>
|
||||
<TooltipContent>Reset (R)</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
{/* Ollama Mode Indicator */}
|
||||
|
||||
182
ui/src/components/DevServerConfigDialog.tsx
Normal file
182
ui/src/components/DevServerConfigDialog.tsx
Normal file
@@ -0,0 +1,182 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Loader2, RotateCcw, Terminal } from 'lucide-react'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { useDevServerConfig, useUpdateDevServerConfig } from '@/hooks/useProjects'
|
||||
import { startDevServer } from '@/lib/api'
|
||||
|
||||
interface DevServerConfigDialogProps {
|
||||
projectName: string
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
autoStartOnSave?: boolean
|
||||
}
|
||||
|
||||
export function DevServerConfigDialog({
|
||||
projectName,
|
||||
isOpen,
|
||||
onClose,
|
||||
autoStartOnSave = false,
|
||||
}: DevServerConfigDialogProps) {
|
||||
const { data: config } = useDevServerConfig(isOpen ? projectName : null)
|
||||
const updateConfig = useUpdateDevServerConfig(projectName)
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const [command, setCommand] = useState('')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [isSaving, setIsSaving] = useState(false)
|
||||
|
||||
// Sync input with config when dialog opens or config loads
|
||||
useEffect(() => {
|
||||
if (isOpen && config) {
|
||||
setCommand(config.custom_command ?? config.effective_command ?? '')
|
||||
setError(null)
|
||||
}
|
||||
}, [isOpen, config])
|
||||
|
||||
const hasCustomCommand = !!config?.custom_command
|
||||
|
||||
const handleSaveAndStart = async () => {
|
||||
const trimmed = command.trim()
|
||||
if (!trimmed) {
|
||||
setError('Please enter a dev server command.')
|
||||
return
|
||||
}
|
||||
|
||||
setIsSaving(true)
|
||||
setError(null)
|
||||
|
||||
try {
|
||||
await updateConfig.mutateAsync(trimmed)
|
||||
|
||||
if (autoStartOnSave) {
|
||||
await startDevServer(projectName)
|
||||
queryClient.invalidateQueries({ queryKey: ['dev-server-status', projectName] })
|
||||
}
|
||||
|
||||
onClose()
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to save configuration')
|
||||
} finally {
|
||||
setIsSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleClear = async () => {
|
||||
setIsSaving(true)
|
||||
setError(null)
|
||||
|
||||
try {
|
||||
await updateConfig.mutateAsync(null)
|
||||
setCommand(config?.detected_command ?? '')
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to clear configuration')
|
||||
} finally {
|
||||
setIsSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-primary/10 text-primary">
|
||||
<Terminal size={20} />
|
||||
</div>
|
||||
<DialogTitle>Dev Server Configuration</DialogTitle>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
<DialogDescription asChild>
|
||||
<div className="space-y-4">
|
||||
{/* Detection info */}
|
||||
<div className="rounded-lg border-2 border-border bg-muted/50 p-3 text-sm">
|
||||
{config?.detected_type ? (
|
||||
<p>
|
||||
Detected project type: <strong className="text-foreground">{config.detected_type}</strong>
|
||||
{config.detected_command && (
|
||||
<span className="text-muted-foreground"> — {config.detected_command}</span>
|
||||
)}
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-muted-foreground">
|
||||
No project type detected. Enter a custom command below.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Command input */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="dev-command" className="text-foreground">Dev server command</Label>
|
||||
<Input
|
||||
id="dev-command"
|
||||
value={command}
|
||||
onChange={(e) => {
|
||||
setCommand(e.target.value)
|
||||
setError(null)
|
||||
}}
|
||||
placeholder="npm run dev"
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && !isSaving) {
|
||||
handleSaveAndStart()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Allowed runners: npm, npx, pnpm, yarn, python, uvicorn, flask, poetry, cargo, go
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Clear custom command button */}
|
||||
{hasCustomCommand && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleClear}
|
||||
disabled={isSaving}
|
||||
className="gap-1.5"
|
||||
>
|
||||
<RotateCcw size={14} />
|
||||
Clear custom command (use auto-detection)
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Error display */}
|
||||
{error && (
|
||||
<p className="text-sm font-mono text-destructive">{error}</p>
|
||||
)}
|
||||
</div>
|
||||
</DialogDescription>
|
||||
|
||||
<DialogFooter className="gap-2 sm:gap-0">
|
||||
<Button variant="outline" onClick={onClose} disabled={isSaving}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleSaveAndStart} disabled={isSaving}>
|
||||
{isSaving ? (
|
||||
<>
|
||||
<Loader2 size={16} className="animate-spin mr-1.5" />
|
||||
Saving...
|
||||
</>
|
||||
) : autoStartOnSave ? (
|
||||
'Save & Start'
|
||||
) : (
|
||||
'Save'
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Globe, Square, Loader2, ExternalLink, AlertTriangle } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { Globe, Square, Loader2, ExternalLink, AlertTriangle, Settings2 } from 'lucide-react'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import type { DevServerStatus } from '../lib/types'
|
||||
import { startDevServer, stopDevServer } from '../lib/api'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DevServerConfigDialog } from './DevServerConfigDialog'
|
||||
|
||||
// Re-export DevServerStatus from lib/types for consumers that import from here
|
||||
export type { DevServerStatus }
|
||||
@@ -59,17 +61,27 @@ interface DevServerControlProps {
|
||||
* - Shows loading state during operations
|
||||
* - Displays clickable URL when server is running
|
||||
* - Uses neobrutalism design with cyan accent when running
|
||||
* - Config dialog for setting custom dev commands
|
||||
*/
|
||||
export function DevServerControl({ projectName, status, url }: DevServerControlProps) {
|
||||
const startDevServerMutation = useStartDevServer(projectName)
|
||||
const stopDevServerMutation = useStopDevServer(projectName)
|
||||
const [showConfigDialog, setShowConfigDialog] = useState(false)
|
||||
const [autoStartOnSave, setAutoStartOnSave] = useState(false)
|
||||
|
||||
const isLoading = startDevServerMutation.isPending || stopDevServerMutation.isPending
|
||||
|
||||
const handleStart = () => {
|
||||
// Clear any previous errors before starting
|
||||
stopDevServerMutation.reset()
|
||||
startDevServerMutation.mutate()
|
||||
startDevServerMutation.mutate(undefined, {
|
||||
onError: (err) => {
|
||||
if (err.message?.includes('No dev command available')) {
|
||||
setAutoStartOnSave(true)
|
||||
setShowConfigDialog(true)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
const handleStop = () => {
|
||||
// Clear any previous errors before stopping
|
||||
@@ -77,6 +89,19 @@ export function DevServerControl({ projectName, status, url }: DevServerControlP
|
||||
stopDevServerMutation.mutate()
|
||||
}
|
||||
|
||||
const handleOpenConfig = () => {
|
||||
setAutoStartOnSave(false)
|
||||
setShowConfigDialog(true)
|
||||
}
|
||||
|
||||
const handleCloseConfig = () => {
|
||||
setShowConfigDialog(false)
|
||||
// Clear the start error if config dialog was opened reactively
|
||||
if (startDevServerMutation.error?.message?.includes('No dev command available')) {
|
||||
startDevServerMutation.reset()
|
||||
}
|
||||
}
|
||||
|
||||
// Server is stopped when status is 'stopped' or 'crashed' (can restart)
|
||||
const isStopped = status === 'stopped' || status === 'crashed'
|
||||
// Server is in a running state
|
||||
@@ -84,25 +109,40 @@ export function DevServerControl({ projectName, status, url }: DevServerControlP
|
||||
// Server has crashed
|
||||
const isCrashed = status === 'crashed'
|
||||
|
||||
// Hide inline error when config dialog is handling it
|
||||
const startError = startDevServerMutation.error
|
||||
const showInlineError = startError && !startError.message?.includes('No dev command available')
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
{isStopped ? (
|
||||
<Button
|
||||
onClick={handleStart}
|
||||
disabled={isLoading}
|
||||
variant={isCrashed ? "destructive" : "outline"}
|
||||
size="sm"
|
||||
title={isCrashed ? "Dev Server Crashed - Click to Restart" : "Start Dev Server"}
|
||||
aria-label={isCrashed ? "Restart Dev Server (crashed)" : "Start Dev Server"}
|
||||
>
|
||||
{isLoading ? (
|
||||
<Loader2 size={18} className="animate-spin" />
|
||||
) : isCrashed ? (
|
||||
<AlertTriangle size={18} />
|
||||
) : (
|
||||
<Globe size={18} />
|
||||
)}
|
||||
</Button>
|
||||
<>
|
||||
<Button
|
||||
onClick={handleStart}
|
||||
disabled={isLoading}
|
||||
variant={isCrashed ? "destructive" : "outline"}
|
||||
size="sm"
|
||||
title={isCrashed ? "Dev Server Crashed - Click to Restart" : "Start Dev Server"}
|
||||
aria-label={isCrashed ? "Restart Dev Server (crashed)" : "Start Dev Server"}
|
||||
>
|
||||
{isLoading ? (
|
||||
<Loader2 size={18} className="animate-spin" />
|
||||
) : isCrashed ? (
|
||||
<AlertTriangle size={18} />
|
||||
) : (
|
||||
<Globe size={18} />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleOpenConfig}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
title="Configure Dev Server"
|
||||
aria-label="Configure Dev Server"
|
||||
>
|
||||
<Settings2 size={16} />
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button
|
||||
onClick={handleStop}
|
||||
@@ -139,12 +179,20 @@ export function DevServerControl({ projectName, status, url }: DevServerControlP
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Error display */}
|
||||
{(startDevServerMutation.error || stopDevServerMutation.error) && (
|
||||
{/* Error display (hide "no dev command" error when config dialog handles it) */}
|
||||
{(showInlineError || stopDevServerMutation.error) && (
|
||||
<span className="text-xs font-mono text-destructive ml-2">
|
||||
{String((startDevServerMutation.error || stopDevServerMutation.error)?.message || 'Operation failed')}
|
||||
{String((showInlineError ? startError : stopDevServerMutation.error)?.message || 'Operation failed')}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Dev Server Config Dialog */}
|
||||
<DevServerConfigDialog
|
||||
projectName={projectName}
|
||||
isOpen={showConfigDialog}
|
||||
onClose={handleCloseConfig}
|
||||
autoStartOnSave={autoStartOnSave}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import * as api from '../lib/api'
|
||||
import type { FeatureCreate, FeatureUpdate, ModelsResponse, ProjectSettingsUpdate, ProvidersResponse, Settings, SettingsUpdate } from '../lib/types'
|
||||
import type { DevServerConfig, FeatureCreate, FeatureUpdate, ModelsResponse, ProjectSettingsUpdate, ProvidersResponse, Settings, SettingsUpdate } from '../lib/types'
|
||||
|
||||
// ============================================================================
|
||||
// Projects
|
||||
@@ -345,3 +345,36 @@ export function useUpdateSettings() {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Dev Server Config
|
||||
// ============================================================================
|
||||
|
||||
// Default config for placeholder (until API responds)
|
||||
const DEFAULT_DEV_SERVER_CONFIG: DevServerConfig = {
|
||||
detected_type: null,
|
||||
detected_command: null,
|
||||
custom_command: null,
|
||||
effective_command: null,
|
||||
}
|
||||
|
||||
export function useDevServerConfig(projectName: string | null) {
|
||||
return useQuery({
|
||||
queryKey: ['dev-server-config', projectName],
|
||||
queryFn: () => api.getDevServerConfig(projectName!),
|
||||
enabled: !!projectName,
|
||||
staleTime: 30_000,
|
||||
placeholderData: DEFAULT_DEV_SERVER_CONFIG,
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateDevServerConfig(projectName: string) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (customCommand: string | null) =>
|
||||
api.updateDevServerConfig(projectName, customCommand),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['dev-server-config', projectName] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -445,6 +445,16 @@ export async function getDevServerConfig(projectName: string): Promise<DevServer
|
||||
return fetchJSON(`/projects/${encodeURIComponent(projectName)}/devserver/config`)
|
||||
}
|
||||
|
||||
export async function updateDevServerConfig(
|
||||
projectName: string,
|
||||
customCommand: string | null
|
||||
): Promise<DevServerConfig> {
|
||||
return fetchJSON(`/projects/${encodeURIComponent(projectName)}/devserver/config`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ custom_command: customCommand }),
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Terminal API
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user