mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-04 23:32:30 +08:00
fix: improve duplicate model ID notifications
- Add toast notification when trying to add duplicate model - Allow free typing when editing model ID, validate on blur - Show warning toast instead of blocking input
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
|||||||
Zap,
|
Zap,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import { useCallback, useEffect, useRef, useState } from "react"
|
import { useCallback, useEffect, useRef, useState } from "react"
|
||||||
|
import { toast } from "sonner"
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@@ -264,7 +265,8 @@ export function ModelConfigDialog({
|
|||||||
if (!selectedProviderId || !selectedProvider) return
|
if (!selectedProviderId || !selectedProvider) return
|
||||||
// Prevent duplicate model IDs
|
// Prevent duplicate model IDs
|
||||||
if (existingModelIds.includes(modelId)) {
|
if (existingModelIds.includes(modelId)) {
|
||||||
return // Model already exists, don't add
|
toast.warning(`Model "${modelId}" already exists in this provider`)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
addModel(selectedProviderId, modelId)
|
addModel(selectedProviderId, modelId)
|
||||||
}
|
}
|
||||||
@@ -1189,11 +1191,28 @@ export function ModelConfigDialog({
|
|||||||
}
|
}
|
||||||
onChange={(
|
onChange={(
|
||||||
e,
|
e,
|
||||||
|
) => {
|
||||||
|
// Allow free typing - validation happens on blur
|
||||||
|
updateModel(
|
||||||
|
selectedProviderId!,
|
||||||
|
model.id,
|
||||||
|
{
|
||||||
|
modelId:
|
||||||
|
e
|
||||||
|
.target
|
||||||
|
.value,
|
||||||
|
validated:
|
||||||
|
undefined,
|
||||||
|
validationError:
|
||||||
|
undefined,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
onBlur={(
|
||||||
|
e,
|
||||||
) => {
|
) => {
|
||||||
const newModelId =
|
const newModelId =
|
||||||
e
|
e.target.value.trim()
|
||||||
.target
|
|
||||||
.value
|
|
||||||
// Check if new ID would be duplicate (excluding current model)
|
// Check if new ID would be duplicate (excluding current model)
|
||||||
const otherModelIds =
|
const otherModelIds =
|
||||||
selectedProvider?.models
|
selectedProvider?.models
|
||||||
@@ -1212,24 +1231,15 @@ export function ModelConfigDialog({
|
|||||||
) ||
|
) ||
|
||||||
[]
|
[]
|
||||||
if (
|
if (
|
||||||
|
newModelId &&
|
||||||
otherModelIds.includes(
|
otherModelIds.includes(
|
||||||
newModelId,
|
newModelId,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return // Don't allow duplicate
|
toast.warning(
|
||||||
|
`Model "${newModelId}" already exists. Please use a unique ID.`,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
updateModel(
|
|
||||||
selectedProviderId!,
|
|
||||||
model.id,
|
|
||||||
{
|
|
||||||
modelId:
|
|
||||||
newModelId,
|
|
||||||
validated:
|
|
||||||
undefined,
|
|
||||||
validationError:
|
|
||||||
undefined,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}}
|
}}
|
||||||
className="flex-1 min-w-0 font-mono text-sm h-8 border-0 bg-transparent focus-visible:bg-background focus-visible:ring-1"
|
className="flex-1 min-w-0 font-mono text-sm h-8 border-0 bg-transparent focus-visible:bg-background focus-visible:ring-1"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user