From 89938191a329d33a2e3fb1f4c7abfe7c817af5e5 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Fri, 5 May 2023 10:59:33 +0800 Subject: [PATCH] fix(linkage-rule): condition variable field is allow select To many association fields (#1798) * fix: linkage rule condiction variables allow select to manyassociation field * fix: linkage rule condiction variables filter * fix: linkage rule condiction variables filter --- .../client/src/schema-component/antd/form-v2/utils.tsx | 4 +++- .../client/src/schema-component/common/utils/uitls.tsx | 2 +- .../LinkageRules/FilterDynamicComponent.tsx | 2 +- .../src/schema-settings/LinkageRules/Variables.tsx | 9 +++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-v2/utils.tsx b/packages/core/client/src/schema-component/antd/form-v2/utils.tsx index 6669d7ed72..734fe432ab 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/utils.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/utils.tsx @@ -62,7 +62,9 @@ export const linkageMergeAction = ({ operator, value }, field, condition, values try { const result = evaluate(value.result || value.value, { ...scope, now: () => new Date().toString() }); valueResult.push(result); - } catch (error) {} + } catch (error) { + console.log(error); + } } else if (value?.mode === 'constant') { valueResult.push(value?.value || value); } else { diff --git a/packages/core/client/src/schema-component/common/utils/uitls.tsx b/packages/core/client/src/schema-component/common/utils/uitls.tsx index ea241c152d..bf9288f808 100644 --- a/packages/core/client/src/schema-component/common/utils/uitls.tsx +++ b/packages/core/client/src/schema-component/common/utils/uitls.tsx @@ -61,7 +61,7 @@ const getValue = (str: string, values) => { const regex = /{{(.*?)}}/; const matches = str?.match?.(regex); if (matches) { - return getVariableValue(str, values); + return getVariableValue(str, flat(values)); } else { return str; } diff --git a/packages/core/client/src/schema-settings/LinkageRules/FilterDynamicComponent.tsx b/packages/core/client/src/schema-settings/LinkageRules/FilterDynamicComponent.tsx index 4b354ee08a..00dc390ada 100644 --- a/packages/core/client/src/schema-settings/LinkageRules/FilterDynamicComponent.tsx +++ b/packages/core/client/src/schema-settings/LinkageRules/FilterDynamicComponent.tsx @@ -11,7 +11,7 @@ type Props = { export function FilterDynamicComponent(props: Props) { const { value, onChange, renderSchemaComponent, collectionName } = props; - const scope = useVariableOptions(collectionName); + const scope = useVariableOptions(collectionName, ['o2m', 'm2m']); return ( {renderSchemaComponent()} diff --git a/packages/core/client/src/schema-settings/LinkageRules/Variables.tsx b/packages/core/client/src/schema-settings/LinkageRules/Variables.tsx index db9a79c5fe..d095814e2b 100644 --- a/packages/core/client/src/schema-settings/LinkageRules/Variables.tsx +++ b/packages/core/client/src/schema-settings/LinkageRules/Variables.tsx @@ -2,6 +2,7 @@ import { useCompile } from '../../schema-component'; import { useCollectionManager, useCollection } from '../../collection-manager'; const supportsType = [ + 'id', 'checkbox', 'number', 'percent', @@ -24,7 +25,7 @@ const supportsType = [ 'o2m', 'm2m', ]; -const useVariableTypes = (currentCollection) => { +const useVariableTypes = (currentCollection, excludes = []) => { const { getCollectionFields, getInterface, getCollection } = useCollectionManager(); const collection = getCollection(currentCollection); const fields = getCollectionFields(currentCollection); @@ -34,7 +35,7 @@ const useVariableTypes = (currentCollection) => { value: currentCollection, options() { const field2option = (field, depth) => { - if (!field.interface || !supportsType.includes(field.interface)) { + if (!field.interface || !supportsType.filter((v) => !excludes.includes(v)).includes(field.interface)) { return; } const fieldInterface = getInterface(field.interface); @@ -92,9 +93,9 @@ const useVariableTypes = (currentCollection) => { ]; }; -export function useVariableOptions(collectionName) { +export function useVariableOptions(collectionName, excludes?) { const compile = useCompile(); - const options = useVariableTypes(collectionName).map((item) => { + const options = useVariableTypes(collectionName, excludes).map((item) => { const options = typeof item.options === 'function' ? item.options() : item.options; return { label: compile(item.title),