From 023096b1a9ea6ccae364c81ba93ca32b077ccecc Mon Sep 17 00:00:00 2001 From: Chareice Date: Tue, 12 Mar 2024 15:14:59 +0800 Subject: [PATCH] fix: pagination error in roles collections resourcer --- .../roles-data-sources-collections.ts | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-data-sources-collections.ts b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-data-sources-collections.ts index fd3d2688d2..1eda1661ff 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-data-sources-collections.ts +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-data-sources-collections.ts @@ -22,7 +22,7 @@ const rolesRemoteCollectionsResourcer = { const collectionRepository = new FullDataRepository(dataSource.collectionManager.getCollections()); // all collections - const [collections, count] = await collectionRepository.findAndCount(); + const [collections] = await collectionRepository.findAndCount(); const filterItem = lodash.get(filter, '$and'); const filterByTitle = filterItem?.find((item) => item.title); @@ -45,44 +45,44 @@ const rolesRemoteCollectionsResourcer = { .filter((roleResources) => roleResources.get('usingActionsConfig')) .map((roleResources) => roleResources.get('name')); + const filtedCollections = collections.filter((collection) => { + return ( + (!filterTitle || lodash.get(collection, 'options.title')?.toLowerCase().includes(filterTitle)) && + (!filterName || collection.options.name.toLowerCase().includes(filterName)) + ); + }); + const items = lodash.sortBy( - collections - .filter((collection) => { - return ( - (!filterTitle || lodash.get(collection, 'options.title')?.toLowerCase().includes(filterTitle)) && - (!filterName || collection.options.name.toLowerCase().includes(filterName)) - ); - }) - .map((collection, i) => { - const collectionName = collection.options.name; - const exists = roleResourcesNames.includes(collectionName); + filtedCollections.map((collection, i) => { + const collectionName = collection.options.name; + const exists = roleResourcesNames.includes(collectionName); - const usingConfig: UsingConfigType = roleResourceActionResourceNames.includes(collectionName) - ? 'resourceAction' - : 'strategy'; + const usingConfig: UsingConfigType = roleResourceActionResourceNames.includes(collectionName) + ? 'resourceAction' + : 'strategy'; - return { - type: 'collection', - name: collectionName, - collectionName, - title: collection.options.uiSchema?.title || collection.options.title, - roleName: role, - usingConfig, - exists, - fields: [...collection.fields.values()].map((field) => { - return field.options; - }), - }; - }), + return { + type: 'collection', + name: collectionName, + collectionName, + title: collection.options.uiSchema?.title || collection.options.title, + roleName: role, + usingConfig, + exists, + fields: [...collection.fields.values()].map((field) => { + return field.options; + }), + }; + }), 'name', ); ctx.body = { - count, + count: filtedCollections.length, rows: items, page: Number(page), pageSize: Number(pageSize), - totalPage: totalPage(count, pageSize), + totalPage: totalPage(filtedCollections.length, pageSize), }; await next();