|
@@ -1,5 +1,6 @@
|
|
|
import React, { forwardRef } from 'react';
|
|
|
import {
|
|
|
+ FormContainer,
|
|
|
FormDndSortList,
|
|
|
IMapping,
|
|
|
IStepForm,
|
|
@@ -7,95 +8,108 @@ import {
|
|
|
Select,
|
|
|
useWizard
|
|
|
} from './form';
|
|
|
+import { Step1 } from './StepOneForm';
|
|
|
+import { Step2 } from './StepTwoForm';
|
|
|
import { ITableSchemaResponse, useTableSchema } from './service';
|
|
|
|
|
|
-interface IForm {
|
|
|
- mapping: IMapping<ITableSchemaResponse>[];
|
|
|
- mode: string;
|
|
|
-}
|
|
|
+export namespace Step3 {
|
|
|
+ export const KEY = 'step3';
|
|
|
+ export const TITLE = '配置转换规则';
|
|
|
|
|
|
-const StepThreeForm: IStepForm<IForm> = (props, ref) => {
|
|
|
- const { wizardData, formProps } = useWizard(ref, { mapping: [] });
|
|
|
+ export interface IForm {
|
|
|
+ mapping: IMapping<ITableSchemaResponse>[];
|
|
|
+ mode: string;
|
|
|
+ }
|
|
|
|
|
|
- const ds1: string | undefined = wizardData['step1']?.dataSource1;
|
|
|
- const tn1: string | undefined = wizardData['step1']?.detail1?.tableName;
|
|
|
- const ds2: string | undefined = wizardData['step2']?.dataSource2;
|
|
|
- const tn2: string | undefined = wizardData['step2']?.detail2?.tableName;
|
|
|
+ interface IWizardData {
|
|
|
+ [Step1.KEY]?: Partial<Step1.IForm>;
|
|
|
+ [Step2.KEY]?: Partial<Step2.IForm>;
|
|
|
+ }
|
|
|
|
|
|
- const { data: sourceSchema } = useTableSchema(ds1, tn1);
|
|
|
- const { data: destSchema } = useTableSchema(ds2, tn2);
|
|
|
+ const StepForm: IStepForm<IForm> = (props, ref) => {
|
|
|
+ const { wizardData, formProps } = useWizard(ref, { mapping: [] });
|
|
|
|
|
|
- const createRowId = (
|
|
|
- sourceSchema?: ITableSchemaResponse | PlaceHolderItem,
|
|
|
- destSchema?: ITableSchemaResponse,
|
|
|
- idx?: number
|
|
|
- ): { sourceId: string; destId: string; rowId: string } => {
|
|
|
- let sourceId: string;
|
|
|
- if (sourceSchema instanceof PlaceHolderItem) {
|
|
|
- sourceId = `${ds1}-${tn1}-${sourceSchema.id}`;
|
|
|
- } else if (sourceSchema) {
|
|
|
- sourceId = `${ds1}-${tn1}-${sourceSchema.field}`;
|
|
|
- } else {
|
|
|
- sourceId = `${ds1}-${tn1}-source${idx}`;
|
|
|
- }
|
|
|
- const destId = destSchema
|
|
|
- ? `${ds2}-${tn2}-${destSchema.field}`
|
|
|
- : `${ds2}-${tn2}-dest${idx}`;
|
|
|
- const rowId = `${sourceId}-${destId}`;
|
|
|
- return { sourceId, destId, rowId };
|
|
|
- };
|
|
|
+ // cast
|
|
|
+ const data: IWizardData = wizardData;
|
|
|
|
|
|
- const formatItemName = (
|
|
|
- schema: ITableSchemaResponse,
|
|
|
- tableName?: string
|
|
|
- ): string => {
|
|
|
- return `${tableName || ''}${schema.field}.${schema.type}`;
|
|
|
- };
|
|
|
+ const ds1 = data[Step1.KEY]?.dataSource;
|
|
|
+ const tn1 = data[Step1.KEY]?.detail?.tableName;
|
|
|
+ const ds2 = data[Step2.KEY]?.dataSource;
|
|
|
+ const tn2 = data[Step2.KEY]?.detail?.tableName;
|
|
|
+
|
|
|
+ const { data: sourceSchema } = useTableSchema(ds1, tn1);
|
|
|
+ const { data: destSchema } = useTableSchema(ds2, tn2);
|
|
|
+
|
|
|
+ const createRowId = (
|
|
|
+ sourceSchema?: ITableSchemaResponse | PlaceHolderItem,
|
|
|
+ destSchema?: ITableSchemaResponse,
|
|
|
+ idx?: number
|
|
|
+ ): { sourceId: string; destId: string; rowId: string } => {
|
|
|
+ let sourceId: string;
|
|
|
+ if (sourceSchema instanceof PlaceHolderItem) {
|
|
|
+ sourceId = `${ds1}-${tn1}-${sourceSchema.id}`;
|
|
|
+ } else if (sourceSchema) {
|
|
|
+ sourceId = `${ds1}-${tn1}-${sourceSchema.field}`;
|
|
|
+ } else {
|
|
|
+ sourceId = `${ds1}-${tn1}-source${idx}`;
|
|
|
+ }
|
|
|
+ const destId = destSchema
|
|
|
+ ? `${ds2}-${tn2}-${destSchema.field}`
|
|
|
+ : `${ds2}-${tn2}-dest${idx}`;
|
|
|
+ const rowId = `${sourceId}-${destId}`;
|
|
|
+ return { sourceId, destId, rowId };
|
|
|
+ };
|
|
|
+
|
|
|
+ const formatItemName = (
|
|
|
+ schema: ITableSchemaResponse,
|
|
|
+ tableName?: string
|
|
|
+ ): string => {
|
|
|
+ return `${tableName || ''}${schema.field}.${schema.type}`;
|
|
|
+ };
|
|
|
+
|
|
|
+ const matchField = (
|
|
|
+ sourceSchema?: ITableSchemaResponse | PlaceHolderItem,
|
|
|
+ destSchema?: ITableSchemaResponse
|
|
|
+ ): boolean => {
|
|
|
+ return (
|
|
|
+ !!sourceSchema &&
|
|
|
+ !!destSchema &&
|
|
|
+ !(sourceSchema instanceof PlaceHolderItem) &&
|
|
|
+ sourceSchema.type === destSchema.type &&
|
|
|
+ sourceSchema.length === destSchema.length
|
|
|
+ );
|
|
|
+ };
|
|
|
|
|
|
- const matchField = (
|
|
|
- sourceSchema?: ITableSchemaResponse | PlaceHolderItem,
|
|
|
- destSchema?: ITableSchemaResponse
|
|
|
- ): boolean => {
|
|
|
return (
|
|
|
- !!sourceSchema &&
|
|
|
- !!destSchema &&
|
|
|
- !(sourceSchema instanceof PlaceHolderItem) &&
|
|
|
- sourceSchema.type === destSchema.type &&
|
|
|
- sourceSchema.length === destSchema.length
|
|
|
+ <FormContainer formProps={formProps}>
|
|
|
+ <div className="form-group">
|
|
|
+ <p className="form-hint">拖拽提取源数据表中的字段,与加载源数据表</p>
|
|
|
+ </div>
|
|
|
+ <FormDndSortList<ITableSchemaResponse, IForm>
|
|
|
+ initSourceList={sourceSchema || []}
|
|
|
+ initDestList={destSchema || []}
|
|
|
+ sourceName={tn1 || ''}
|
|
|
+ destName={tn2 || ''}
|
|
|
+ matchFn={matchField}
|
|
|
+ createRowId={createRowId}
|
|
|
+ formatItemName={(value, isSource) =>
|
|
|
+ formatItemName(value, isSource ? tn1 : tn2)
|
|
|
+ }
|
|
|
+ name="mapping"
|
|
|
+ required
|
|
|
+ />
|
|
|
+ <Select<IForm>
|
|
|
+ label="写入模式"
|
|
|
+ name="mode"
|
|
|
+ options={[
|
|
|
+ { label: '追加', value: 'append' },
|
|
|
+ { label: '覆盖', value: 'overwrite' }
|
|
|
+ ]}
|
|
|
+ required
|
|
|
+ />
|
|
|
+ </FormContainer>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- return (
|
|
|
- <form onSubmit={evt => evt.preventDefault()}>
|
|
|
- <div className="form-group">
|
|
|
- <p className="form-hint">拖拽提取源数据表中的字段,与加载源数据表</p>
|
|
|
- </div>
|
|
|
- <FormDndSortList<ITableSchemaResponse, IForm>
|
|
|
- initSourceList={sourceSchema || []}
|
|
|
- initDestList={destSchema || []}
|
|
|
- sourceName={tn1 || ''}
|
|
|
- destName={tn2 || ''}
|
|
|
- matchFn={matchField}
|
|
|
- createRowId={createRowId}
|
|
|
- formatItemName={(value, isSource) =>
|
|
|
- formatItemName(value, isSource ? tn1 : tn2)
|
|
|
- }
|
|
|
- name="mapping"
|
|
|
- required
|
|
|
- formProps={formProps}
|
|
|
- />
|
|
|
- <Select<IForm>
|
|
|
- label="写入模式"
|
|
|
- name="mode"
|
|
|
- options={[
|
|
|
- { label: '追加', value: 'append' },
|
|
|
- { label: '覆盖', value: 'overwrite' }
|
|
|
- ]}
|
|
|
- required
|
|
|
- formProps={formProps}
|
|
|
- />
|
|
|
- </form>
|
|
|
- );
|
|
|
-};
|
|
|
-
|
|
|
-export default forwardRef(StepThreeForm);
|
|
|
+ export const Form = forwardRef(StepForm);
|
|
|
+}
|