Merge pull request #4548 from Micah-Zheng/fix/default-api-key-group
fix: 修复默认主题 API 密钥分组行为
This commit is contained in:
commit
95648353e4
@ -128,7 +128,12 @@ export function ApiKeyGroupCombobox({
|
||||
<ChevronsUpDown className='h-4 w-4 shrink-0 opacity-50' />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className='data-[state=closed]:zoom-out-100 data-[state=open]:zoom-in-100 data-[side=bottom]:slide-in-from-top-0 data-[side=left]:slide-in-from-right-0 data-[side=right]:slide-in-from-left-0 data-[side=top]:slide-in-from-bottom-0 w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-xl p-0 shadow-lg data-[state=closed]:duration-75 data-[state=open]:duration-100'>
|
||||
<PopoverContent
|
||||
className='data-[state=closed]:zoom-out-100 data-[state=open]:zoom-in-100 data-[side=bottom]:slide-in-from-top-0 data-[side=left]:slide-in-from-right-0 data-[side=right]:slide-in-from-left-0 data-[side=top]:slide-in-from-bottom-0 w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-xl p-0 shadow-lg data-[state=closed]:duration-75 data-[state=open]:duration-100'
|
||||
onWheel={(event) => event.stopPropagation()}
|
||||
onTouchMove={(event) => event.stopPropagation()}
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
>
|
||||
<Command shouldFilter={false}>
|
||||
<CommandInput
|
||||
placeholder={t('Search...')}
|
||||
|
||||
@ -14,6 +14,7 @@ import { toast } from 'sonner'
|
||||
import { getUserModels, getUserGroups } from '@/lib/api'
|
||||
import { getCurrencyDisplay, getCurrencyLabel } from '@/lib/currency'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useStatus } from '@/hooks/use-status'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Collapsible,
|
||||
@ -48,7 +49,7 @@ import { ERROR_MESSAGES, SUCCESS_MESSAGES } from '../constants'
|
||||
import {
|
||||
apiKeyFormSchema,
|
||||
type ApiKeyFormValues,
|
||||
API_KEY_FORM_DEFAULT_VALUES,
|
||||
getApiKeyFormDefaultValues,
|
||||
transformFormDataToPayload,
|
||||
transformApiKeyToFormDefaults,
|
||||
} from '../lib'
|
||||
@ -103,8 +104,10 @@ export function ApiKeysMutateDrawer({
|
||||
const { t } = useTranslation()
|
||||
const isUpdate = !!currentRow
|
||||
const { triggerRefresh } = useApiKeys()
|
||||
const { status } = useStatus()
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
const [advancedOpen, setAdvancedOpen] = useState(false)
|
||||
const defaultUseAutoGroup = status?.default_use_auto_group === true
|
||||
|
||||
// Fetch models
|
||||
const { data: modelsData } = useQuery({
|
||||
@ -142,7 +145,7 @@ export function ApiKeysMutateDrawer({
|
||||
|
||||
const form = useForm<ApiKeyFormValues>({
|
||||
resolver: zodResolver(apiKeyFormSchema),
|
||||
defaultValues: API_KEY_FORM_DEFAULT_VALUES,
|
||||
defaultValues: getApiKeyFormDefaultValues(defaultUseAutoGroup),
|
||||
})
|
||||
|
||||
// Load existing data when updating
|
||||
@ -156,9 +159,9 @@ export function ApiKeysMutateDrawer({
|
||||
})
|
||||
} else if (open && !isUpdate) {
|
||||
// For create, reset to defaults
|
||||
form.reset(API_KEY_FORM_DEFAULT_VALUES)
|
||||
form.reset(getApiKeyFormDefaultValues(defaultUseAutoGroup))
|
||||
}
|
||||
}, [open, isUpdate, currentRow, form])
|
||||
}, [open, isUpdate, currentRow, form, defaultUseAutoGroup])
|
||||
|
||||
const onSubmit = async (data: ApiKeyFormValues) => {
|
||||
setIsSubmitting(true)
|
||||
|
||||
2
web/default/src/features/keys/constants.ts
vendored
2
web/default/src/features/keys/constants.ts
vendored
@ -56,7 +56,7 @@ export const API_KEY_STATUS_OPTIONS = Object.values(API_KEY_STATUSES).map(
|
||||
// Default Values
|
||||
// ============================================================================
|
||||
|
||||
export const DEFAULT_GROUP = 'auto' as const
|
||||
export const DEFAULT_GROUP = '' as const
|
||||
|
||||
// ============================================================================
|
||||
// Error Messages (i18n keys: use t(ERROR_MESSAGES.xxx) when displaying)
|
||||
|
||||
@ -37,6 +37,16 @@ export const API_KEY_FORM_DEFAULT_VALUES: ApiKeyFormValues = {
|
||||
tokenCount: 1,
|
||||
}
|
||||
|
||||
export function getApiKeyFormDefaultValues(
|
||||
defaultUseAutoGroup: boolean
|
||||
): ApiKeyFormValues {
|
||||
return {
|
||||
...API_KEY_FORM_DEFAULT_VALUES,
|
||||
group: defaultUseAutoGroup ? 'auto' : DEFAULT_GROUP,
|
||||
cross_group_retry: defaultUseAutoGroup,
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Form Data Transformation
|
||||
// ============================================================================
|
||||
|
||||
1
web/default/src/features/keys/lib/index.ts
vendored
1
web/default/src/features/keys/lib/index.ts
vendored
@ -5,6 +5,7 @@ export {
|
||||
apiKeyFormSchema,
|
||||
type ApiKeyFormValues,
|
||||
API_KEY_FORM_DEFAULT_VALUES,
|
||||
getApiKeyFormDefaultValues,
|
||||
transformFormDataToPayload,
|
||||
transformApiKeyToFormDefaults,
|
||||
} from './api-key-form'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user