From 35198b715e949ca76c4c12b5c34d0f47392eeebd Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Tue, 24 Sep 2024 12:29:16 +0800 Subject: [PATCH] fix(variable): should show all collection fields (#5310) --- .../antd/filter/useFilterActionProps.ts | 18 ++++++++++-------- .../VariableInput/hooks/useBaseVariable.tsx | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/filter/useFilterActionProps.ts b/packages/core/client/src/schema-component/antd/filter/useFilterActionProps.ts index 19a8f50a4a..e193e2a2df 100644 --- a/packages/core/client/src/schema-component/antd/filter/useFilterActionProps.ts +++ b/packages/core/client/src/schema-component/antd/filter/useFilterActionProps.ts @@ -21,9 +21,9 @@ export const useGetFilterOptions = () => { const { getCollectionFields } = useCollectionManager_deprecated(); const getFilterFieldOptions = useGetFilterFieldOptions(); - return (collectionName, dataSource?: string) => { + return (collectionName, dataSource?: string, usedInVariable?: boolean) => { const fields = getCollectionFields(collectionName, dataSource); - const options = getFilterFieldOptions(fields); + const options = getFilterFieldOptions(fields, usedInVariable); return options; }; }; @@ -39,18 +39,20 @@ export const useGetFilterFieldOptions = () => { const fieldSchema = useFieldSchema(); const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || []; const { getCollectionFields, getInterface } = useCollectionManager_deprecated(); - const field2option = (field, depth) => { + const field2option = (field, depth, usedInVariable?: boolean) => { if (nonfilterable.length && depth === 1 && nonfilterable.includes(field.name)) { return; } if (!field.interface) { return; } + const fieldInterface = getInterface(field.interface); - if (!fieldInterface?.filterable) { + if (!fieldInterface?.filterable && !usedInVariable) { return; } - const { nested, children, operators } = fieldInterface.filterable; + + const { nested, children, operators } = fieldInterface?.filterable || {}; const option = { name: field.name, type: field.type, @@ -80,17 +82,17 @@ export const useGetFilterFieldOptions = () => { } return option; }; - const getOptions = (fields, depth) => { + const getOptions = (fields, depth, usedInVariable?: boolean) => { const options = []; fields.forEach((field) => { - const option = field2option(field, depth); + const option = field2option(field, depth, usedInVariable); if (option) { options.push(option); } }); return options; }; - return (fields) => getOptions(fields, 1); + return (fields, usedInVariable) => getOptions(fields, 1, usedInVariable); }; export const useFilterFieldOptions = (fields) => { diff --git a/packages/core/client/src/schema-settings/VariableInput/hooks/useBaseVariable.tsx b/packages/core/client/src/schema-settings/VariableInput/hooks/useBaseVariable.tsx index ea17da86da..36d3b9793f 100644 --- a/packages/core/client/src/schema-settings/VariableInput/hooks/useBaseVariable.tsx +++ b/packages/core/client/src/schema-settings/VariableInput/hooks/useBaseVariable.tsx @@ -211,8 +211,9 @@ export const useBaseVariable = ({ const target = option.field.target; return new Promise((resolve) => { setTimeout(() => { + const usedInVariable = true; const children = ( - getChildren(returnFields(getFilterOptions(target, dataSource), option), { + getChildren(returnFields(getFilterOptions(target, dataSource, usedInVariable), option), { collectionField, uiSchema, targetFieldSchema,