litellm/ui/litellm-dashboard/src/components/query_param_input.tsx
yuneng-jiang 2672b36dc3
fix(ui): clear pass-through header rows when the create modal is reopened (#37549)
KeyValueInput and QueryParamInput each seeded a private copy of their rows
from the value prop with a one-time useState initializer. The antd form they
were written for hid that: rc-field-form bumps an internal resetCount key on
resetFields, which remounts a Field's children, so the private copy was thrown
away on every reset. react-hook-form's reset does not remount, and the modal is
hidden rather than unmounted, so after Cancel the rows stayed on screen holding
the old values while the form value went back to empty.

The visible cost was a blocked create flow. A leaked header row made the modal
look configured, but the form value behind it was gone, so submitting a fresh
path and target was refused with "Please configure the headers" and no request
was sent. Typing one character into the leaked row put a value back and the
submit went through, which is not something a user can guess.

Both inputs are now controlled off the value prop, which is an array of pairs
rather than a record. A record cannot represent a row whose name is still empty,
which is the reason the private copy existed: two blank rows collapse into one
and a half-typed row disappears as it is typed. With pairs the field value is
the editable shape, the second source of truth is gone, and a form reset clears
the rows like every other field. add_pass_through converts to a record at submit,
so the request payload is unchanged.

Headers now require at least one row with a non-empty name. Previously that was
enforced by accident, because adding a row did not notify the form at all.
2026-08-19 18:44:01 -07:00

54 lines
1.7 KiB
TypeScript

import React from "react";
import { Minus, Plus } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import type { KeyValuePair } from "./key_value_input";
interface QueryParamInputProps {
value?: readonly KeyValuePair[];
onChange?: (value: readonly KeyValuePair[]) => void;
}
const QueryParamInput: React.FC<QueryParamInputProps> = ({ value = [], onChange }) => {
const handleAdd = () => onChange?.([...value, ["", ""]]);
const handleRemove = (index: number) => onChange?.(value.filter((_, i) => i !== index));
const handleChange = (index: number, pair: KeyValuePair) =>
onChange?.(value.map((existing, i) => (i === index ? pair : existing)));
return (
<div className="space-y-2">
{value.map(([key, val], index) => (
<div key={index} className="flex items-center gap-2">
<Input
placeholder="Parameter Name (e.g., version)"
value={key}
onChange={(e) => handleChange(index, [e.target.value, val])}
/>
<Input
placeholder="Parameter Value (e.g., v1)"
value={val}
onChange={(e) => handleChange(index, [key, e.target.value])}
/>
<Button
type="button"
variant="ghost"
size="icon-sm"
onClick={() => handleRemove(index)}
aria-label={`Remove query parameter ${index + 1}`}
>
<Minus />
</Button>
</div>
))}
<Button type="button" variant="outline" onClick={handleAdd}>
<Plus />
Add Query Parameter
</Button>
</div>
);
};
export default QueryParamInput;