From a266367105983bca10c0ca8a567341d9a206b751 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Fri, 7 Jul 2023 09:31:00 +0800 Subject: [PATCH] fix: current object variavle can not be selected (#2201) --- .../EnableChildCollections/DynamicComponent.tsx | 5 ++++- .../VariableInput/hooks/useIterationVariable.ts | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/core/client/src/schema-settings/EnableChildCollections/DynamicComponent.tsx b/packages/core/client/src/schema-settings/EnableChildCollections/DynamicComponent.tsx index ee347bdfa..552af8b87 100644 --- a/packages/core/client/src/schema-settings/EnableChildCollections/DynamicComponent.tsx +++ b/packages/core/client/src/schema-settings/EnableChildCollections/DynamicComponent.tsx @@ -18,7 +18,10 @@ export const ChildDynamicComponent = observer( }); const compile = useCompile(); - const result = useMemo(() => [formVariabele, iterationVariabele].filter(Boolean), [formVariabele]); + const result = useMemo( + () => [formVariabele, iterationVariabele].filter(Boolean), + [formVariabele, iterationVariabele], + ); const scope = compile(result); useEffect(() => { onChange(fieldSchema.default); diff --git a/packages/core/client/src/schema-settings/VariableInput/hooks/useIterationVariable.ts b/packages/core/client/src/schema-settings/VariableInput/hooks/useIterationVariable.ts index e980da8f0..3c9a563d9 100644 --- a/packages/core/client/src/schema-settings/VariableInput/hooks/useIterationVariable.ts +++ b/packages/core/client/src/schema-settings/VariableInput/hooks/useIterationVariable.ts @@ -1,5 +1,5 @@ -import { Schema } from '@formily/react'; import { useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; import { useCompile, useGetFilterOptions } from '../../../schema-component'; import { FieldOption, Option } from '../type'; @@ -27,7 +27,7 @@ const getChildren = ( label: compile(option.title), depth, // 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; level?: number; }) => { + const { t } = useTranslation(); const compile = useCompile(); const getFilterOptions = useGetFilterOptions(); const loadChildren = (option: any): Promise => { @@ -103,15 +104,14 @@ export const useIterationVariable = ({ }, 5); }); }; - + const label = t('Current object'); const result = useMemo(() => { return ( blockForm && currentCollection !== rootCollection && { - label: `{{t("Current object")}}`, + label: label, value: '$iteration', key: '$iteration', - children: [], isLeaf: false, field: { target: currentCollection,