fix: 修复默认主题 API 密钥分组行为
Signed-off-by: Micah-Zheng <102610064+Micah-Zheng@users.noreply.github.com>
This commit is contained in:
@@ -128,7 +128,12 @@ export function ApiKeyGroupCombobox({
|
|||||||
<ChevronsUpDown className='h-4 w-4 shrink-0 opacity-50' />
|
<ChevronsUpDown className='h-4 w-4 shrink-0 opacity-50' />
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</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}>
|
<Command shouldFilter={false}>
|
||||||
<CommandInput
|
<CommandInput
|
||||||
placeholder={t('Search...')}
|
placeholder={t('Search...')}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { toast } from 'sonner'
|
|||||||
import { getUserModels, getUserGroups } from '@/lib/api'
|
import { getUserModels, getUserGroups } from '@/lib/api'
|
||||||
import { getCurrencyDisplay, getCurrencyLabel } from '@/lib/currency'
|
import { getCurrencyDisplay, getCurrencyLabel } from '@/lib/currency'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
import { useStatus } from '@/hooks/use-status'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import {
|
import {
|
||||||
Collapsible,
|
Collapsible,
|
||||||
@@ -48,7 +49,7 @@ import { ERROR_MESSAGES, SUCCESS_MESSAGES } from '../constants'
|
|||||||
import {
|
import {
|
||||||
apiKeyFormSchema,
|
apiKeyFormSchema,
|
||||||
type ApiKeyFormValues,
|
type ApiKeyFormValues,
|
||||||
API_KEY_FORM_DEFAULT_VALUES,
|
getApiKeyFormDefaultValues,
|
||||||
transformFormDataToPayload,
|
transformFormDataToPayload,
|
||||||
transformApiKeyToFormDefaults,
|
transformApiKeyToFormDefaults,
|
||||||
} from '../lib'
|
} from '../lib'
|
||||||
@@ -103,8 +104,10 @@ export function ApiKeysMutateDrawer({
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const isUpdate = !!currentRow
|
const isUpdate = !!currentRow
|
||||||
const { triggerRefresh } = useApiKeys()
|
const { triggerRefresh } = useApiKeys()
|
||||||
|
const { status } = useStatus()
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
const [advancedOpen, setAdvancedOpen] = useState(false)
|
const [advancedOpen, setAdvancedOpen] = useState(false)
|
||||||
|
const defaultUseAutoGroup = status?.default_use_auto_group === true
|
||||||
|
|
||||||
// Fetch models
|
// Fetch models
|
||||||
const { data: modelsData } = useQuery({
|
const { data: modelsData } = useQuery({
|
||||||
@@ -142,7 +145,7 @@ export function ApiKeysMutateDrawer({
|
|||||||
|
|
||||||
const form = useForm<ApiKeyFormValues>({
|
const form = useForm<ApiKeyFormValues>({
|
||||||
resolver: zodResolver(apiKeyFormSchema),
|
resolver: zodResolver(apiKeyFormSchema),
|
||||||
defaultValues: API_KEY_FORM_DEFAULT_VALUES,
|
defaultValues: getApiKeyFormDefaultValues(defaultUseAutoGroup),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Load existing data when updating
|
// Load existing data when updating
|
||||||
@@ -156,9 +159,9 @@ export function ApiKeysMutateDrawer({
|
|||||||
})
|
})
|
||||||
} else if (open && !isUpdate) {
|
} else if (open && !isUpdate) {
|
||||||
// For create, reset to defaults
|
// 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) => {
|
const onSubmit = async (data: ApiKeyFormValues) => {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ export const API_KEY_STATUS_OPTIONS = Object.values(API_KEY_STATUSES).map(
|
|||||||
// Default Values
|
// 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)
|
// 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,
|
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
|
// Form Data Transformation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
+1
@@ -5,6 +5,7 @@ export {
|
|||||||
apiKeyFormSchema,
|
apiKeyFormSchema,
|
||||||
type ApiKeyFormValues,
|
type ApiKeyFormValues,
|
||||||
API_KEY_FORM_DEFAULT_VALUES,
|
API_KEY_FORM_DEFAULT_VALUES,
|
||||||
|
getApiKeyFormDefaultValues,
|
||||||
transformFormDataToPayload,
|
transformFormDataToPayload,
|
||||||
transformApiKeyToFormDefaults,
|
transformApiKeyToFormDefaults,
|
||||||
} from './api-key-form'
|
} from './api-key-form'
|
||||||
|
|||||||
Reference in New Issue
Block a user