feat(clone): allow same-source cloning and disable cross-sourceType targets
- Remove the restriction that prevents cloning to the same data source - Disable (instead of hide) target options with different sourceType - Add sourceType label (MT4/MT5) to data source select options - Preserve groupFilter/param1/param2 when cloning to same source - Auto-reset target when source changes to incompatible sourceType - Remove parent-level check requiring at least 2 data sources Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -232,22 +232,22 @@ const MultiCopyPopup = ({
|
||||
onValuesChange={({ sourceDataSourceId }) => {
|
||||
if (sourceDataSourceId) {
|
||||
const curFormRef = formMapRef?.current?.[0]?.current;
|
||||
const curTargetDataSourceId =
|
||||
curFormRef?.getFieldValue('targetDataSourceId');
|
||||
if (curTargetDataSourceId === sourceDataSourceId) {
|
||||
let targetDataSourceId: string | number | null = null;
|
||||
for (const item of dataSourceList) {
|
||||
if (item.id !== sourceDataSourceId) {
|
||||
targetDataSourceId = item.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetDataSourceId) {
|
||||
curFormRef?.setFieldsValue({
|
||||
targetDataSourceId,
|
||||
});
|
||||
setTargetDataSourceId(targetDataSourceId);
|
||||
}
|
||||
const curTargetId = curFormRef?.getFieldValue('targetDataSourceId');
|
||||
const sourceItem = dataSourceList.find(
|
||||
(item) => item.id === sourceDataSourceId,
|
||||
);
|
||||
const targetItem = dataSourceList.find(
|
||||
(item) => item.id === curTargetId,
|
||||
);
|
||||
if (targetItem && sourceItem && targetItem.sourceType !== sourceItem.sourceType) {
|
||||
const fallback =
|
||||
dataSourceList.find(
|
||||
(item) =>
|
||||
item.id !== sourceDataSourceId &&
|
||||
item.sourceType === sourceItem.sourceType,
|
||||
)?.id || sourceDataSourceId;
|
||||
curFormRef?.setFieldsValue({ targetDataSourceId: fallback });
|
||||
setTargetDataSourceId(fallback);
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
Row,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import useRichFormat from '@/hooks/useRichI18n';
|
||||
import { $t } from '@/utils/i18n';
|
||||
import { type SchemaType, schemaMap } from '../../ruleFormSchema';
|
||||
@@ -68,49 +68,83 @@ const SingleCopyPopup = ({
|
||||
} =
|
||||
schemaMap[currentRuleType as unknown as SchemaType]?.({ richFormat }) || {};
|
||||
|
||||
const rightDataSourceList = dataSourceList.filter(
|
||||
(item) => item.id !== formValues?.dataSourceId,
|
||||
);
|
||||
const sourceSourceType = useMemo(() => {
|
||||
return dataSourceList.find((item) => item.id === formValues?.dataSourceId)
|
||||
?.sourceType;
|
||||
}, [dataSourceList, formValues?.dataSourceId]);
|
||||
|
||||
const dataSourceOptions = useMemo(() => {
|
||||
return dataSourceList.map((item) => ({
|
||||
...item,
|
||||
disabled: item.sourceType !== sourceSourceType,
|
||||
label: (
|
||||
<Flex justify="space-between" align="center">
|
||||
<span>{item.sourceName}</span>
|
||||
<Typography.Text
|
||||
type="secondary"
|
||||
style={{ fontSize: 12, marginLeft: 8 }}
|
||||
>
|
||||
MT{item.sourceType}
|
||||
</Typography.Text>
|
||||
</Flex>
|
||||
),
|
||||
}));
|
||||
}, [dataSourceList, sourceSourceType]);
|
||||
|
||||
const initialValues = transformInitialValue?.(formValues) || formValues;
|
||||
|
||||
const rightFirstDataSource = rightDataSourceList[0];
|
||||
const rightFirstDataSource =
|
||||
dataSourceOptions.find(
|
||||
(item) => item.id !== formValues?.dataSourceId && !item.disabled,
|
||||
) || dataSourceOptions[0];
|
||||
const isSameSource = rightFirstDataSource?.id === formValues?.dataSourceId;
|
||||
const copyFormValues = {
|
||||
...initialValues,
|
||||
name: initialValues?.name
|
||||
? `${initialValues.name} - ${rightFirstDataSource?.sourceName}`
|
||||
: `${Date.now()} - ${rightFirstDataSource?.sourceName}`,
|
||||
groupFilter: '',
|
||||
id: void 0,
|
||||
dataSourceId: rightFirstDataSource?.id || '',
|
||||
...(isSameSource
|
||||
? {}
|
||||
: {
|
||||
groupFilter: '',
|
||||
...(symbolFormShow ? { param2: '' } : {}),
|
||||
...(assetFormShow ? { param1: '' } : {}),
|
||||
}),
|
||||
};
|
||||
if (symbolFormShow) {
|
||||
copyFormValues.param2 = '';
|
||||
}
|
||||
if (assetFormShow) {
|
||||
copyFormValues.param1 = '';
|
||||
}
|
||||
|
||||
const formContent = ({
|
||||
dataSourceList,
|
||||
dataSourceList: options,
|
||||
formAttr,
|
||||
onDataSourceChange,
|
||||
}: {
|
||||
dataSourceList: API.DataSourceListItem[];
|
||||
dataSourceList: any[];
|
||||
formAttr: Record<string, any>;
|
||||
onDataSourceChange?: (dataSourceId: string | number) => void;
|
||||
}) => {
|
||||
return (
|
||||
<ProForm {...formAttr} submitter={false}>
|
||||
<ProForm
|
||||
{...formAttr}
|
||||
submitter={false}
|
||||
onValuesChange={(changedValues) => {
|
||||
if (changedValues.dataSourceId && onDataSourceChange) {
|
||||
onDataSourceChange(changedValues.dataSourceId);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ProFormSelect
|
||||
name="dataSourceId"
|
||||
label={$t('table.dataSource')}
|
||||
options={dataSourceList}
|
||||
options={options}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
fieldProps={{
|
||||
allowClear: false,
|
||||
fieldNames: {
|
||||
label: 'sourceName',
|
||||
label: 'label',
|
||||
value: 'id',
|
||||
},
|
||||
optionLabelProp: 'label',
|
||||
}}
|
||||
/>
|
||||
<BetaSchemaForm layoutType="Embed" columns={leftForm} />
|
||||
@@ -194,53 +228,64 @@ const SingleCopyPopup = ({
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Row>
|
||||
<Col xs={24} sm={11}>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>📋 {$t('pages.rules.originalRule')}</Text>
|
||||
</div>
|
||||
{formContent({
|
||||
dataSourceList,
|
||||
formAttr: { initialValues, disabled: true },
|
||||
})}
|
||||
</Col>
|
||||
{visible && (
|
||||
<Row>
|
||||
<Col xs={24} sm={11}>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>📋 {$t('pages.rules.originalRule')}</Text>
|
||||
</div>
|
||||
{formContent({
|
||||
dataSourceList: dataSourceOptions,
|
||||
formAttr: { initialValues, disabled: true },
|
||||
})}
|
||||
</Col>
|
||||
|
||||
<Col xs={0} sm={1}>
|
||||
<Flex vertical align="center" style={{ height: '100%' }}>
|
||||
<ArrowRightOutlined style={{ marginTop: 2, fontSize: 18 }} />
|
||||
<Divider type="vertical" style={{ flex: 1, marginTop: 16 }} />
|
||||
</Flex>
|
||||
</Col>
|
||||
<Col xs={0} sm={1}>
|
||||
<Flex vertical align="center" style={{ height: '100%' }}>
|
||||
<ArrowRightOutlined style={{ marginTop: 2, fontSize: 18 }} />
|
||||
<Divider type="vertical" style={{ flex: 1, marginTop: 16 }} />
|
||||
</Flex>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={0}>
|
||||
<div className="text-center" style={{ marginBottom: 16 }}>
|
||||
<ArrowDownOutlined />
|
||||
</div>
|
||||
</Col>
|
||||
<Col xs={24} sm={0}>
|
||||
<div className="text-center" style={{ marginBottom: 16 }}>
|
||||
<ArrowDownOutlined />
|
||||
</div>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12}>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>✏️ {$t('pages.rules.cloneRulePreview')}</Text>
|
||||
</div>
|
||||
<Col xs={24} sm={12}>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>✏️ {$t('pages.rules.cloneRulePreview')}</Text>
|
||||
</div>
|
||||
|
||||
{formContent({
|
||||
dataSourceList: rightDataSourceList,
|
||||
formAttr: {
|
||||
initialValues: copyFormValues,
|
||||
formRef: formRef,
|
||||
disabled: confirmLoading,
|
||||
},
|
||||
})}
|
||||
{errMsg && (
|
||||
<Alert
|
||||
message={errMsg}
|
||||
type="error"
|
||||
showIcon
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
{formContent({
|
||||
dataSourceList: dataSourceOptions,
|
||||
formAttr: {
|
||||
initialValues: copyFormValues,
|
||||
formRef: formRef,
|
||||
disabled: confirmLoading,
|
||||
},
|
||||
onDataSourceChange: (dataSourceId) => {
|
||||
const isSame = dataSourceId === formValues?.dataSourceId;
|
||||
if (!isSame) {
|
||||
const fields: Record<string, any> = { groupFilter: '' };
|
||||
if (symbolFormShow) fields.param2 = '';
|
||||
if (assetFormShow) fields.param1 = '';
|
||||
formRef.current?.setFieldsValue(fields);
|
||||
}
|
||||
},
|
||||
})}
|
||||
{errMsg && (
|
||||
<Alert
|
||||
message={errMsg}
|
||||
type="error"
|
||||
showIcon
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ArrowDownOutlined } from '@ant-design/icons';
|
||||
import { ProFormDependency, ProFormSelect } from '@ant-design/pro-components';
|
||||
import { Divider, Tag } from 'antd';
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { Divider, Flex, Tag, Typography } from 'antd';
|
||||
import { useContext, useEffect, useMemo } from 'react';
|
||||
import { $t } from '@/utils/i18n';
|
||||
import { MultiCopyPopupContext } from '../MultiCopyPopup';
|
||||
import RuleCheckCard from './RuleCheckCard';
|
||||
@@ -13,11 +13,52 @@ type Step1Props = {
|
||||
const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
const { dataSourceList } = useContext(MultiCopyPopupContext);
|
||||
|
||||
const buildOptions = (sourceId?: string | number) => {
|
||||
const sourceType = dataSourceList.find((item) => item.id === sourceId)
|
||||
?.sourceType;
|
||||
return dataSourceList.map((item) => ({
|
||||
...item,
|
||||
disabled: item.sourceType !== sourceType,
|
||||
label: (
|
||||
<Flex justify="space-between" align="center">
|
||||
<span>{item.sourceName}</span>
|
||||
<Typography.Text
|
||||
type="secondary"
|
||||
style={{ fontSize: 12, marginLeft: 8 }}
|
||||
>
|
||||
MT{item.sourceType}
|
||||
</Typography.Text>
|
||||
</Flex>
|
||||
),
|
||||
}));
|
||||
};
|
||||
|
||||
const sourceOptions = useMemo(
|
||||
() => dataSourceList.map((item) => ({
|
||||
...item,
|
||||
label: (
|
||||
<Flex justify="space-between" align="center">
|
||||
<span>{item.sourceName}</span>
|
||||
<Typography.Text
|
||||
type="secondary"
|
||||
style={{ fontSize: 12, marginLeft: 8 }}
|
||||
>
|
||||
MT{item.sourceType}
|
||||
</Typography.Text>
|
||||
</Flex>
|
||||
),
|
||||
})),
|
||||
[dataSourceList],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (dataSourceList?.length) {
|
||||
// waitTime(1000).then(() => {
|
||||
const sourceDataSourceId = dataSourceList[0]?.id || '';
|
||||
const targetDataSourceId = dataSourceList[1]?.id || '';
|
||||
const sourceItem = dataSourceList[0];
|
||||
const sourceDataSourceId = sourceItem?.id || '';
|
||||
const sameTypeItem = dataSourceList.find(
|
||||
(item) => item.id !== sourceDataSourceId && item.sourceType === sourceItem?.sourceType,
|
||||
);
|
||||
const targetDataSourceId = sameTypeItem?.id || sourceDataSourceId;
|
||||
const curFormRef = formMapRef?.current?.[0]?.current;
|
||||
if (curFormRef) {
|
||||
curFormRef?.setFieldsValue({
|
||||
@@ -26,7 +67,6 @@ const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
});
|
||||
setTargetDataSourceId(targetDataSourceId);
|
||||
}
|
||||
// });
|
||||
}
|
||||
}, [dataSourceList]);
|
||||
|
||||
@@ -35,14 +75,15 @@ const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
<ProFormSelect
|
||||
name="sourceDataSourceId"
|
||||
label={$t('pages.clones.step1.source')}
|
||||
options={dataSourceList}
|
||||
options={sourceOptions}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
fieldProps={{
|
||||
allowClear: false,
|
||||
fieldNames: {
|
||||
label: 'sourceName',
|
||||
label: 'label',
|
||||
value: 'id',
|
||||
},
|
||||
optionLabelProp: 'label',
|
||||
}}
|
||||
/>
|
||||
<ProFormDependency name={['sourceDataSourceId']}>
|
||||
@@ -61,21 +102,20 @@ const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
<ProFormDependency name={['sourceDataSourceId']}>
|
||||
{({ sourceDataSourceId }) => {
|
||||
if (!sourceDataSourceId) return null;
|
||||
const dataSourceOptions = dataSourceList.filter(
|
||||
(item) => item.id !== sourceDataSourceId,
|
||||
);
|
||||
const targetOptions = buildOptions(sourceDataSourceId);
|
||||
return (
|
||||
<ProFormSelect
|
||||
name="targetDataSourceId"
|
||||
label={$t('pages.clones.step1.target')}
|
||||
options={dataSourceOptions}
|
||||
options={targetOptions}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
fieldProps={{
|
||||
allowClear: false,
|
||||
fieldNames: {
|
||||
label: 'sourceName',
|
||||
label: 'label',
|
||||
value: 'id',
|
||||
},
|
||||
optionLabelProp: 'label',
|
||||
}}
|
||||
onChange={(value: string | number | null) => {
|
||||
setTargetDataSourceId(value || null);
|
||||
|
||||
@@ -295,10 +295,6 @@ const RuleCommon: React.FC = () => {
|
||||
<Button
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() => {
|
||||
if (dataSourceList.length < 2) {
|
||||
message.warning($t('pages.rules.cloneRuleWarning'));
|
||||
return;
|
||||
}
|
||||
setFormValues(rule);
|
||||
setCopyVisible(true);
|
||||
}}
|
||||
@@ -455,10 +451,6 @@ const RuleCommon: React.FC = () => {
|
||||
<Button
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() => {
|
||||
if (dataSourceList.length < 2) {
|
||||
message.warning($t('pages.rules.cloneRuleWarning'));
|
||||
return;
|
||||
}
|
||||
setMultiCopyVisible(true);
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user