fix: edit community backend
This commit is contained in:
@@ -7,7 +7,7 @@ import { PageActionType } from '@/config/types';
|
|||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Tabs } from 'antd';
|
import { Tabs } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { useEffect, useId, useRef, useState } from 'react';
|
import React, { useEffect, useId, useMemo, useRef, useState } from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import ColumnWrapper from '../../_components/column-wrapper';
|
import ColumnWrapper from '../../_components/column-wrapper';
|
||||||
import {
|
import {
|
||||||
@@ -41,6 +41,14 @@ interface AddModalProps {
|
|||||||
title?: string;
|
title?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const versionFields = [
|
||||||
|
'image_name',
|
||||||
|
'run_command',
|
||||||
|
'custom_framework',
|
||||||
|
'entrypoint',
|
||||||
|
'env'
|
||||||
|
];
|
||||||
|
|
||||||
const AddModal: React.FC<AddModalProps> = (props) => {
|
const AddModal: React.FC<AddModalProps> = (props) => {
|
||||||
const { action, currentData, onClose, onSubmit, onSubmitYaml, open, title } =
|
const { action, currentData, onClose, onSubmit, onSubmitYaml, open, title } =
|
||||||
props;
|
props;
|
||||||
@@ -52,25 +60,29 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
const [yamlContent, setYamlContent] = useState<string>('');
|
const [yamlContent, setYamlContent] = useState<string>('');
|
||||||
const [formContent, setFormContent] = useState<FormData>({} as FormData);
|
const [formContent, setFormContent] = useState<FormData>({} as FormData);
|
||||||
|
|
||||||
const versionFields = [
|
const showVersionCustomSuffix =
|
||||||
'image_name',
|
currentData?.backend_source === BackendSourceValueMap.BUILTIN ||
|
||||||
'run_command',
|
currentData?.backend_source === BackendSourceValueMap.COMMUNITY;
|
||||||
'custom_framework',
|
|
||||||
'entrypoint',
|
const backendSource = useMemo(
|
||||||
'env'
|
() => currentData?.backend_source || BackendSourceValueMap.CUSTOM,
|
||||||
];
|
[currentData]
|
||||||
|
);
|
||||||
|
|
||||||
// remove '-custom' suffix from version_no in currentData, when action is EDIT
|
// remove '-custom' suffix from version_no in currentData, when action is EDIT
|
||||||
const genertateCurrentVersionData = (values: ListItem): ListItem => {
|
const genertateCurrentVersionData = (values: ListItem): ListItem => {
|
||||||
const data = { ...values };
|
const data = { ...values };
|
||||||
data.version_configs = Object.entries(data.version_configs || {}).reduce(
|
|
||||||
(acc, [key, value]) => {
|
if (showVersionCustomSuffix) {
|
||||||
const version = key.replace(/-custom$/, '');
|
data.version_configs = Object.entries(data.version_configs || {}).reduce(
|
||||||
acc[version] = { ...value, backend_source: data.backend_source };
|
(acc, [key, value]) => {
|
||||||
return acc;
|
const version = key.replace(/-custom$/, '');
|
||||||
},
|
acc[version] = { ...value, backend_source: data.backend_source };
|
||||||
{} as any
|
return acc;
|
||||||
);
|
},
|
||||||
|
{} as any
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
@@ -267,7 +279,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
<ImportYAML
|
<ImportYAML
|
||||||
actionStatus={{
|
actionStatus={{
|
||||||
action: action,
|
action: action,
|
||||||
isBuiltIn: currentData?.is_built_in || false
|
backendSource: backendSource
|
||||||
}}
|
}}
|
||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
content={yamlContent}
|
content={yamlContent}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
useState
|
useState
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { yaml2Json, yamlTemplate } from '../config';
|
import { BackendSourceValueMap, yaml2Json, yamlTemplate } from '../config';
|
||||||
import createSchema from '../config/schema/create.json';
|
import createSchema from '../config/schema/create.json';
|
||||||
import updateBuiltinSchema from '../config/schema/update-builtin.json';
|
import updateBuiltinSchema from '../config/schema/update-builtin.json';
|
||||||
import udpateCustomSchema from '../config/schema/update-custom.json';
|
import udpateCustomSchema from '../config/schema/update-custom.json';
|
||||||
@@ -17,7 +17,7 @@ interface ImportYAMLProps {
|
|||||||
ref?: any;
|
ref?: any;
|
||||||
actionStatus: {
|
actionStatus: {
|
||||||
action: PageActionType;
|
action: PageActionType;
|
||||||
isBuiltIn: boolean;
|
backendSource: string;
|
||||||
};
|
};
|
||||||
content?: string;
|
content?: string;
|
||||||
onSubmit?: (content: string) => void;
|
onSubmit?: (content: string) => void;
|
||||||
@@ -53,7 +53,7 @@ const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
|
|||||||
console.log('exsistingVersions', jsonData);
|
console.log('exsistingVersions', jsonData);
|
||||||
// Check backend version rules
|
// Check backend version rules
|
||||||
if (
|
if (
|
||||||
actionStatus.isBuiltIn &&
|
actionStatus.backendSource === BackendSourceValueMap.BUILTIN &&
|
||||||
exsistingVersions.find((v) => !v?.endsWith('-custom'))
|
exsistingVersions.find((v) => !v?.endsWith('-custom'))
|
||||||
) {
|
) {
|
||||||
setError(intl.formatMessage({ id: 'backend.version.no.tips' }));
|
setError(intl.formatMessage({ id: 'backend.version.no.tips' }));
|
||||||
@@ -62,7 +62,7 @@ const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
|
|||||||
|
|
||||||
// Check custom backend name rule
|
// Check custom backend name rule
|
||||||
if (
|
if (
|
||||||
!actionStatus.isBuiltIn &&
|
actionStatus.backendSource === BackendSourceValueMap.CUSTOM &&
|
||||||
actionStatus.action === PageAction.CREATE &&
|
actionStatus.action === PageAction.CREATE &&
|
||||||
!jsonData.backend_name?.endsWith('-custom')
|
!jsonData.backend_name?.endsWith('-custom')
|
||||||
) {
|
) {
|
||||||
@@ -74,7 +74,7 @@ const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
|
|||||||
if (
|
if (
|
||||||
jsonData.default_version &&
|
jsonData.default_version &&
|
||||||
!exsistingVersions.includes(jsonData.default_version) &&
|
!exsistingVersions.includes(jsonData.default_version) &&
|
||||||
!actionStatus.isBuiltIn
|
actionStatus.backendSource === BackendSourceValueMap.CUSTOM
|
||||||
) {
|
) {
|
||||||
// the default_version must be in [existingVersions]
|
// the default_version must be in [existingVersions]
|
||||||
setError(
|
setError(
|
||||||
@@ -118,7 +118,7 @@ const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
|
|||||||
schema={
|
schema={
|
||||||
actionStatus.action === PageAction.CREATE
|
actionStatus.action === PageAction.CREATE
|
||||||
? createSchema
|
? createSchema
|
||||||
: actionStatus.isBuiltIn
|
: actionStatus.backendSource === BackendSourceValueMap.BUILTIN
|
||||||
? updateBuiltinSchema
|
? updateBuiltinSchema
|
||||||
: udpateCustomSchema
|
: udpateCustomSchema
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { createContext, useContext } from 'react';
|
|||||||
interface FormContextProps {
|
interface FormContextProps {
|
||||||
action: PageActionType;
|
action: PageActionType;
|
||||||
backendSource: string;
|
backendSource: string;
|
||||||
|
showCustomSuffix: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FormContext = createContext<FormContextProps | null>(
|
export const FormContext = createContext<FormContextProps | null>(
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ const BackendForm: React.FC<AddModalProps> = forwardRef(
|
|||||||
const [activeKey, setActiveKey] = React.useState<string[]>([]);
|
const [activeKey, setActiveKey] = React.useState<string[]>([]);
|
||||||
const backendSource = Form.useWatch('backend_source', form);
|
const backendSource = Form.useWatch('backend_source', form);
|
||||||
|
|
||||||
|
const showCustomSuffix =
|
||||||
|
currentData?.backend_source === BackendSourceValueMap.BUILTIN ||
|
||||||
|
currentData?.backend_source === BackendSourceValueMap.COMMUNITY;
|
||||||
|
|
||||||
const onFinishFailed = (errorInfo: any) => {
|
const onFinishFailed = (errorInfo: any) => {
|
||||||
const errorFields = errorInfo.errorFields || [];
|
const errorFields = errorInfo.errorFields || [];
|
||||||
if (errorFields.length > 0) {
|
if (errorFields.length > 0) {
|
||||||
@@ -44,14 +48,18 @@ const BackendForm: React.FC<AddModalProps> = forwardRef(
|
|||||||
? `${values.backend_name}-custom`
|
? `${values.backend_name}-custom`
|
||||||
: values.backend_name
|
: values.backend_name
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// add '-custom' suffix to version_no in version_configs when backendSource is BUILTIN or COMMUNITY
|
||||||
data.version_configs = data.version_configs?.map((item) => {
|
data.version_configs = data.version_configs?.map((item) => {
|
||||||
if (item.version_no) {
|
if (item.version_no) {
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
version_no:
|
version_no: [
|
||||||
backendSource === BackendSourceValueMap.BUILTIN
|
BackendSourceValueMap.BUILTIN,
|
||||||
? `${item.version_no}-custom`
|
BackendSourceValueMap.COMMUNITY
|
||||||
: item.version_no
|
].includes(backendSource)
|
||||||
|
? `${item.version_no}-custom`
|
||||||
|
: item.version_no
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
@@ -85,7 +93,11 @@ const BackendForm: React.FC<AddModalProps> = forwardRef(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<FormContext.Provider
|
<FormContext.Provider
|
||||||
value={{ action: action, backendSource: backendSource }}
|
value={{
|
||||||
|
action: action,
|
||||||
|
backendSource: backendSource,
|
||||||
|
showCustomSuffix: showCustomSuffix
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Form
|
<Form
|
||||||
name="basicForm"
|
name="basicForm"
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ const VersionsForm: React.FC<AddModalProps> = ({
|
|||||||
const defaultCollapseKey =
|
const defaultCollapseKey =
|
||||||
action === 'edit' ? new Set<number>() : new Set([0]);
|
action === 'edit' ? new Set<number>() : new Set([0]);
|
||||||
const form = Form.useFormInstance();
|
const form = Form.useFormInstance();
|
||||||
const { backendSource } = useFormContext();
|
const { backendSource, showCustomSuffix } = useFormContext();
|
||||||
const version_configs = Form.useWatch('version_configs', form);
|
const version_configs = Form.useWatch('version_configs', form);
|
||||||
const [collapseKey, setCollapseKey] =
|
const [collapseKey, setCollapseKey] =
|
||||||
React.useState<Set<number | string>>(defaultCollapseKey);
|
React.useState<Set<number | string>>(defaultCollapseKey);
|
||||||
@@ -329,7 +329,7 @@ const VersionsForm: React.FC<AddModalProps> = ({
|
|||||||
>
|
>
|
||||||
<SealInput.Input
|
<SealInput.Input
|
||||||
trim
|
trim
|
||||||
addAfter={isBuiltin ? '-custom' : null}
|
addAfter={showCustomSuffix ? '-custom' : null}
|
||||||
onChange={handleVersionChange}
|
onChange={handleVersionChange}
|
||||||
label={intl.formatMessage({ id: 'backend.version' })}
|
label={intl.formatMessage({ id: 'backend.version' })}
|
||||||
required
|
required
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ const useCreateBackend = () => {
|
|||||||
closeBackendModal: handleCloseModal,
|
closeBackendModal: handleCloseModal,
|
||||||
addBackend: handleAddBackend,
|
addBackend: handleAddBackend,
|
||||||
editBackend: handleEditBackend,
|
editBackend: handleEditBackend,
|
||||||
openBackendModalStatus: openCustomModalStatus, // for create custom backend and edit
|
openBackendModalStatus: openCustomModalStatus, // for create custom backend and edit custom/builtin/community backend
|
||||||
openCommunityModalStatus: openCommunityModalStatus, // for create community backend
|
openCommunityModalStatus: openCommunityModalStatus, // for create community backend
|
||||||
addActions: addItems
|
addActions: addItems
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -175,6 +175,20 @@ const generateEnvArgs = (params: any) => {
|
|||||||
return envArgs;
|
return envArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// concat the args, the args is a key-value
|
||||||
|
const generateExtraArgs = (params: any) => {
|
||||||
|
const args = params.registrationInfo?.args || {};
|
||||||
|
const argsList = Object.entries(args);
|
||||||
|
if (argsList.length === 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
let argsStr = '';
|
||||||
|
argsList.forEach(([key, value]) => {
|
||||||
|
argsStr += `${key} ${value} \\\n `;
|
||||||
|
});
|
||||||
|
return argsStr;
|
||||||
|
};
|
||||||
|
|
||||||
const generateExtraModelDirArg = (modelDir: string) => {
|
const generateExtraModelDirArg = (modelDir: string) => {
|
||||||
const pathList = modelDir
|
const pathList = modelDir
|
||||||
?.split(',')
|
?.split(',')
|
||||||
@@ -208,7 +222,8 @@ const setWorkerIPArg = (params: any) => {
|
|||||||
|
|
||||||
const setImageArgs = (params: any) => {
|
const setImageArgs = (params: any) => {
|
||||||
return `${params.image} \\
|
return `${params.image} \\
|
||||||
--server-url ${params.server} \\`;
|
--server-url ${params.server} \\
|
||||||
|
${generateExtraArgs(params)}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// avaliable for NVIDIA、MThreads
|
// avaliable for NVIDIA、MThreads
|
||||||
|
|||||||
Reference in New Issue
Block a user