mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix: avoid auto-applying OpenCode config on dropdown selection (#275)
This commit is contained in:
1 parent
0b1d3b175e
commit
a7d0c13f9a
1 file changed
+80
-52
@@ -1,11 +1,12 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Loader2, Plus, Trash2, Edit, StarOff, Download, RotateCcw, FileText, ArrowUpCircle, History, ChevronDown } from 'lucide-react'
|
||||
import { Loader2, Plus, Trash2, Edit, Download, RotateCcw, FileText, ArrowUpCircle, History, ChevronDown } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { CreateConfigDialog } from './CreateConfigDialog'
|
||||
import { OpenCodeConfigEditor } from './OpenCodeConfigEditor'
|
||||
@@ -638,20 +639,28 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
value={activeConfigName}
|
||||
onValueChange={(value) => {
|
||||
setActiveConfigName(value)
|
||||
const next = configs.find((c) => c.name === value)
|
||||
if (next && !next.isDefault) {
|
||||
void setDefaultConfig(next)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="w-full sm:max-w-xs">
|
||||
<SelectValue placeholder="Select a configuration..." />
|
||||
<SelectValue placeholder="Select a configuration...">
|
||||
{activeConfig && (
|
||||
<>
|
||||
{activeConfig.name}
|
||||
{activeConfig.isDefault && (
|
||||
<span className="text-orange-500 dark:text-orange-400"> (Active)</span>
|
||||
)}
|
||||
{!activeConfig.isValid && ' (Invalid)'}
|
||||
</>
|
||||
)}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{configs.map((config) => (
|
||||
<SelectItem key={config.id} value={config.name}>
|
||||
{config.name}
|
||||
{config.isDefault && ' (Current)'}
|
||||
{config.isDefault && (
|
||||
<span className="text-orange-500 dark:text-orange-400"> (Active)</span>
|
||||
)}
|
||||
{!config.isValid && ' (Invalid)'}
|
||||
</SelectItem>
|
||||
))}
|
||||
@@ -659,55 +668,74 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
</Select>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
{activeConfig?.isDefault && (
|
||||
<Badge variant="default" className="text-green-500 bg-green-500/10">
|
||||
Current
|
||||
</Badge>
|
||||
)}
|
||||
{activeConfig && !activeConfig.isValid && (
|
||||
<Badge variant="destructive">Invalid Config</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 sm:ml-auto">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={!activeConfig}
|
||||
onClick={() => activeConfig && downloadConfig(activeConfig)}
|
||||
>
|
||||
<Download className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={!activeConfig}
|
||||
onClick={() => activeConfig && startEdit(activeConfig)}
|
||||
>
|
||||
<Edit className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={!activeConfig || activeConfig.isDefault || isUpdating}
|
||||
onClick={() => activeConfig && setDefaultConfig(activeConfig)}
|
||||
>
|
||||
<StarOff className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={!activeConfig}
|
||||
className="text-red-500 hover:text-red-600"
|
||||
onClick={() => activeConfig && setDeleteConfirmConfig(activeConfig)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button size="sm" onClick={() => setIsCreateDialogOpen(true)}>
|
||||
<Plus className="h-3 w-3 sm:h-4 sm:w-4 mr-1" />
|
||||
<span className="text-xs sm:text-sm">New Config</span>
|
||||
</Button>
|
||||
</div>
|
||||
<TooltipProvider delayDuration={200}>
|
||||
<div className="flex items-center gap-1 sm:gap-1.5 sm:ml-auto">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={!activeConfig}
|
||||
onClick={() => activeConfig && downloadConfig(activeConfig)}
|
||||
>
|
||||
<Download className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">Download</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={!activeConfig}
|
||||
onClick={() => activeConfig && startEdit(activeConfig)}
|
||||
>
|
||||
<Edit className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">Edit</TooltipContent>
|
||||
</Tooltip>
|
||||
{!activeConfig?.isDefault && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="default"
|
||||
disabled={!activeConfig || isUpdating}
|
||||
onClick={() => activeConfig && setDefaultConfig(activeConfig)}
|
||||
>
|
||||
Apply
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">Apply as default</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={!activeConfig}
|
||||
className="text-red-500 hover:text-red-600"
|
||||
onClick={() => activeConfig && setDeleteConfirmConfig(activeConfig)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">Delete</TooltipContent>
|
||||
</Tooltip>
|
||||
<Button size="sm" onClick={() => setIsCreateDialogOpen(true)}>
|
||||
<Plus className="h-3 w-3 sm:h-4 sm:w-4 mr-1" />
|
||||
<span className="text-xs sm:text-sm">New Config</span>
|
||||
</Button>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
|
||||
{activeConfig && (
|
||||
@@ -781,7 +809,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<div className="space-y-6">
|
||||
<div className='px-1'>
|
||||
<Label className="text-sm sm:text-base font-medium">Select Configuration to Edit</Label>
|
||||
<Select
|
||||
<Select
|
||||
onValueChange={(value) => {
|
||||
const config = configs.find(c => c.name === value)
|
||||
setSelectedConfig(config || null)
|
||||
|
||||
Reference in new issue
Block a user