new
This commit is contained in:
91
src/pages/rules/components/CopyRule/comp/Step1.tsx
Normal file
91
src/pages/rules/components/CopyRule/comp/Step1.tsx
Normal file
@@ -0,0 +1,91 @@
|
||||
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 { $t } from '@/utils/i18n';
|
||||
import { MultiCopyPopupContext } from '../MultiCopyPopup';
|
||||
import RuleCheckCard from './RuleCheckCard';
|
||||
|
||||
type Step1Props = {
|
||||
formMapRef: any;
|
||||
setTargetDataSourceId: (id: string | number | null) => void;
|
||||
};
|
||||
const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
const { dataSourceList } = useContext(MultiCopyPopupContext);
|
||||
|
||||
useEffect(() => {
|
||||
if (dataSourceList?.length) {
|
||||
// waitTime(1000).then(() => {
|
||||
const sourceDataSourceId = dataSourceList[0]?.id || '';
|
||||
const targetDataSourceId = dataSourceList[1]?.id || '';
|
||||
const curFormRef = formMapRef?.current?.[0]?.current;
|
||||
if (curFormRef) {
|
||||
curFormRef?.setFieldsValue({
|
||||
sourceDataSourceId,
|
||||
targetDataSourceId,
|
||||
});
|
||||
setTargetDataSourceId(targetDataSourceId);
|
||||
}
|
||||
// });
|
||||
}
|
||||
}, [dataSourceList]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ProFormSelect
|
||||
name="sourceDataSourceId"
|
||||
label={$t('pages.clones.step1.source')}
|
||||
options={dataSourceList}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
fieldProps={{
|
||||
allowClear: false,
|
||||
fieldNames: {
|
||||
label: 'sourceName',
|
||||
value: 'id',
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<ProFormDependency name={['sourceDataSourceId']}>
|
||||
{({ sourceDataSourceId }) => {
|
||||
if (!sourceDataSourceId) return null;
|
||||
return <RuleCheckCard dataSourceId={sourceDataSourceId} />;
|
||||
}}
|
||||
</ProFormDependency>
|
||||
|
||||
<Divider>
|
||||
<Tag style={{ borderRadius: 30, padding: '4px 16px' }}>
|
||||
<ArrowDownOutlined /> {$t('pages.clones.step1.dividerText')}
|
||||
</Tag>
|
||||
</Divider>
|
||||
|
||||
<ProFormDependency name={['sourceDataSourceId']}>
|
||||
{({ sourceDataSourceId }) => {
|
||||
if (!sourceDataSourceId) return null;
|
||||
const dataSourceOptions = dataSourceList.filter(
|
||||
(item) => item.id !== sourceDataSourceId,
|
||||
);
|
||||
return (
|
||||
<ProFormSelect
|
||||
name="targetDataSourceId"
|
||||
label={$t('pages.clones.step1.target')}
|
||||
options={dataSourceOptions}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
fieldProps={{
|
||||
allowClear: false,
|
||||
fieldNames: {
|
||||
label: 'sourceName',
|
||||
value: 'id',
|
||||
},
|
||||
}}
|
||||
onChange={(value: string | number | null) => {
|
||||
setTargetDataSourceId(value || null);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</ProFormDependency>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Step1;
|
||||
Reference in New Issue
Block a user