fix: submit form data error
This commit is contained in:
@@ -13,7 +13,7 @@ interface CompatibilityAlertProps {
|
||||
show: boolean;
|
||||
title?: string;
|
||||
isHtml?: boolean;
|
||||
type: 'danger' | 'warning' | 'transition' | 'info';
|
||||
type?: 'danger' | 'warning' | 'transition';
|
||||
message: string | string[];
|
||||
};
|
||||
contentStyle?: React.CSSProperties;
|
||||
|
||||
@@ -159,7 +159,9 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
||||
const generateGPUIds = (data: FormData) => {
|
||||
const gpu_ids = _.get(data, 'gpu_selector.gpu_ids', []);
|
||||
if (!gpu_ids.length) {
|
||||
return {};
|
||||
return {
|
||||
gpu_selector: null
|
||||
};
|
||||
}
|
||||
|
||||
const result = _.reduce(
|
||||
@@ -175,14 +177,11 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
||||
[]
|
||||
);
|
||||
|
||||
if (result.length) {
|
||||
return {
|
||||
gpu_selector: {
|
||||
gpu_ids: result
|
||||
}
|
||||
};
|
||||
}
|
||||
return {};
|
||||
return {
|
||||
gpu_selector: {
|
||||
gpu_ids: result
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const handleOk = async (formdata: FormData) => {
|
||||
@@ -198,6 +197,8 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
||||
...gpuSelector
|
||||
};
|
||||
|
||||
console.log('allValues--------', allValues);
|
||||
|
||||
onOk(allValues);
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import styled from 'styled-components';
|
||||
import { queryCatalogItemSpec } from '../apis';
|
||||
import {
|
||||
backendOptionsMap,
|
||||
excludeFields,
|
||||
modelCategoriesMap,
|
||||
sourceOptions
|
||||
} from '../config';
|
||||
@@ -83,6 +82,8 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
||||
handleShowCompatibleAlert,
|
||||
setWarningStatus,
|
||||
handleEvaluate,
|
||||
generateGPUIds,
|
||||
handleOnValuesChange,
|
||||
warningStatus
|
||||
} = useCheckCompatibility();
|
||||
const intl = useIntl();
|
||||
@@ -275,14 +276,12 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
const handleOnValuesChange = async (changedValues: any, allValues: any) => {
|
||||
const keys = Object.keys(changedValues);
|
||||
const isExcludeField = keys.some((key) => excludeFields.includes(key));
|
||||
if (!isExcludeField) {
|
||||
const values = form.current?.form.getFieldsValue?.();
|
||||
const data = generateSubmitData(values);
|
||||
handleCheckCompatibility(data);
|
||||
}
|
||||
const onValuesChange = async (changedValues: any, allValues: any) => {
|
||||
handleOnValuesChange?.({
|
||||
changedValues,
|
||||
allValues: generateSubmitData(allValues),
|
||||
source: props.source
|
||||
});
|
||||
};
|
||||
|
||||
const handleBackendChange = (backend: string) => {
|
||||
@@ -561,7 +560,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
||||
gpuOptions={gpuOptions}
|
||||
onBackendChange={handleBackendChange}
|
||||
onSourceChange={handleSourceChange}
|
||||
onValuesChange={handleOnValuesChange}
|
||||
onValuesChange={onValuesChange}
|
||||
></DataForm>
|
||||
</>
|
||||
</ColumnWrapper>
|
||||
|
||||
@@ -115,16 +115,16 @@ const AddModal: FC<AddModalProps> = (props) => {
|
||||
};
|
||||
|
||||
const handleOnOk = async (allValues: FormData) => {
|
||||
const result = getSourceRepoConfigValue(props.source, allValues).values;
|
||||
if (submitAnyway.current) {
|
||||
onOk(allValues);
|
||||
onOk(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = getSourceRepoConfigValue(props.source, allValues);
|
||||
const evalutionData = await handleEvaluate(result.values);
|
||||
const evalutionData = await handleEvaluate(result);
|
||||
handleShowCompatibleAlert?.(evalutionData);
|
||||
if (evalutionData?.compatible) {
|
||||
onOk(allValues);
|
||||
onOk(result);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -309,12 +309,6 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
|
||||
handleSelectModelFile(sortList[0]);
|
||||
setDataSource({ fileList: sortList, loading: false });
|
||||
|
||||
// if (timer.current) {
|
||||
// clearTimeout(timer.current);
|
||||
// }
|
||||
// timer.current = setTimeout(() => {
|
||||
// handleEvaluate(sortList);
|
||||
// }, 200);
|
||||
handleEvaluate(sortList);
|
||||
} catch (error) {
|
||||
setDataSource({ fileList: [], loading: false });
|
||||
|
||||
@@ -59,7 +59,6 @@ import {
|
||||
import {
|
||||
InstanceRealtimeLogStatus,
|
||||
backendOptionsMap,
|
||||
getSourceRepoConfigValue,
|
||||
modelCategories,
|
||||
modelCategoriesMap,
|
||||
modelSourceMap
|
||||
@@ -261,14 +260,8 @@ const Models: React.FC<ModelsProps> = ({
|
||||
const handleModalOk = useCallback(
|
||||
async (data: FormData) => {
|
||||
try {
|
||||
const result = getSourceRepoConfigValue(
|
||||
currentData.current?.source,
|
||||
data
|
||||
);
|
||||
await updateModel({
|
||||
data: {
|
||||
...result.values
|
||||
},
|
||||
data,
|
||||
id: currentData.current?.id as number
|
||||
});
|
||||
setOpenAddModal(false);
|
||||
@@ -299,12 +292,8 @@ const Models: React.FC<ModelsProps> = ({
|
||||
try {
|
||||
console.log('data:', data, openDeployModal);
|
||||
|
||||
const result = getSourceRepoConfigValue(openDeployModal.source, data);
|
||||
|
||||
const modelData = await createModel({
|
||||
data: {
|
||||
...result.values
|
||||
}
|
||||
data
|
||||
});
|
||||
setOpenDeployModal({
|
||||
...openDeployModal,
|
||||
|
||||
@@ -293,7 +293,8 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
|
||||
form.submit?.();
|
||||
};
|
||||
|
||||
const handleOk = async (formdata: FormData) => {
|
||||
const handleOk = async (data: FormData) => {
|
||||
const formdata = getSourceRepoConfigValue(data.source, data).values;
|
||||
let obj = {};
|
||||
let submitData = {} as FormData;
|
||||
if (
|
||||
@@ -306,23 +307,16 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
|
||||
cpu_offloading: false
|
||||
};
|
||||
}
|
||||
if (formdata.scheduleType === 'manual') {
|
||||
const gpuSelector = generateGPUIds(formdata);
|
||||
submitData = {
|
||||
..._.omit(formdata, ['scheduleType']),
|
||||
categories: formdata.categories ? [formdata.categories] : [],
|
||||
worker_selector: null,
|
||||
...obj,
|
||||
...gpuSelector
|
||||
};
|
||||
} else {
|
||||
submitData = {
|
||||
..._.omit(formdata, ['scheduleType']),
|
||||
categories: formdata.categories ? [formdata.categories] : [],
|
||||
gpu_selector: null,
|
||||
...obj
|
||||
};
|
||||
}
|
||||
|
||||
submitData = {
|
||||
..._.omit(formdata, ['scheduleType']),
|
||||
categories: formdata.categories ? [formdata.categories] : [],
|
||||
worker_selector: null,
|
||||
...obj,
|
||||
...(formdata.scheduleType === 'manual'
|
||||
? generateGPUIds(formdata)
|
||||
: { gpu_selector: null })
|
||||
};
|
||||
|
||||
if (submitAnyway.current) {
|
||||
onOk(submitData);
|
||||
|
||||
@@ -217,7 +217,7 @@ export const useCheckCompatibility = () => {
|
||||
const [warningStatus, setWarningStatus] = useState<{
|
||||
show: boolean;
|
||||
title?: string;
|
||||
type?: 'transition' | 'warning' | 'error';
|
||||
type?: 'transition' | 'warning' | 'danger';
|
||||
message: string | string[];
|
||||
}>({
|
||||
show: false,
|
||||
|
||||
@@ -13,7 +13,6 @@ import { createModel } from '@/pages/llmodels/apis';
|
||||
import DeployModal from '@/pages/llmodels/components/deploy-modal';
|
||||
import {
|
||||
backendOptionsMap,
|
||||
getSourceRepoConfigValue,
|
||||
modelSourceMap,
|
||||
setSourceRepoConfigValue
|
||||
} from '@/pages/llmodels/config';
|
||||
@@ -393,11 +392,8 @@ const ModelFiles = () => {
|
||||
|
||||
const handleCreateModel = async (data: any) => {
|
||||
try {
|
||||
const result = getSourceRepoConfigValue(openDeployModal.source, data);
|
||||
const modelData = await createModel({
|
||||
data: {
|
||||
...result.values
|
||||
}
|
||||
data
|
||||
});
|
||||
setOpenDeployModal({
|
||||
...openDeployModal,
|
||||
|
||||
Reference in New Issue
Block a user