From 684c1ab60026da5400aab3634ad41e1b176b2dd0 Mon Sep 17 00:00:00 2001 From: jialin Date: Thu, 16 Apr 2026 15:03:18 +0800 Subject: [PATCH] fix: apikey model access --- src/components/seal-form/wrapper/index.tsx | 1 + src/pages/_components/select-panel/index.tsx | 15 +- .../add-apikey-modal/allow-models.tsx | 142 ++++++++++-------- .../components/add-apikey-modal/form.tsx | 16 +- .../components/add-apikey-modal/index.tsx | 7 +- src/pages/api-keys/config/index.ts | 4 +- src/pages/api-keys/hooks/use-keys-columns.tsx | 52 ++++--- 7 files changed, 132 insertions(+), 105 deletions(-) diff --git a/src/components/seal-form/wrapper/index.tsx b/src/components/seal-form/wrapper/index.tsx index b19d5472..309a8ba8 100644 --- a/src/components/seal-form/wrapper/index.tsx +++ b/src/components/seal-form/wrapper/index.tsx @@ -170,6 +170,7 @@ const Extra = styled.div` const AddAfter = styled.div` position: relative; + border-radius: 0 var(--ant-border-radius) var(--ant-border-radius) 0; color: var(--ant-color-text-tertiary); font-size: var(--font-size-base); padding-inline: calc(var(--ant-padding-sm) - 1px); diff --git a/src/pages/_components/select-panel/index.tsx b/src/pages/_components/select-panel/index.tsx index b13b4e20..85c17065 100644 --- a/src/pages/_components/select-panel/index.tsx +++ b/src/pages/_components/select-panel/index.tsx @@ -37,6 +37,12 @@ interface SelectPanelProps { selectedKeys: string[]; notFoundContent?: React.ReactNode; onSelectChange: (selectedKeys: string[]) => void; + styles?: { + container?: React.CSSProperties; + left?: React.CSSProperties; + right?: React.CSSProperties; + header?: React.CSSProperties; + }; } const SelectPanel: React.FC = ({ @@ -46,6 +52,7 @@ const SelectPanel: React.FC = ({ selectedKeys, searchPlaceholder, notFoundContent, + styles, onSelectChange }) => { const intl = useIntl(); @@ -150,9 +157,13 @@ const SelectPanel: React.FC = ({ }; return ( - + -
+
( [] ); @@ -56,11 +58,10 @@ const AllowModelsForm: React.FC<{ const handleAllowTypeChange = (e: any) => { const value = e.target.value; onValuesChange?.({ allowed_type: value }, form.getFieldsValue()); - if (value === 'management') { - form.setFieldsValue({ scope: ['management'] }); - } else { - form.setFieldsValue({ scope: ['inference'] }); - } + }; + + const handleOnScopeChange = (checkedValues: any) => { + console.log('checkedValues', form.getFieldValue('allowed_type')); }; useEffect(() => { @@ -71,61 +72,82 @@ const AllowModelsForm: React.FC<{
- - + name="scope" style={{ marginBottom: 8 }}> + ({ + label: intl.formatMessage({ id: item.label }), + value: item.value + }))} + onChange={handleOnScopeChange} + > -
); }; diff --git a/src/pages/api-keys/components/add-apikey-modal/form.tsx b/src/pages/api-keys/components/add-apikey-modal/form.tsx index 8b78d26c..b6c3a05f 100644 --- a/src/pages/api-keys/components/add-apikey-modal/form.tsx +++ b/src/pages/api-keys/components/add-apikey-modal/form.tsx @@ -6,7 +6,7 @@ import { PageActionType } from '@/config/types'; import { useIntl } from '@umijs/max'; import { Form } from 'antd'; import React from 'react'; -import { accessScopeOptions, expirationOptions } from '../../config'; +import { expirationOptions } from '../../config'; import { FormData, ListItem } from '../../config/types'; import AllowModelsForm from './allow-models'; @@ -115,19 +115,7 @@ const APIKeyForm: React.FC<{ )} )} - - name="scope" - hidden - normalize={(value) => (value ? [value] : [])} - getValueProps={(value) => ({ - value: Array.isArray(value) ? value[0] : value - })} - > - - + = ({ ..._.omit(formdata, ['allowed_type']), allowed_model_names: formdata.allowed_type === 'all' || - formdata.allowed_type === 'management' + !formdata.scope?.includes('inference') ? [] : formdata.allowed_model_names || [] }; @@ -186,9 +186,7 @@ const AddModal: React.FC = ({ scope: currentData.scope, allowed_type: currentData.allowed_model_names?.length ? 'custom' - : currentData.scope?.includes('management') - ? 'management' - : 'all', + : 'all', expires_in: parseExpireValue(currentData as ListItem), allowed_model_names: currentData.allowed_model_names || [] }); @@ -272,6 +270,7 @@ const AddModal: React.FC = ({ onFinish={handleOnOk} preserve={false} initialValues={{ + allowed_type: 'all', scope: ['inference'] }} > diff --git a/src/pages/api-keys/config/index.ts b/src/pages/api-keys/config/index.ts index f45a66b3..626c9756 100644 --- a/src/pages/api-keys/config/index.ts +++ b/src/pages/api-keys/config/index.ts @@ -27,13 +27,13 @@ export const expirationOptions = [ export const accessScopeOptions = [ { - label: 'management', + label: 'apikeys.accessScope.management', value: 'management', description: 'v2/', locale: true }, { - label: 'inference', + label: 'apikeys.table.bindModels', value: 'inference', description: 'v1/', locale: true diff --git a/src/pages/api-keys/hooks/use-keys-columns.tsx b/src/pages/api-keys/hooks/use-keys-columns.tsx index f08e0cfd..ccd486fd 100644 --- a/src/pages/api-keys/hooks/use-keys-columns.tsx +++ b/src/pages/api-keys/hooks/use-keys-columns.tsx @@ -8,7 +8,6 @@ import { Tag } from 'antd'; import { ColumnsType } from 'antd/lib/table'; import dayjs from 'dayjs'; import { useMemo } from 'react'; -import { accessScopeOptions } from '../config'; import { ListItem } from '../config/types'; interface ColumnsHookProps { @@ -16,7 +15,7 @@ interface ColumnsHookProps { sortOrder: string[]; } -const actionList: Global.ActionItem[] = [ +const actionList: Global.ActionItem[] = [ { label: 'common.button.edit', key: 'edit', @@ -36,20 +35,6 @@ const useModelsColumns = ({ }: ColumnsHookProps): ColumnsType => { const intl = useIntl(); - const renderAPIs = (record: ListItem) => { - const option = accessScopeOptions.find( - (item) => item.value === record.scope?.[0] - ); - return ( - - {intl.formatMessage({ - id: option?.label || '' - })} - {option?.description && [{option?.description}]} - - ); - }; - return useMemo(() => { return [ { @@ -112,13 +97,34 @@ const useModelsColumns = ({ showTitle: false }, render: (text: string[], record: ListItem) => ( - - {record.scope?.[0] === 'management' - ? intl.formatMessage({ id: 'apikeys.accessScope.management' }) - : record.allowed_model_names?.length - ? record.allowed_model_names.join(', ') - : intl.formatMessage({ id: 'apikeys.models.all' })} - +
+ {record.scope?.includes('management') && ( + + {intl.formatMessage({ id: 'apikeys.accessScope.management' })} + + )} + {record.scope?.includes('inference') && ( +
+ + {record.allowed_model_names?.length + ? record.allowed_model_names.join(', ') + : intl.formatMessage({ id: 'apikeys.models.all' })} + +
+ )} +
) }, {