chore: update env vars from backend version
This commit is contained in:
+1
-1
@@ -47,7 +47,7 @@ export const workerListAtom = atom<
|
|||||||
}[]
|
}[]
|
||||||
>([]);
|
>([]);
|
||||||
|
|
||||||
interface BackGroupOption {
|
export interface BackGroupOption {
|
||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
|||||||
@@ -40,5 +40,6 @@ export default {
|
|||||||
'backend.entrypoint.tips':
|
'backend.entrypoint.tips':
|
||||||
'If specified, the ENTRYPOINT defined in the image will be ignored, and the command below will be used as the container startup entrypoint.',
|
'If specified, the ENTRYPOINT defined in the image will be ignored, and the command below will be used as the container startup entrypoint.',
|
||||||
'backend.form.defaultEnvironment': 'Default Environment Variables',
|
'backend.form.defaultEnvironment': 'Default Environment Variables',
|
||||||
'backend.recommendModels': 'Recommended Models'
|
'backend.recommendModels': 'Recommended Models',
|
||||||
|
'backend.filter.source': 'Filter by source'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,5 +40,6 @@ export default {
|
|||||||
'backend.entrypoint.tips':
|
'backend.entrypoint.tips':
|
||||||
'If specified, the ENTRYPOINT defined in the image will be ignored, and the command below will be used as the container startup entrypoint.',
|
'If specified, the ENTRYPOINT defined in the image will be ignored, and the command below will be used as the container startup entrypoint.',
|
||||||
'backend.form.defaultEnvironment': 'Default Environment Variables',
|
'backend.form.defaultEnvironment': 'Default Environment Variables',
|
||||||
'backend.recommendModels': 'Recommended Models'
|
'backend.recommendModels': 'Recommended Models',
|
||||||
|
'backend.filter.source': 'Filter by source'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,10 +40,12 @@ export default {
|
|||||||
'backend.entrypoint.tips':
|
'backend.entrypoint.tips':
|
||||||
'Если указано, ENTRYPOINT, заданный в образе, будет проигнорирован, а вместо него для запуска контейнера будет использована команда ниже.',
|
'Если указано, ENTRYPOINT, заданный в образе, будет проигнорирован, а вместо него для запуска контейнера будет использована команда ниже.',
|
||||||
'backend.form.defaultEnvironment': 'Default Environment Variables',
|
'backend.form.defaultEnvironment': 'Default Environment Variables',
|
||||||
'backend.recommendModels': 'Recommended Models'
|
'backend.recommendModels': 'Recommended Models',
|
||||||
|
'backend.filter.source': 'Filter by source'
|
||||||
};
|
};
|
||||||
|
|
||||||
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
||||||
// 1. 'backend.form.defaultEnvironment': 'Default Environment Variables',
|
// 1. 'backend.form.defaultEnvironment': 'Default Environment Variables',
|
||||||
// 2. 'backend.recommendModels': 'Recommended Models'
|
// 2. 'backend.recommendModels': 'Recommended Models',
|
||||||
|
// 3. 'backend.filter.source': 'Filter by source'
|
||||||
// ========== End of To-Do List ==========
|
// ========== End of To-Do List ==========
|
||||||
|
|||||||
@@ -37,5 +37,6 @@ export default {
|
|||||||
'backend.entrypoint.tips':
|
'backend.entrypoint.tips':
|
||||||
'如指定,镜像中定义的 ENTRYPOINT 将被忽略,下面的命令将作为容器启动入口命令使用。',
|
'如指定,镜像中定义的 ENTRYPOINT 将被忽略,下面的命令将作为容器启动入口命令使用。',
|
||||||
'backend.form.defaultEnvironment': '默认环境变量',
|
'backend.form.defaultEnvironment': '默认环境变量',
|
||||||
'backend.recommendModels': '推荐模型'
|
'backend.recommendModels': '推荐模型',
|
||||||
|
'backend.filter.source': '按来源过滤'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -308,6 +308,28 @@ const BackendCard: React.FC<BackendCardProps> = ({ data, onSelect }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderEnabledTag = () => {
|
||||||
|
if (data.backend_source !== BackendSourceValueMap.COMMUNITY) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<ThemeTag
|
||||||
|
className="font-400"
|
||||||
|
variant="outlined"
|
||||||
|
color={data.enabled ? 'green' : 'default'}
|
||||||
|
style={{
|
||||||
|
borderRadius: 'var(--ant-border-radius)',
|
||||||
|
margin: 0,
|
||||||
|
width: 'max-content'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{data.enabled
|
||||||
|
? `${intl.formatMessage({ id: 'common.status.enabled' })}`
|
||||||
|
: `${intl.formatMessage({ id: 'common.status.disabled' })}`}
|
||||||
|
</ThemeTag>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledCard
|
<StyledCard
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
@@ -344,27 +366,10 @@ const BackendCard: React.FC<BackendCardProps> = ({ data, onSelect }) => {
|
|||||||
<InfoItem>
|
<InfoItem>
|
||||||
<span className="label">
|
<span className="label">
|
||||||
<IconFont type="icon-source" className="icon" />
|
<IconFont type="icon-source" className="icon" />
|
||||||
<span>Source:</span>
|
<span>{intl.formatMessage({ id: 'models.form.source' })}:</span>
|
||||||
</span>
|
</span>
|
||||||
{renderSource()}
|
{renderSource()}
|
||||||
{data.backend_source === BackendSourceValueMap.COMMUNITY && (
|
{renderEnabledTag()}
|
||||||
<>
|
|
||||||
<ThemeTag
|
|
||||||
className="font-400"
|
|
||||||
variant="outlined"
|
|
||||||
color={data.enabled ? 'green' : 'default'}
|
|
||||||
style={{
|
|
||||||
borderRadius: 'var(--ant-border-radius)',
|
|
||||||
margin: 0,
|
|
||||||
width: 'max-content'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{data.enabled
|
|
||||||
? `${intl.formatMessage({ id: 'common.status.enabled' })}`
|
|
||||||
: `${intl.formatMessage({ id: 'common.status.disabled' })}`}
|
|
||||||
</ThemeTag>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</InfoItem>
|
</InfoItem>
|
||||||
{renderRecommendModels()}
|
{renderRecommendModels()}
|
||||||
</SourceWrapper>
|
</SourceWrapper>
|
||||||
|
|||||||
@@ -69,7 +69,9 @@ const VersionInfoModal: React.FC<VersionInfoModalProps> = ({
|
|||||||
open={open}
|
open={open}
|
||||||
title={
|
title={
|
||||||
<div className="flex-center gap-16">
|
<div className="flex-center gap-16">
|
||||||
<span>{intl.formatMessage({ id: 'backend.versions' })}</span>
|
<span style={{ fontSize: 14 }}>
|
||||||
|
{intl.formatMessage({ id: 'backend.versions' })}
|
||||||
|
</span>
|
||||||
<Button onClick={addVersion} type="link" size="small">
|
<Button onClick={addVersion} type="link" size="small">
|
||||||
<PlusOutlined /> {intl.formatMessage({ id: 'backend.addVersion' })}
|
<PlusOutlined /> {intl.formatMessage({ id: 'backend.addVersion' })}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { PageActionType } from '@/config/types';
|
||||||
|
import { createContext, useContext } from 'react';
|
||||||
|
|
||||||
|
interface FormContextProps {
|
||||||
|
action: PageActionType;
|
||||||
|
backendSource: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FormContext = createContext<FormContextProps | null>(
|
||||||
|
{} as FormContextProps
|
||||||
|
);
|
||||||
|
|
||||||
|
export const useFormContext = () => {
|
||||||
|
const context = useContext(FormContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error('useFormContext must be used within a FormContextProvider');
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
};
|
||||||
@@ -49,6 +49,24 @@ export const TagColorMap: Record<string, string> = {
|
|||||||
[BackendSourceValueMap.COMMUNITY]: 'cyan'
|
[BackendSourceValueMap.COMMUNITY]: 'cyan'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const backendSourceOptions = [
|
||||||
|
{
|
||||||
|
label: BackendSourceLabelMap[BackendSourceValueMap.BUILTIN],
|
||||||
|
value: BackendSourceValueMap.BUILTIN,
|
||||||
|
locale: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: BackendSourceLabelMap[BackendSourceValueMap.COMMUNITY],
|
||||||
|
value: BackendSourceValueMap.COMMUNITY,
|
||||||
|
locale: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: BackendSourceLabelMap[BackendSourceValueMap.CUSTOM],
|
||||||
|
value: BackendSourceValueMap.CUSTOM,
|
||||||
|
locale: true
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
export const backendActions = [
|
export const backendActions = [
|
||||||
{
|
{
|
||||||
label: 'common.button.edit',
|
label: 'common.button.edit',
|
||||||
|
|||||||
@@ -3,22 +3,19 @@ import ListInput from '@/components/list-input';
|
|||||||
import SealInput from '@/components/seal-form/seal-input';
|
import SealInput from '@/components/seal-form/seal-input';
|
||||||
import SealTextArea from '@/components/seal-form/seal-textarea';
|
import SealTextArea from '@/components/seal-form/seal-textarea';
|
||||||
import { PageAction } from '@/config';
|
import { PageAction } from '@/config';
|
||||||
import { PageActionType } from '@/config/types';
|
|
||||||
import useAppUtils from '@/hooks/use-app-utils';
|
import useAppUtils from '@/hooks/use-app-utils';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Form } from 'antd';
|
import { Form } from 'antd';
|
||||||
import React, { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { BackendSourceValueMap } from '../config';
|
import { BackendSourceValueMap } from '../config';
|
||||||
import { FormData, ListItem } from '../config/types';
|
import { useFormContext } from '../config/form-context';
|
||||||
|
import { FormData } from '../config/types';
|
||||||
|
|
||||||
type AddModalProps = {
|
const BasicForm = () => {
|
||||||
action: PageActionType;
|
|
||||||
currentData?: ListItem;
|
|
||||||
};
|
|
||||||
const BasicForm: React.FC<AddModalProps> = ({ action, currentData }) => {
|
|
||||||
const form = Form.useFormInstance();
|
const form = Form.useFormInstance();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const { getRuleMessage } = useAppUtils();
|
const { getRuleMessage } = useAppUtils();
|
||||||
|
const { action, backendSource } = useFormContext();
|
||||||
const defaultEnvs = Form.useWatch('default_environment', form);
|
const defaultEnvs = Form.useWatch('default_environment', form);
|
||||||
|
|
||||||
const handleEnviromentVarsChange = (labels: Record<string, any>) => {
|
const handleEnviromentVarsChange = (labels: Record<string, any>) => {
|
||||||
@@ -44,18 +41,18 @@ const BasicForm: React.FC<AddModalProps> = ({ action, currentData }) => {
|
|||||||
>
|
>
|
||||||
<SealInput.Input
|
<SealInput.Input
|
||||||
trim
|
trim
|
||||||
addAfter={currentData?.is_built_in ? null : '-custom'}
|
addAfter={
|
||||||
|
backendSource === BackendSourceValueMap.CUSTOM ? '-custom' : null
|
||||||
|
}
|
||||||
disabled={action === PageAction.EDIT}
|
disabled={action === PageAction.EDIT}
|
||||||
label={intl.formatMessage({ id: 'common.table.name' })}
|
label={intl.formatMessage({ id: 'common.table.name' })}
|
||||||
required
|
required
|
||||||
></SealInput.Input>
|
></SealInput.Input>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{action === PageAction.CREATE && (
|
<Form.Item<FormData> hidden name="backend_source">
|
||||||
<Form.Item<FormData> hidden name="backend_source">
|
<SealInput.Input></SealInput.Input>
|
||||||
<SealInput.Input></SealInput.Input>
|
</Form.Item>
|
||||||
</Form.Item>
|
{backendSource !== BackendSourceValueMap.BUILTIN && (
|
||||||
)}
|
|
||||||
{!currentData?.is_built_in && (
|
|
||||||
<>
|
<>
|
||||||
<Form.Item<FormData>
|
<Form.Item<FormData>
|
||||||
name="health_check_path"
|
name="health_check_path"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useIntl } from '@umijs/max';
|
|||||||
import { Form } from 'antd';
|
import { Form } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { forwardRef, useEffect, useImperativeHandle } from 'react';
|
import React, { forwardRef, useEffect, useImperativeHandle } from 'react';
|
||||||
|
import { FormContext } from '../config/form-context';
|
||||||
import { FormData, ListItem } from '../config/types';
|
import { FormData, ListItem } from '../config/types';
|
||||||
import BasicForm from './basic';
|
import BasicForm from './basic';
|
||||||
import VersionsForm from './versions-config';
|
import VersionsForm from './versions-config';
|
||||||
@@ -18,6 +19,7 @@ const BackendForm: React.FC<AddModalProps> = forwardRef(
|
|||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [activeKey, setActiveKey] = React.useState<string[]>([]);
|
const [activeKey, setActiveKey] = React.useState<string[]>([]);
|
||||||
|
const backendSource = Form.useWatch('backend_source', form);
|
||||||
|
|
||||||
const onFinishFailed = (errorInfo: any) => {
|
const onFinishFailed = (errorInfo: any) => {
|
||||||
const errorFields = errorInfo.errorFields || [];
|
const errorFields = errorInfo.errorFields || [];
|
||||||
@@ -79,22 +81,26 @@ const BackendForm: React.FC<AddModalProps> = forwardRef(
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<FormContext.Provider
|
||||||
name="basicForm"
|
value={{ action: action, backendSource: backendSource }}
|
||||||
form={form}
|
|
||||||
onFinish={handleOnFinish}
|
|
||||||
preserve={false}
|
|
||||||
scrollToFirstError={true}
|
|
||||||
initialValues={_.omit(currentData, ['version_configs'])}
|
|
||||||
onFinishFailed={onFinishFailed}
|
|
||||||
>
|
>
|
||||||
<BasicForm action={action} currentData={currentData}></BasicForm>
|
<Form
|
||||||
<VersionsForm
|
name="basicForm"
|
||||||
action={action}
|
form={form}
|
||||||
currentData={currentData}
|
onFinish={handleOnFinish}
|
||||||
activeKey={activeKey}
|
preserve={false}
|
||||||
></VersionsForm>
|
scrollToFirstError={true}
|
||||||
</Form>
|
initialValues={_.omit(currentData, ['version_configs'])}
|
||||||
|
onFinishFailed={onFinishFailed}
|
||||||
|
>
|
||||||
|
<BasicForm></BasicForm>
|
||||||
|
<VersionsForm
|
||||||
|
action={action}
|
||||||
|
currentData={currentData}
|
||||||
|
activeKey={activeKey}
|
||||||
|
></VersionsForm>
|
||||||
|
</Form>
|
||||||
|
</FormContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ const VersionsForm: React.FC<AddModalProps> = ({
|
|||||||
label={intl.formatMessage({
|
label={intl.formatMessage({
|
||||||
id: 'models.form.env'
|
id: 'models.form.env'
|
||||||
})}
|
})}
|
||||||
labels={versionConfigs.environment}
|
labels={versionConfigs?.[name]?.environment}
|
||||||
btnText={intl.formatMessage({ id: 'common.button.vars' })}
|
btnText={intl.formatMessage({ id: 'common.button.vars' })}
|
||||||
onChange={(envs) =>
|
onChange={(envs) =>
|
||||||
handleEnviromentVarsChange(envs, name)
|
handleEnviromentVarsChange(envs, name)
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { PageAction } from '@/config';
|
||||||
|
import { PageActionType } from '@/config/types';
|
||||||
|
import useBodyScroll from '@/hooks/use-body-scroll';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { ListItem } from '../config/types';
|
||||||
|
|
||||||
|
const useCreateBackend = () => {
|
||||||
|
const { saveScrollHeight, restoreScrollHeight } = useBodyScroll();
|
||||||
|
const [openModalStatus, setOpenModalStatus] = useState<{
|
||||||
|
open: boolean;
|
||||||
|
action: PageActionType;
|
||||||
|
currentData?: ListItem;
|
||||||
|
title: string;
|
||||||
|
}>({
|
||||||
|
open: false,
|
||||||
|
action: PageAction.CREATE,
|
||||||
|
currentData: undefined,
|
||||||
|
title: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const openModal = (action: PageActionType, title: string, row?: ListItem) => {
|
||||||
|
setOpenModalStatus({
|
||||||
|
...openModalStatus,
|
||||||
|
open: true,
|
||||||
|
title: title,
|
||||||
|
action,
|
||||||
|
currentData: row
|
||||||
|
});
|
||||||
|
saveScrollHeight();
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeModal = () => {
|
||||||
|
setOpenModalStatus({
|
||||||
|
open: false,
|
||||||
|
action: PageAction.CREATE,
|
||||||
|
currentData: undefined,
|
||||||
|
title: ''
|
||||||
|
});
|
||||||
|
restoreScrollHeight();
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
openBackendModalStatus: openModalStatus,
|
||||||
|
setOpenBackendModalStatus: setOpenModalStatus,
|
||||||
|
openBackendModal: openModal,
|
||||||
|
closeBackendModal: closeModal
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useCreateBackend;
|
||||||
@@ -2,7 +2,6 @@ import DeleteModal from '@/components/delete-modal';
|
|||||||
import IconFont from '@/components/icon-font';
|
import IconFont from '@/components/icon-font';
|
||||||
import { FilterBar } from '@/components/page-tools';
|
import { FilterBar } from '@/components/page-tools';
|
||||||
import { PageAction } from '@/config';
|
import { PageAction } from '@/config';
|
||||||
import { PageActionType } from '@/config/types';
|
|
||||||
import useTableFetch from '@/hooks/use-table-fetch';
|
import useTableFetch from '@/hooks/use-table-fetch';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import useMemoizedFn from 'ahooks/lib/useMemoizedFn';
|
import useMemoizedFn from 'ahooks/lib/useMemoizedFn';
|
||||||
@@ -23,8 +22,9 @@ import {
|
|||||||
import AddModal from './components/add-modal';
|
import AddModal from './components/add-modal';
|
||||||
import BackendCardList from './components/backend-list';
|
import BackendCardList from './components/backend-list';
|
||||||
import VersionInfoModal from './components/version-info-modal';
|
import VersionInfoModal from './components/version-info-modal';
|
||||||
import { json2Yaml, yaml2Json } from './config';
|
import { backendSourceOptions, json2Yaml, yaml2Json } from './config';
|
||||||
import { FormData, ListItem } from './config/types';
|
import { FormData, ListItem } from './config/types';
|
||||||
|
import useCreateBackend from './hooks/use-create-backend';
|
||||||
import useExportYAML from './hooks/use-export-yaml';
|
import useExportYAML from './hooks/use-export-yaml';
|
||||||
import useEnableBackend from './services/use-enable-backend';
|
import useEnableBackend from './services/use-enable-backend';
|
||||||
|
|
||||||
@@ -36,6 +36,7 @@ const BackendList = () => {
|
|||||||
rowSelection,
|
rowSelection,
|
||||||
queryParams,
|
queryParams,
|
||||||
modalRef,
|
modalRef,
|
||||||
|
handleQueryChange,
|
||||||
fetchData,
|
fetchData,
|
||||||
handleDelete,
|
handleDelete,
|
||||||
handleSearch,
|
handleSearch,
|
||||||
@@ -52,41 +53,34 @@ const BackendList = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const { exportYAML } = useExportYAML();
|
const { exportYAML } = useExportYAML();
|
||||||
const [openModalStatus, setOpenModalStatus] = useState<{
|
|
||||||
open: boolean;
|
|
||||||
action: PageActionType;
|
|
||||||
currentData?: Partial<ListItem>;
|
|
||||||
}>({ open: false, action: 'create' });
|
|
||||||
const [openVersionInfoModal, setOpenVersionInfoModal] = useState<{
|
const [openVersionInfoModal, setOpenVersionInfoModal] = useState<{
|
||||||
open: boolean;
|
open: boolean;
|
||||||
currentData?: Partial<ListItem>;
|
currentData?: ListItem;
|
||||||
}>({ open: false });
|
}>({ open: false });
|
||||||
const { handleEnableBackend } = useEnableBackend();
|
const { handleEnableBackend } = useEnableBackend();
|
||||||
|
const { openBackendModal, closeBackendModal, openBackendModalStatus } =
|
||||||
|
useCreateBackend();
|
||||||
|
|
||||||
// built_in_version_configs is read-only, but needs to be included when updating
|
// built_in_version_configs is read-only, but needs to be included when updating
|
||||||
const handleOnSubmit = async (values: FormData) => {
|
const handleOnSubmit = async (values: FormData) => {
|
||||||
try {
|
try {
|
||||||
if (openModalStatus.action === 'create') {
|
if (openBackendModalStatus.action === 'create') {
|
||||||
await createBackend({ data: values });
|
await createBackend({ data: values });
|
||||||
} else {
|
} else {
|
||||||
const omitFields = openModalStatus.currentData?.is_built_in
|
const omitFields = openBackendModalStatus.currentData?.is_built_in
|
||||||
? ['built_in_version_configs', 'default_version']
|
? ['built_in_version_configs', 'default_version']
|
||||||
: ['built_in_version_configs'];
|
: ['built_in_version_configs'];
|
||||||
|
|
||||||
await updateBackend(openModalStatus.currentData!.id!, {
|
await updateBackend(openBackendModalStatus.currentData!.id!, {
|
||||||
data: {
|
data: {
|
||||||
built_in_version_configs:
|
built_in_version_configs:
|
||||||
openModalStatus.currentData?.built_in_version_configs,
|
openBackendModalStatus.currentData?.built_in_version_configs,
|
||||||
..._.omit(values, omitFields),
|
..._.omit(values, omitFields),
|
||||||
health_check_path: values.health_check_path || null
|
health_check_path: values.health_check_path || null
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setOpenModalStatus({
|
closeBackendModal();
|
||||||
open: false,
|
|
||||||
action: 'create',
|
|
||||||
currentData: undefined
|
|
||||||
});
|
|
||||||
handleSearch();
|
handleSearch();
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
@@ -94,46 +88,42 @@ const BackendList = () => {
|
|||||||
// built_in_version_configs needs to be included when updating from YAML, but not allowed to be changed
|
// built_in_version_configs needs to be included when updating from YAML, but not allowed to be changed
|
||||||
const handleOnSubmitYaml = async (values: { content: string }) => {
|
const handleOnSubmitYaml = async (values: { content: string }) => {
|
||||||
try {
|
try {
|
||||||
if (openModalStatus.action === 'create') {
|
if (openBackendModalStatus.action === 'create') {
|
||||||
await createBackendFromYAML({ data: values });
|
await createBackendFromYAML({ data: values });
|
||||||
} else {
|
} else {
|
||||||
const jsonData = yaml2Json(values.content);
|
const jsonData = yaml2Json(values.content);
|
||||||
const yamlContent = json2Yaml({
|
const yamlContent = json2Yaml({
|
||||||
backend_name: openModalStatus.currentData?.backend_name,
|
backend_name: openBackendModalStatus.currentData?.backend_name,
|
||||||
default_version: openModalStatus.currentData?.default_version,
|
default_version: openBackendModalStatus.currentData?.default_version,
|
||||||
built_in_version_configs:
|
built_in_version_configs:
|
||||||
openModalStatus.currentData?.built_in_version_configs,
|
openBackendModalStatus.currentData?.built_in_version_configs,
|
||||||
...jsonData
|
...jsonData
|
||||||
});
|
});
|
||||||
await updateBackendFromYAML(openModalStatus.currentData!.id!, {
|
await updateBackendFromYAML(openBackendModalStatus.currentData!.id!, {
|
||||||
data: {
|
data: {
|
||||||
content: yamlContent
|
content: yamlContent
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setOpenModalStatus({
|
closeBackendModal();
|
||||||
open: false,
|
|
||||||
action: 'create',
|
|
||||||
currentData: undefined
|
|
||||||
});
|
|
||||||
handleSearch();
|
handleSearch();
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddBackend = () => {
|
const handleFilterBySource = (value: string) => {
|
||||||
setOpenModalStatus({
|
handleQueryChange({
|
||||||
open: true,
|
backend_source: value,
|
||||||
action: PageAction.CREATE
|
page: 1
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnSelect = (item: any) => {
|
const handleAddBackend = () => {
|
||||||
|
openBackendModal(PageAction.CREATE, '');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnSelect = async (item: any) => {
|
||||||
if (item.action === 'edit') {
|
if (item.action === 'edit') {
|
||||||
setOpenModalStatus({
|
openBackendModal(PageAction.EDIT, '', item.data);
|
||||||
open: true,
|
|
||||||
action: 'edit',
|
|
||||||
currentData: item.data
|
|
||||||
});
|
|
||||||
} else if (item.action === 'delete') {
|
} else if (item.action === 'delete') {
|
||||||
handleDelete(item.data, {
|
handleDelete(item.data, {
|
||||||
name: item.data.backend_name
|
name: item.data.backend_name
|
||||||
@@ -162,6 +152,10 @@ const BackendList = () => {
|
|||||||
enabled: item.action === 'enable'
|
enabled: item.action === 'enable'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// delay 200ms to refresh list
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, 300);
|
||||||
|
});
|
||||||
handleSearch();
|
handleSearch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -171,11 +165,7 @@ const BackendList = () => {
|
|||||||
open: false,
|
open: false,
|
||||||
currentData: undefined
|
currentData: undefined
|
||||||
});
|
});
|
||||||
setOpenModalStatus({
|
openBackendModal(PageAction.EDIT, '', openVersionInfoModal.currentData);
|
||||||
open: true,
|
|
||||||
action: 'edit',
|
|
||||||
currentData: openVersionInfoModal.currentData
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadMore = useMemoizedFn((nextPage: number) => {
|
const loadMore = useMemoizedFn((nextPage: number) => {
|
||||||
@@ -197,12 +187,18 @@ const BackendList = () => {
|
|||||||
input: 300
|
input: 300
|
||||||
}}
|
}}
|
||||||
inputHolder={intl.formatMessage({ id: 'common.filter.name' })}
|
inputHolder={intl.formatMessage({ id: 'common.filter.name' })}
|
||||||
|
selectHolder={intl.formatMessage({ id: 'backend.filter.source' })}
|
||||||
buttonText={intl.formatMessage({ id: 'backend.button.add' })}
|
buttonText={intl.formatMessage({ id: 'backend.button.add' })}
|
||||||
handleClickPrimary={handleAddBackend}
|
handleClickPrimary={handleAddBackend}
|
||||||
handleSearch={handleSearch}
|
handleSearch={handleSearch}
|
||||||
|
handleSelectChange={handleFilterBySource}
|
||||||
handleInputChange={handleNameChange}
|
handleInputChange={handleNameChange}
|
||||||
rowSelection={rowSelection}
|
rowSelection={rowSelection}
|
||||||
showSelect={false}
|
showSelect={true}
|
||||||
|
selectOptions={backendSourceOptions.map((item) => ({
|
||||||
|
label: intl.formatMessage({ id: item.label }),
|
||||||
|
value: item.value
|
||||||
|
}))}
|
||||||
></FilterBar>
|
></FilterBar>
|
||||||
|
|
||||||
<ScrollerContext.Provider
|
<ScrollerContext.Provider
|
||||||
@@ -237,14 +233,14 @@ const BackendList = () => {
|
|||||||
></NoResult>
|
></NoResult>
|
||||||
</ScrollerContext.Provider>
|
</ScrollerContext.Provider>
|
||||||
<AddModal
|
<AddModal
|
||||||
action={openModalStatus.action}
|
action={openBackendModalStatus.action}
|
||||||
onClose={() => setOpenModalStatus({ open: false, action: 'create' })}
|
onClose={closeBackendModal}
|
||||||
onSubmit={handleOnSubmit}
|
onSubmit={handleOnSubmit}
|
||||||
onSubmitYaml={handleOnSubmitYaml}
|
onSubmitYaml={handleOnSubmitYaml}
|
||||||
currentData={openModalStatus.currentData as ListItem}
|
currentData={openBackendModalStatus.currentData as ListItem}
|
||||||
open={openModalStatus.open}
|
open={openBackendModalStatus.open}
|
||||||
title={
|
title={
|
||||||
openModalStatus.action === 'create'
|
openBackendModalStatus.action === PageAction.CREATE
|
||||||
? intl.formatMessage({ id: 'backend.button.add' })
|
? intl.formatMessage({ id: 'backend.button.add' })
|
||||||
: intl.formatMessage({ id: 'backend.button.edit' })
|
: intl.formatMessage({ id: 'backend.button.edit' })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ export interface BackendGroupItem {
|
|||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
environment?: Record<string, any>;
|
||||||
is_deprecated: boolean;
|
is_deprecated: boolean;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
@@ -333,6 +334,7 @@ export interface BackendOption {
|
|||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
environment?: Record<string, any>;
|
||||||
is_deprecated: boolean;
|
is_deprecated: boolean;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
@@ -352,6 +354,7 @@ export interface BackendItem {
|
|||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
versions: {
|
versions: {
|
||||||
version: string;
|
version: string;
|
||||||
|
environment?: Record<string, any>;
|
||||||
is_deprecated: boolean;
|
is_deprecated: boolean;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import SealCascader from '@/components/seal-form/seal-cascader';
|
|||||||
import SealInput from '@/components/seal-form/seal-input';
|
import SealInput from '@/components/seal-form/seal-input';
|
||||||
import SealSelect from '@/components/seal-form/seal-select';
|
import SealSelect from '@/components/seal-form/seal-select';
|
||||||
import TooltipList from '@/components/tooltip-list';
|
import TooltipList from '@/components/tooltip-list';
|
||||||
import { PageAction } from '@/config';
|
|
||||||
import useAppUtils from '@/hooks/use-app-utils';
|
import useAppUtils from '@/hooks/use-app-utils';
|
||||||
import { BackendSourceValueMap } from '@/pages/backends/config';
|
import { BackendSourceValueMap } from '@/pages/backends/config';
|
||||||
import { CaretDownOutlined, InfoCircleOutlined } from '@ant-design/icons';
|
import { CaretDownOutlined, InfoCircleOutlined } from '@ant-design/icons';
|
||||||
@@ -44,7 +43,15 @@ const BackendFields: React.FC = () => {
|
|||||||
const [selectedBackend, setSelectedBackend] =
|
const [selectedBackend, setSelectedBackend] =
|
||||||
React.useState<BackendOption | null>(null);
|
React.useState<BackendOption | null>(null);
|
||||||
|
|
||||||
const handleBackendVersionOnChange = (value: any) => {
|
const handleBackendVersionOnChange = (value: any, option: any) => {
|
||||||
|
if (Object.keys(option.data.environment || {}).length > 0) {
|
||||||
|
form.setFieldsValue({
|
||||||
|
env: {
|
||||||
|
...(option?.data?.environment || {})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onValuesChange?.({}, form.getFieldsValue());
|
onValuesChange?.({}, form.getFieldsValue());
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,7 +118,6 @@ const BackendFields: React.FC = () => {
|
|||||||
}, [backend, selectedBackend, intl]);
|
}, [backend, selectedBackend, intl]);
|
||||||
|
|
||||||
const backendVersionLabelRender = (option: any) => {
|
const backendVersionLabelRender = (option: any) => {
|
||||||
console.log('backendVersionLabelRender option:', option);
|
|
||||||
return option.title;
|
return option.title;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -122,7 +128,12 @@ const BackendFields: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<Select.OptGroup label={label}>
|
<Select.OptGroup label={label}>
|
||||||
{values.map((item) => (
|
{values.map((item) => (
|
||||||
<Select.Option key={item.value} value={item.value} label={item.label}>
|
<Select.Option
|
||||||
|
data={item}
|
||||||
|
key={item.value}
|
||||||
|
value={item.value}
|
||||||
|
label={item.label}
|
||||||
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
</Select.Option>
|
</Select.Option>
|
||||||
))}
|
))}
|
||||||
@@ -131,9 +142,19 @@ const BackendFields: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleOnBackendChange = (value: any[], option: any) => {
|
const handleOnBackendChange = (value: any[], option: any) => {
|
||||||
form.setFieldValue('backend', value?.[1]);
|
const selectedBackend = value?.[1];
|
||||||
onBackendChange?.(value?.[1], option?.[1] || {});
|
const selectedOption = option?.[1] || {};
|
||||||
setSelectedBackend(option?.[1] || {});
|
|
||||||
|
console.log('handleOnBackendChange selectedOption:', selectedOption);
|
||||||
|
|
||||||
|
form.setFieldsValue({
|
||||||
|
backend: selectedBackend,
|
||||||
|
env: {
|
||||||
|
...(selectedOption.environment || {})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
onBackendChange?.(selectedBackend, selectedOption);
|
||||||
|
setSelectedBackend(selectedOption);
|
||||||
};
|
};
|
||||||
|
|
||||||
const displayRender = (labels: any[], selectedOptions?: any[]) => {
|
const displayRender = (labels: any[], selectedOptions?: any[]) => {
|
||||||
@@ -195,7 +216,7 @@ const BackendFields: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (action === PageAction.EDIT) {
|
if (backend) {
|
||||||
const selected = flatBackendOptions?.find(
|
const selected = flatBackendOptions?.find(
|
||||||
(item) => item.value === backend
|
(item) => item.value === backend
|
||||||
);
|
);
|
||||||
@@ -206,7 +227,7 @@ const BackendFields: React.FC = () => {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [backend, flatBackendOptions, action]);
|
}, [backend, flatBackendOptions]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -212,7 +212,6 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
setTimeout(resolve, 100);
|
setTimeout(resolve, 100);
|
||||||
});
|
});
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
env: null,
|
|
||||||
backend_version: null, // don't set default version here, let the user select it
|
backend_version: null, // don't set default version here, let the user select it
|
||||||
backend_parameters: option.default_backend_param || [],
|
backend_parameters: option.default_backend_param || [],
|
||||||
...updateKVCacheConfig(val, option),
|
...updateKVCacheConfig(val, option),
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ interface BackendGroup {
|
|||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
isLeaf?: boolean;
|
||||||
children: BackendOption[];
|
children: BackendOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +60,8 @@ export default function useQueryBackends() {
|
|||||||
'default_version',
|
'default_version',
|
||||||
'backend_source',
|
'backend_source',
|
||||||
'is_built_in',
|
'is_built_in',
|
||||||
'default_backend_param'
|
'default_backend_param',
|
||||||
|
'environment'
|
||||||
]),
|
]),
|
||||||
backend_source: item.backend_source || BackendSourceValueMap.CUSTOM,
|
backend_source: item.backend_source || BackendSourceValueMap.CUSTOM,
|
||||||
value: item.backend_name,
|
value: item.backend_name,
|
||||||
@@ -77,6 +79,7 @@ export default function useQueryBackends() {
|
|||||||
label: vItem.version,
|
label: vItem.version,
|
||||||
value: vItem.version,
|
value: vItem.version,
|
||||||
is_deprecated: vItem.is_deprecated,
|
is_deprecated: vItem.is_deprecated,
|
||||||
|
environment: vItem.environment || {},
|
||||||
title: vItem.version.replace(/-custom$/, '')
|
title: vItem.version.replace(/-custom$/, '')
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user