fix: edit community backend
This commit is contained in:
@@ -22,6 +22,10 @@ const BackendForm: React.FC<AddModalProps> = forwardRef(
|
||||
const [activeKey, setActiveKey] = React.useState<string[]>([]);
|
||||
const backendSource = Form.useWatch('backend_source', form);
|
||||
|
||||
const showCustomSuffix =
|
||||
currentData?.backend_source === BackendSourceValueMap.BUILTIN ||
|
||||
currentData?.backend_source === BackendSourceValueMap.COMMUNITY;
|
||||
|
||||
const onFinishFailed = (errorInfo: any) => {
|
||||
const errorFields = errorInfo.errorFields || [];
|
||||
if (errorFields.length > 0) {
|
||||
@@ -44,14 +48,18 @@ const BackendForm: React.FC<AddModalProps> = forwardRef(
|
||||
? `${values.backend_name}-custom`
|
||||
: 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) => {
|
||||
if (item.version_no) {
|
||||
return {
|
||||
...item,
|
||||
version_no:
|
||||
backendSource === BackendSourceValueMap.BUILTIN
|
||||
? `${item.version_no}-custom`
|
||||
: item.version_no
|
||||
version_no: [
|
||||
BackendSourceValueMap.BUILTIN,
|
||||
BackendSourceValueMap.COMMUNITY
|
||||
].includes(backendSource)
|
||||
? `${item.version_no}-custom`
|
||||
: item.version_no
|
||||
};
|
||||
}
|
||||
return item;
|
||||
@@ -85,7 +93,11 @@ const BackendForm: React.FC<AddModalProps> = forwardRef(
|
||||
|
||||
return (
|
||||
<FormContext.Provider
|
||||
value={{ action: action, backendSource: backendSource }}
|
||||
value={{
|
||||
action: action,
|
||||
backendSource: backendSource,
|
||||
showCustomSuffix: showCustomSuffix
|
||||
}}
|
||||
>
|
||||
<Form
|
||||
name="basicForm"
|
||||
|
||||
@@ -67,7 +67,7 @@ const VersionsForm: React.FC<AddModalProps> = ({
|
||||
const defaultCollapseKey =
|
||||
action === 'edit' ? new Set<number>() : new Set([0]);
|
||||
const form = Form.useFormInstance();
|
||||
const { backendSource } = useFormContext();
|
||||
const { backendSource, showCustomSuffix } = useFormContext();
|
||||
const version_configs = Form.useWatch('version_configs', form);
|
||||
const [collapseKey, setCollapseKey] =
|
||||
React.useState<Set<number | string>>(defaultCollapseKey);
|
||||
@@ -329,7 +329,7 @@ const VersionsForm: React.FC<AddModalProps> = ({
|
||||
>
|
||||
<SealInput.Input
|
||||
trim
|
||||
addAfter={isBuiltin ? '-custom' : null}
|
||||
addAfter={showCustomSuffix ? '-custom' : null}
|
||||
onChange={handleVersionChange}
|
||||
label={intl.formatMessage({ id: 'backend.version' })}
|
||||
required
|
||||
|
||||
Reference in New Issue
Block a user