chore: quick create route
This commit is contained in:
@@ -30,6 +30,11 @@ export const rowActionList = [
|
||||
label: 'common.button.edit',
|
||||
icon: icons.EditOutlined
|
||||
},
|
||||
{
|
||||
key: 'registerRoute',
|
||||
label: 'providers.table.registerRoute',
|
||||
icon: icons.CaptivePortal
|
||||
},
|
||||
{
|
||||
key: 'copy',
|
||||
label: 'common.button.clone',
|
||||
|
||||
@@ -98,7 +98,7 @@ const SupportedModels = () => {
|
||||
if (!value || value.length === 0) {
|
||||
return Promise.reject(
|
||||
new Error(
|
||||
getRuleMessage('input', 'providers.form.rules.models')
|
||||
intl.formatMessage({ id: 'providers.form.rules.models' })
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ const SupportedModels = () => {
|
||||
if (value.some((item: ProviderModel) => !item.name)) {
|
||||
return Promise.reject(
|
||||
new Error(
|
||||
getRuleMessage('select', 'providers.form.rules.model')
|
||||
intl.formatMessage({ id: 'providers.form.rules.model' })
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// columns.ts
|
||||
import AutoTooltip from '@/components/auto-tooltip';
|
||||
import DropdownButtons from '@/components/drop-down-buttons';
|
||||
import { SealColumnProps } from '@/components/seal-table/types';
|
||||
import { tableSorter } from '@/config/settings';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Tag } from 'antd';
|
||||
import { ColumnsType } from 'antd/lib/table';
|
||||
import dayjs from 'dayjs';
|
||||
import { useMemo } from 'react';
|
||||
import ProviderLogo from '../components/provider-logo';
|
||||
@@ -16,10 +16,18 @@ import { MaasProviderItem, ProviderModel } from '../config/types';
|
||||
const useProviderColumns = (
|
||||
handleSelect: (val: string, record: MaasProviderItem) => void,
|
||||
onCellClick?: (record: MaasProviderItem, dataIndex: string) => void
|
||||
): SealColumnProps[] => {
|
||||
): ColumnsType<MaasProviderItem> => {
|
||||
const intl = useIntl();
|
||||
|
||||
return useMemo(() => {
|
||||
const setActionList = (record: MaasProviderItem) => {
|
||||
return rowActionList.filter((action) => {
|
||||
if (action.key === 'registerRoute') {
|
||||
return record.models && record.models.length > 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
return [
|
||||
{
|
||||
title: intl.formatMessage({ id: 'common.table.name' }),
|
||||
@@ -84,7 +92,7 @@ const useProviderColumns = (
|
||||
minWidth: 120,
|
||||
render: (value: string, record: MaasProviderItem) => (
|
||||
<DropdownButtons
|
||||
items={rowActionList}
|
||||
items={setActionList(record)}
|
||||
onSelect={(val) => handleSelect(val, record)}
|
||||
></DropdownButtons>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { registerRouteConfigAtom } from '@/atoms/routes';
|
||||
import { modelCategoriesMap } from '@/pages/llmodels/config';
|
||||
import { useNavigate } from '@umijs/max';
|
||||
import { useAtom } from 'jotai';
|
||||
|
||||
const useRegisterRoute = () => {
|
||||
const navigate = useNavigate();
|
||||
const [, setRegisterRouteConfig] = useAtom(registerRouteConfigAtom);
|
||||
|
||||
const handleRegisterRoute = (record: any) => {
|
||||
const model = record.models?.[0] || {};
|
||||
const initialValues = {
|
||||
name: model.name || '',
|
||||
categories: [model.category || modelCategoriesMap.llm],
|
||||
routeTargets: [
|
||||
{
|
||||
weight: 100,
|
||||
provider_model_name: model.name,
|
||||
provider_id: record.id,
|
||||
parentId: record.id
|
||||
}
|
||||
]
|
||||
};
|
||||
setRegisterRouteConfig({
|
||||
initialValues,
|
||||
create: true
|
||||
});
|
||||
navigate('/models/routes');
|
||||
};
|
||||
|
||||
return {
|
||||
handleRegisterRoute
|
||||
};
|
||||
};
|
||||
|
||||
export default useRegisterRoute;
|
||||
@@ -1,15 +1,12 @@
|
||||
import { expandKeysAtom } from '@/atoms/clusters';
|
||||
import DeleteModal from '@/components/delete-modal';
|
||||
import IconFont from '@/components/icon-font';
|
||||
import { FilterBar } from '@/components/page-tools';
|
||||
import { PageAction } from '@/config';
|
||||
import { TABLE_SORT_DIRECTIONS } from '@/config/settings';
|
||||
import useExpandedRowKeys from '@/hooks/use-expanded-row-keys';
|
||||
import useTableFetch from '@/hooks/use-table-fetch';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
import { ConfigProvider, message, Table } from 'antd';
|
||||
import { useAtom } from 'jotai';
|
||||
import _ from 'lodash';
|
||||
import NoResult from '../_components/no-result';
|
||||
import PageBox from '../_components/page-box';
|
||||
@@ -24,6 +21,7 @@ import AddMaasProvider from './components/add-provider-modal';
|
||||
import { FormData, MaasProviderItem as ListItem } from './config/types';
|
||||
import useCreateProvider from './hooks/use-create-provider';
|
||||
import useProviderColumns from './hooks/use-provider-columns';
|
||||
import useRegisterRoute from './hooks/use-register-route';
|
||||
|
||||
const MaasProvider: React.FC = () => {
|
||||
const {
|
||||
@@ -45,10 +43,8 @@ const MaasProvider: React.FC = () => {
|
||||
API: MAAS_PROVIDERS_API,
|
||||
contentForDelete: 'menu.models.providers'
|
||||
});
|
||||
const [expandAtom] = useAtom(expandKeysAtom);
|
||||
const { handleExpandChange, handleExpandAll, expandedRowKeys } =
|
||||
useExpandedRowKeys(expandAtom);
|
||||
const intl = useIntl();
|
||||
const { handleRegisterRoute } = useRegisterRoute();
|
||||
const { openProviderModalStatus, openProviderModal, closeProviderModal } =
|
||||
useCreateProvider({
|
||||
refresh: handleSearch
|
||||
@@ -117,6 +113,10 @@ const MaasProvider: React.FC = () => {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (val === 'registerRoute') {
|
||||
handleRegisterRoute(row);
|
||||
}
|
||||
});
|
||||
|
||||
const renderEmpty = (type?: string) => {
|
||||
|
||||
Reference in New Issue
Block a user