From 084822814dba5b6d9690fa8edeb9829c9094490f Mon Sep 17 00:00:00 2001 From: jialin Date: Sun, 19 Apr 2026 16:24:04 +0800 Subject: [PATCH] fix: models, apikeys Cascader --- src/pages/usage/components/breakdown-tabs.tsx | 2 + src/pages/usage/components/daily-usage.tsx | 2 +- src/pages/usage/components/filter-bar.tsx | 223 ++++++++++++++---- src/pages/usage/config/index.ts | 62 +++++ src/pages/usage/config/types.ts | 2 + src/pages/usage/index.tsx | 23 +- .../usage/services/use-query-meta-data.ts | 35 ++- src/pages/usage/styles/filter-bar.less | 7 + 8 files changed, 295 insertions(+), 61 deletions(-) diff --git a/src/pages/usage/components/breakdown-tabs.tsx b/src/pages/usage/components/breakdown-tabs.tsx index 914e907e..d55e1727 100644 --- a/src/pages/usage/components/breakdown-tabs.tsx +++ b/src/pages/usage/components/breakdown-tabs.tsx @@ -1,11 +1,13 @@ import { Tabs } from 'antd'; import React from 'react'; +import { GroupOption } from '../config'; import { UsageFilterItem } from '../config/types'; import ApiKeysTable from '../tables/apikeys-table'; import ModelsTable from '../tables/models-table'; import UsersTable from '../tables/users-table'; type FilterOptionType = Omit; +type GroupOptionType = GroupOption; const BreakdownTabs: React.FC<{ dateRange: { diff --git a/src/pages/usage/components/daily-usage.tsx b/src/pages/usage/components/daily-usage.tsx index 5c6f0bce..de1d8c20 100644 --- a/src/pages/usage/components/daily-usage.tsx +++ b/src/pages/usage/components/daily-usage.tsx @@ -183,7 +183,7 @@ const DailyUsage: React.FC = (props) => { chartData={chartData} seriesData={[]} xAxisData={xAxisData} - height={360} + height={280} smooth={false} legendData={legendData} labelFormatter={labelFormatter} diff --git a/src/pages/usage/components/filter-bar.tsx b/src/pages/usage/components/filter-bar.tsx index 601abfd8..bcac5793 100644 --- a/src/pages/usage/components/filter-bar.tsx +++ b/src/pages/usage/components/filter-bar.tsx @@ -1,14 +1,19 @@ +import AutoTooltip from '@/components/auto-tooltip'; +import SealCascader from '@/components/seal-form/seal-cascader'; import SimpleSelect from '@/components/seal-form/simple-select'; import useRangePickerPreset from '@/pages/dashboard/hooks/use-rangepicker-preset'; +import ProviderLogo from '@/pages/maas-provider/components/provider-logo'; import { useModel } from '@@/plugin-model'; import { DownloadOutlined, SyncOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, DatePicker, Dropdown, MenuProps } from 'antd'; import dayjs from 'dayjs'; import React from 'react'; +import { GroupOption } from '../config'; import { UsageFilterItem } from '../config/types'; import FilterBarCss from '../styles/filter-bar.less'; +type valueType = string | number | null; const DefaultDateConfig = { maxRange: 90, defaultRange: 29 @@ -23,9 +28,9 @@ interface FilterBarProps { selectedModels: string[]; selectedUsers: string[]; selectedApiKeys: string[]; - modelOptions: OptionType[]; + modelOptions: GroupOption[]; userOptions: OptionType[]; - apiKeyOptions: OptionType[]; + apiKeyOptions: GroupOption[]; onScopeChange: (value: string) => void; onDateChange: (dates: any, dateStrings: [string, string]) => void; onModelsChange: (value: string[]) => void; @@ -88,6 +93,11 @@ const FilterBar: React.FC = (props) => { } ] }); + const [activeModels, setActiveModels] = React.useState([]); + const [activeApiKeys, setActiveApiKeys] = React.useState([]); + const [activeUserApiKeys, setActiveUserApiKeys] = React.useState( + [] + ); const initialInfo = useModel('@@initialState'); const { initialState } = initialInfo || {}; @@ -104,17 +114,79 @@ const FilterBar: React.FC = (props) => { } ]; + const handleOnModelsChange = (value: valueType[][], selectedOptions: any) => { + setActiveModels(value); + const selectedValues: string[] = value.map((item) => { + if (Array.isArray(item)) { + return item[item.length - 1] as string; // Get the last value in the array + } + return item as string; + }); + onModelsChange(selectedValues); + }; + + const handleOnApiKeysChange = ( + value: valueType[][], + selectedOptions: any + ) => { + setActiveApiKeys(value); + const selectedValues: string[] = value.map((item) => { + if (Array.isArray(item)) { + return item[item.length - 1] as string; // Get the last value in the array + } + return item as string; + }); + onApiKeysChange(selectedValues); + }; + + const displayRender = (labels: any[], option: any) => { + return ( + + {labels[0]} / {labels[1]} + + } + > + {labels[0]} / {labels[1]} + + ); + }; + + const optionRender = (option: any) => { + const { data } = option; + console.log('optionRender', option); + + if (!data.isParent) { + return {data.label}; + } + + if (data.type === 'deployments') { + return ( + + + + {intl.formatMessage({ id: 'menu.models.deployment' })} + + + ); + } + + return ( + + + + {data.label} + + + ); + }; + return (
- {/* {initialState?.currentUser?.is_admin && ( - - )} */} = (props) => { value={[dayjs(startDate), dayjs(endDate)]} onChange={onDateChange} /> - + > + triggerNode.parentNode} + > +
{initialState?.currentUser?.is_admin && ( + <> + +
+ triggerNode.parentNode} + > +
+ + )} + {!initialState?.currentUser?.is_admin && ( )} -