fix: current object variavle can not be selected (#2201)

This commit is contained in:
katherinehhh 2023-07-07 09:31:00 +08:00 committed by GitHub
parent 44adf53c11
commit a266367105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -18,7 +18,10 @@ export const ChildDynamicComponent = observer(
}); });
const compile = useCompile(); const compile = useCompile();
const result = useMemo(() => [formVariabele, iterationVariabele].filter(Boolean), [formVariabele]); const result = useMemo(
() => [formVariabele, iterationVariabele].filter(Boolean),
[formVariabele, iterationVariabele],
);
const scope = compile(result); const scope = compile(result);
useEffect(() => { useEffect(() => {
onChange(fieldSchema.default); onChange(fieldSchema.default);

View File

@ -1,5 +1,5 @@
import { Schema } from '@formily/react';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useCompile, useGetFilterOptions } from '../../../schema-component'; import { useCompile, useGetFilterOptions } from '../../../schema-component';
import { FieldOption, Option } from '../type'; import { FieldOption, Option } from '../type';
@ -27,7 +27,7 @@ const getChildren = (
label: compile(option.title), label: compile(option.title),
depth, depth,
// TODO: 现在是通过组件的名称来过滤能够被选择的选项,这样的坏处是不够精确,后续可以优化 // TODO: 现在是通过组件的名称来过滤能够被选择的选项,这样的坏处是不够精确,后续可以优化
disabled: schema?.['x-component'] !== option.schema?.['x-component'], disabled: schema && schema?.['x-component'] !== option.schema?.['x-component'],
}; };
} }
@ -64,6 +64,7 @@ export const useIterationVariable = ({
schema?: any; schema?: any;
level?: number; level?: number;
}) => { }) => {
const { t } = useTranslation();
const compile = useCompile(); const compile = useCompile();
const getFilterOptions = useGetFilterOptions(); const getFilterOptions = useGetFilterOptions();
const loadChildren = (option: any): Promise<void> => { const loadChildren = (option: any): Promise<void> => {
@ -103,15 +104,14 @@ export const useIterationVariable = ({
}, 5); }, 5);
}); });
}; };
const label = t('Current object');
const result = useMemo(() => { const result = useMemo(() => {
return ( return (
blockForm && blockForm &&
currentCollection !== rootCollection && { currentCollection !== rootCollection && {
label: `{{t("Current object")}}`, label: label,
value: '$iteration', value: '$iteration',
key: '$iteration', key: '$iteration',
children: [],
isLeaf: false, isLeaf: false,
field: { field: {
target: currentCollection, target: currentCollection,