mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 00:14:15 +00:00
fix(ui/profiles): preserve ANTHROPIC_EXTRA_MODELS on untouched edit-dialog save
The edit dialog cannot pre-populate `extraModels` from the existing profile (the Profile type carries no env data), so the field always opens blank in edit mode. Forwarding that blank value unconditionally clobbered any saved ANTHROPIC_EXTRA_MODELS, since the PUT route treats an empty string as a delete signal. Track react-hook-form's `dirtyFields.extraModels` and only include the field in the update payload when the user actually touched it. Typing then clearing still marks the field dirty, so the explicit-clear UX keeps working.
This commit is contained in:
1 parent
7f14c565df
commit
9122f68dd4
1 file changed
+9
-3
@@ -57,7 +57,7 @@ export function ProfileDialog({ open, onClose, profile }: ProfileDialogProps) {
|
|||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { errors },
|
formState: { errors, dirtyFields },
|
||||||
reset,
|
reset,
|
||||||
control,
|
control,
|
||||||
} = useForm<FormData>({
|
} = useForm<FormData>({
|
||||||
@@ -97,14 +97,20 @@ export function ProfileDialog({ open, onClose, profile }: ProfileDialogProps) {
|
|||||||
const onSubmit = async (data: FormData) => {
|
const onSubmit = async (data: FormData) => {
|
||||||
try {
|
try {
|
||||||
if (profile) {
|
if (profile) {
|
||||||
// Update mode
|
// Update mode. The dialog cannot pre-populate `extraModels` from the
|
||||||
|
// existing profile (Profile type carries no env data), so the field
|
||||||
|
// always starts blank in edit mode. Forwarding that blank value
|
||||||
|
// unconditionally would clobber any saved ANTHROPIC_EXTRA_MODELS via
|
||||||
|
// the route's "empty string deletes" semantics. Only forward the
|
||||||
|
// field if the user actually edited it — typing then clearing still
|
||||||
|
// marks it dirty, preserving the explicit-clear UX.
|
||||||
await updateMutation.mutateAsync({
|
await updateMutation.mutateAsync({
|
||||||
name: profile.name,
|
name: profile.name,
|
||||||
data: {
|
data: {
|
||||||
baseUrl: data.baseUrl,
|
baseUrl: data.baseUrl,
|
||||||
apiKey: data.apiKey,
|
apiKey: data.apiKey,
|
||||||
model: data.model,
|
model: data.model,
|
||||||
extraModels: data.extraModels,
|
...(dirtyFields.extraModels ? { extraModels: data.extraModels } : {}),
|
||||||
opusModel: data.opusModel,
|
opusModel: data.opusModel,
|
||||||
sonnetModel: data.sonnetModel,
|
sonnetModel: data.sonnetModel,
|
||||||
haikuModel: data.haikuModel,
|
haikuModel: data.haikuModel,
|
||||||
|
|||||||
Reference in new issue
Block a user