From d705877eec5b3ad82fdfbcb9856d3f3243660698 Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 15 Oct 2024 09:23:24 +0800 Subject: [PATCH] fix(workflow): workflow node variables do not display inherited collection fields (#5415) * fix: missing fields in the inherited table * fix(client): fix hidden collection * refactor(client): add new api to get all fields on collection manager --------- Co-authored-by: mytharcher --- .../src/data-source/collection/Collection.ts | 4 ++++ .../data-source/collection/CollectionManager.ts | 4 ++++ .../antd/appends-tree-select/AppendsTreeSelect.tsx | 14 ++++++-------- .../plugin-workflow/src/client/variable.tsx | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/core/client/src/data-source/collection/Collection.ts b/packages/core/client/src/data-source/collection/Collection.ts index 977a6769c2..7eaf1daf9f 100644 --- a/packages/core/client/src/data-source/collection/Collection.ts +++ b/packages/core/client/src/data-source/collection/Collection.ts @@ -250,6 +250,10 @@ export class Collection { return predicate ? filter(this.fields, predicate) : this.fields; } + getAllFields(predicate?: GetCollectionFieldPredicate) { + return this.getFields(predicate); + } + protected getFieldsMap() { if (!this.fieldsMap) { this.fieldsMap = this.getFields().reduce((memo, field) => { diff --git a/packages/core/client/src/data-source/collection/CollectionManager.ts b/packages/core/client/src/data-source/collection/CollectionManager.ts index 0d9265973f..cb85139999 100644 --- a/packages/core/client/src/data-source/collection/CollectionManager.ts +++ b/packages/core/client/src/data-source/collection/CollectionManager.ts @@ -140,6 +140,10 @@ export class CollectionManager { return this.getCollection(collectionName)?.getFields(predicate) || []; } + getCollectionAllFields(collectionName: string, predicate?: GetCollectionFieldPredicate) { + return this.getCollection(collectionName)?.getAllFields(predicate) || []; + } + /** * @example * getFilterByTK('users', { id: 1 }); // 1 diff --git a/packages/core/client/src/schema-component/antd/appends-tree-select/AppendsTreeSelect.tsx b/packages/core/client/src/schema-component/antd/appends-tree-select/AppendsTreeSelect.tsx index 42e7e2daf0..e62aea2aac 100644 --- a/packages/core/client/src/schema-component/antd/appends-tree-select/AppendsTreeSelect.tsx +++ b/packages/core/client/src/schema-component/antd/appends-tree-select/AppendsTreeSelect.tsx @@ -12,13 +12,7 @@ import { Tag, TreeSelect } from 'antd'; import type { DefaultOptionType, TreeSelectProps } from 'rc-tree-select/es/TreeSelect'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { - CollectionFieldOptions_deprecated, - parseCollectionName, - useApp, - useCollectionManager_deprecated, - useCompile, -} from '../../..'; +import { CollectionFieldOptions_deprecated, parseCollectionName, useApp, useCompile } from '../../..'; export type AppendsTreeSelectProps = { value: string[] | string; @@ -106,7 +100,11 @@ export const AppendsTreeSelect: React.FC { + const instance = collectionManager.getCollection(name); + // NOTE: condition for compatibility with hidden collections like "attachments" + return instance ? instance.getAllFields(predicate) : []; + }; const treeData = Object.values(optionsMap); const value: string | DefaultOptionType[] = useMemo(() => { if (props.multiple) { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx index 30ed780432..e86e19287c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx @@ -503,7 +503,7 @@ export function useGetCollectionFields(dataSourceName?) { const app = useApp(); const { collectionManager } = app.dataSourceManager.getDataSource(dataSourceName); - return useCallback((collectionName) => collectionManager.getCollectionFields(collectionName), [collectionManager]); + return useCallback((collectionName) => collectionManager.getCollectionAllFields(collectionName), [collectionManager]); } export function WorkflowVariableInput({ variableOptions, ...props }): JSX.Element {