refactor: enable child collection support current object (#2188)
* refactor: enable child collection support current object * refactor: locale improve
This commit is contained in:
parent
c9b726916c
commit
566668daa1
@ -706,5 +706,5 @@ export default {
|
|||||||
"Create":"Create",
|
"Create":"Create",
|
||||||
"Current form": "Current form",
|
"Current form": "Current form",
|
||||||
"Current object":"Current object",
|
"Current object":"Current object",
|
||||||
"Linkage form form data":"Linkage form form data",
|
"Linkage with form fields":"Linkage with form fields",
|
||||||
};
|
};
|
||||||
|
@ -617,5 +617,5 @@ export default {
|
|||||||
"Create":"新規のみ" ,
|
"Create":"新規のみ" ,
|
||||||
"Current form":"現在のフォーム",
|
"Current form":"現在のフォーム",
|
||||||
"Current object":"現在のオブジェクト",
|
"Current object":"現在のオブジェクト",
|
||||||
"Linkage form form data":"フォームデータから連動",
|
"Linkage with form fields":"フォームデータから連動",
|
||||||
}
|
}
|
||||||
|
@ -790,5 +790,5 @@ export default {
|
|||||||
"File manager": "文件管理器",
|
"File manager": "文件管理器",
|
||||||
"Direct duplicate": "直接复制",
|
"Direct duplicate": "直接复制",
|
||||||
"Copy into the form and continue to fill in": "复制到表单并继续填写",
|
"Copy into the form and continue to fill in": "复制到表单并继续填写",
|
||||||
"Linkage form form data":"从表单数据里联动",
|
"Linkage with form fields":"从表单字段联动",
|
||||||
}
|
}
|
||||||
|
@ -121,10 +121,19 @@ export const CreateRecordAction = observer(
|
|||||||
{ displayName: 'CreateRecordAction' },
|
{ displayName: 'CreateRecordAction' },
|
||||||
);
|
);
|
||||||
|
|
||||||
function getLinkageCollection(str, form) {
|
function getLinkageCollection(str, form, field) {
|
||||||
|
const variablesCtx = { $form: form.values, $iteration: form.values };
|
||||||
|
if (str.includes('$iteration')) {
|
||||||
|
const path = field.path.segments.concat([]);
|
||||||
|
path.splice(-2);
|
||||||
|
str = str.replace('$iteration.', `$iteration.${path.join('.')}.`);
|
||||||
|
const data = parseVariables(str, variablesCtx);
|
||||||
|
return data;
|
||||||
|
} else {
|
||||||
const data = parseVariables(str, { $form: form.values });
|
const data = parseVariables(str, { $form: form.values });
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
export const CreateAction = observer(
|
export const CreateAction = observer(
|
||||||
(props: any) => {
|
(props: any) => {
|
||||||
const { onClick } = props;
|
const { onClick } = props;
|
||||||
@ -222,7 +231,7 @@ export const CreateAction = observer(
|
|||||||
danger={componentType === 'danger'}
|
danger={componentType === 'danger'}
|
||||||
icon={icon}
|
icon={icon}
|
||||||
onClick={(info) => {
|
onClick={(info) => {
|
||||||
const collectionName = getLinkageCollection(linkageFromForm, form);
|
const collectionName = getLinkageCollection(linkageFromForm, form, field);
|
||||||
const targetCollection = inheritsCollections.find((v) => v.name === collectionName)
|
const targetCollection = inheritsCollections.find((v) => v.name === collectionName)
|
||||||
? collectionName
|
? collectionName
|
||||||
: collection.name;
|
: collection.name;
|
||||||
|
@ -4,15 +4,22 @@ import React, { useEffect, useMemo } from 'react';
|
|||||||
import { useCompile } from '../../schema-component';
|
import { useCompile } from '../../schema-component';
|
||||||
import { Variable } from '.././../schema-component';
|
import { Variable } from '.././../schema-component';
|
||||||
import { useFormVariable } from '../VariableInput/hooks/useFormVariable';
|
import { useFormVariable } from '../VariableInput/hooks/useFormVariable';
|
||||||
|
import { useIterationVariable } from '../VariableInput/hooks/useIterationVariable';
|
||||||
|
|
||||||
export const ChildDynamicComponent = observer(
|
export const ChildDynamicComponent = observer(
|
||||||
(props: { collectionName: string; form: any; onChange; value; default }) => {
|
(props: { rootCollection: string; form: any; onChange; value; default; collectionField }) => {
|
||||||
const { form, collectionName, onChange, value } = props;
|
const { form, rootCollection, onChange, value, collectionField } = props;
|
||||||
const formVariabele = useFormVariable({ blockForm: form, rootCollection: collectionName });
|
|
||||||
const compile = useCompile();
|
|
||||||
const result = useMemo(() => [formVariabele].filter(Boolean), [formVariabele]);
|
|
||||||
const scope = compile(result);
|
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
|
const formVariabele = useFormVariable({ blockForm: form, rootCollection });
|
||||||
|
const iterationVariabele = useIterationVariable({
|
||||||
|
blockForm: form,
|
||||||
|
collectionField,
|
||||||
|
rootCollection,
|
||||||
|
});
|
||||||
|
|
||||||
|
const compile = useCompile();
|
||||||
|
const result = useMemo(() => [formVariabele, iterationVariabele].filter(Boolean), [formVariabele]);
|
||||||
|
const scope = compile(result);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onChange(fieldSchema.default);
|
onChange(fieldSchema.default);
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -47,6 +47,7 @@ import {
|
|||||||
SchemaComponentContext,
|
SchemaComponentContext,
|
||||||
SchemaComponentOptions,
|
SchemaComponentOptions,
|
||||||
useAPIClient,
|
useAPIClient,
|
||||||
|
useBlockRequestContext,
|
||||||
useCollection,
|
useCollection,
|
||||||
useCollectionManager,
|
useCollectionManager,
|
||||||
useCompile,
|
useCompile,
|
||||||
@ -1180,6 +1181,7 @@ SchemaSettings.EnableChildCollections = function EnableChildCollectionsItem(prop
|
|||||||
const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current'];
|
const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current'];
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
const { getCollectionJoinField } = useCollectionManager();
|
const { getCollectionJoinField } = useCollectionManager();
|
||||||
|
const ctx = useBlockRequestContext();
|
||||||
const collectionField = getCollectionJoinField(fieldSchema?.parent?.['x-collection-field']) || {};
|
const collectionField = getCollectionJoinField(fieldSchema?.parent?.['x-collection-field']) || {};
|
||||||
const isAssocationAdd = fieldSchema?.parent?.['x-component'] === 'CollectionField';
|
const isAssocationAdd = fieldSchema?.parent?.['x-component'] === 'CollectionField';
|
||||||
return (
|
return (
|
||||||
@ -1212,13 +1214,14 @@ SchemaSettings.EnableChildCollections = function EnableChildCollectionsItem(prop
|
|||||||
},
|
},
|
||||||
linkageFromForm: {
|
linkageFromForm: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
title: "{{t('Linkage form form')}}",
|
title: "{{t('Linkage with form fields')}}",
|
||||||
'x-visible': '{{isAssocationAdd}}',
|
'x-visible': '{{isAssocationAdd}}',
|
||||||
'x-decorator': 'FormItem',
|
'x-decorator': 'FormItem',
|
||||||
'x-component': ChildDynamicComponent,
|
'x-component': ChildDynamicComponent,
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
collectionName: collectionField?.collectionName || collectionName,
|
rootCollection: ctx.props.collection || ctx.props.resource,
|
||||||
form,
|
form,
|
||||||
|
collectionField,
|
||||||
},
|
},
|
||||||
default: fieldSchema?.['x-component-props']?.['linkageFromForm'],
|
default: fieldSchema?.['x-component-props']?.['linkageFromForm'],
|
||||||
},
|
},
|
||||||
|
@ -59,7 +59,7 @@ export const useIterationVariable = ({
|
|||||||
blockForm?: any;
|
blockForm?: any;
|
||||||
collectionField: any;
|
collectionField: any;
|
||||||
operator?: any;
|
operator?: any;
|
||||||
schema: any;
|
schema?: any;
|
||||||
level?: number;
|
level?: number;
|
||||||
rootCollection?: string;
|
rootCollection?: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user