mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
ui fix key table
This commit is contained in:
parent
145aa8854f
commit
981efffa3b
1 changed files with 33 additions and 4 deletions
|
@ -261,6 +261,23 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
|
||||||
const [errorModels, setErrorModels] = useState<string[]>([]);
|
const [errorModels, setErrorModels] = useState<string[]>([]);
|
||||||
const [errorBudget, setErrorBudget] = useState<boolean>(false);
|
const [errorBudget, setErrorBudget] = useState<boolean>(false);
|
||||||
|
|
||||||
|
let metadataString = '';
|
||||||
|
try {
|
||||||
|
metadataString = JSON.stringify(token.metadata, null, 2);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error stringifying metadata:", error);
|
||||||
|
// You can choose a fallback, such as an empty string or a warning message
|
||||||
|
metadataString = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure token is defined and handle gracefully if not
|
||||||
|
const initialValues = token ? {
|
||||||
|
...token,
|
||||||
|
budget_duration: token.budget_duration,
|
||||||
|
metadata: metadataString
|
||||||
|
} : { metadata: metadataString };
|
||||||
|
|
||||||
|
|
||||||
const handleOk = () => {
|
const handleOk = () => {
|
||||||
form
|
form
|
||||||
.validateFields()
|
.validateFields()
|
||||||
|
@ -286,7 +303,7 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
|
||||||
<Form
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
onFinish={handleEditSubmit}
|
onFinish={handleEditSubmit}
|
||||||
initialValues={{...token, budget_duration: token.budget_duration}} // Pass initial values here
|
initialValues={initialValues}
|
||||||
labelCol={{ span: 8 }}
|
labelCol={{ span: 8 }}
|
||||||
wrapperCol={{ span: 16 }}
|
wrapperCol={{ span: 16 }}
|
||||||
labelAlign="left"
|
labelAlign="left"
|
||||||
|
@ -441,13 +458,14 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
|
||||||
<InputNumber step={1} precision={1} width={200} />
|
<InputNumber step={1} precision={1} width={200} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="Metadata"
|
label="Metadata (ensure this is valid JSON)"
|
||||||
name="metadata"
|
name="metadata"
|
||||||
initialValue={token.metadata}
|
|
||||||
>
|
>
|
||||||
<TextArea
|
<TextArea
|
||||||
value={String(token.metadata)}
|
|
||||||
rows={10}
|
rows={10}
|
||||||
|
onChange={(e) => {
|
||||||
|
form.setFieldsValue({ metadata: e.target.value });
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</>
|
</>
|
||||||
|
@ -675,6 +693,17 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
|
||||||
const currentKey = formValues.token;
|
const currentKey = formValues.token;
|
||||||
formValues.key = currentKey;
|
formValues.key = currentKey;
|
||||||
|
|
||||||
|
// Convert metadata back to an object if it exists and is a string
|
||||||
|
if (formValues.metadata && typeof formValues.metadata === 'string') {
|
||||||
|
try {
|
||||||
|
formValues.metadata = JSON.parse(formValues.metadata);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error parsing metadata JSON:", error);
|
||||||
|
message.error("Invalid metadata JSON for formValue " + formValues.metadata);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the budget_duration back to the API expected format
|
// Convert the budget_duration back to the API expected format
|
||||||
if (formValues.budget_duration) {
|
if (formValues.budget_duration) {
|
||||||
switch (formValues.budget_duration) {
|
switch (formValues.budget_duration) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue