fix: models, apikeys Cascader

This commit is contained in:
jialin
2026-04-22 13:16:48 +08:00
committed by jialin
parent 3a58bd1eef
commit 084822814d
8 changed files with 295 additions and 61 deletions
+62
View File
@@ -1,3 +1,5 @@
import { UsageFilterItem } from './types';
export const groupByOptions = [
{
value: '',
@@ -106,3 +108,63 @@ export const generateColumns = (data: SourceItem[]) => {
}))
];
};
interface DataItem {
identity: {
value: {
provider_name: string | null;
provider_type: string | null;
model_name: string;
};
};
label: string;
}
interface GroupedOption {
value: string;
label: string;
providerType: string;
children: {
label: string;
value: string;
identity: UsageFilterItem['identity'];
}[];
}
export interface GroupOption<TChild> {
value: string | number | null;
label: string;
type: string;
isParent: boolean;
children: (TChild & { value: string })[];
}
export function groupToOptions<T, TChild>(
data: T[],
options: {
getGroupKey: (item: T) => string;
getGroupType: (item: T) => string;
getChild: (item: T) => TChild;
}
): GroupOption<TChild>[] {
const groupedMap = new Map<string, GroupOption<TChild>>();
data.forEach((item) => {
const groupKey = options.getGroupKey(item);
const groupType = options.getGroupType(item);
if (!groupedMap.has(groupKey)) {
groupedMap.set(groupKey, {
value: groupKey,
label: groupKey,
type: groupType,
isParent: true,
children: []
});
}
groupedMap.get(groupKey)!.children.push(options.getChild(item));
});
return Array.from(groupedMap.values());
}
+2
View File
@@ -7,6 +7,8 @@ export interface UsageFilterItem {
api_key_name: string | null;
access_key: string | null;
api_key_is_custom: boolean | null;
provider_type: string | null;
provider_name: string | null;
};
current: {
model_id: string | null;