From ecc0be56ec777519cbd9f42b0ac94363bca017e6 Mon Sep 17 00:00:00 2001 From: Mariia_Aloshyna Date: Wed, 4 Dec 2024 13:52:59 +0200 Subject: [PATCH] UIDATIMP-1686: Replace `_/proxy/tenants/${tenant}/modules` with `stripes.discovery.modules` object --- CHANGELOG.md | 1 + src/settings/MatchProfiles/MatchProfiles.js | 22 ++++++--------------- src/utils/fetchJsonShemas.js | 4 ++-- src/utils/tests/fetchJsonSchemas.test.js | 13 +++++------- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c54c1ed..3612692b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Bugs fixed: * Allow central tenant to create action profile for Orders and Invoices. (UIDATIMP-1679) * Allow central tenant to create filed mapping profile for Orders and Invoices. (UIDATIMP-1685) +* Replace `_/proxy/tenants/${tenant}/modules` with `stripes.discovery.modules` object. (UIDATIMP-1686) ## [8.0.2](https://github.com/folio-org/ui-data-import/tree/v8.0.2) (2024-11-21) diff --git a/src/settings/MatchProfiles/MatchProfiles.js b/src/settings/MatchProfiles/MatchProfiles.js index 91e7d0f5d..fc4ba3b1d 100644 --- a/src/settings/MatchProfiles/MatchProfiles.js +++ b/src/settings/MatchProfiles/MatchProfiles.js @@ -237,16 +237,6 @@ export class MatchProfiles extends Component { staticFallback: { params: {} }, }, }, - modules: { - type: 'okapi', - path: (queryParams, pathComponents, resourceData, logger, props) => { - const { stripes: { okapi: { tenant } } } = props; - - return `_/proxy/tenants/${tenant}/modules`; - }, - throwErrors: false, - GET: { params: { full: true } }, - }, }); static propTypes = { @@ -308,17 +298,17 @@ export class MatchProfiles extends Component { }; async componentDidUpdate(prevProps) { - if (!isEqual(prevProps.resources.modules, this.props.resources.modules) - && !isEmpty(this.props.resources.modules.records)) { + if (!isEqual(prevProps.stripes.discovery.modules, this.props.stripes.discovery.modules) + && !isEmpty(this.props.stripes.discovery.modules)) { const { stripes, stripes: { okapi }, - resources: { modules: { records } }, + stripes: { discovery: { modules } }, } = this.props; - const inventoryModuleVersion = getModuleVersion(records, 'Inventory Storage Module'); - const ordersModuleVersion = getModuleVersion(records, 'Orders Business Logic Module'); - const invoiceModuleVersion = getModuleVersion(records, 'Invoice business logic module'); + const inventoryModuleVersion = getModuleVersion(modules, 'Inventory Storage Module'); + const ordersModuleVersion = getModuleVersion(modules, 'Orders Business Logic Module'); + const invoiceModuleVersion = getModuleVersion(modules, 'Invoice business logic module'); const requestsToInstance = INSTANCE_RESOURCE_PATHS.map(path => fetchJsonSchema(path, inventoryModuleVersion, okapi)); const requestsToHoldings = HOLDINGS_RESOURCE_PATHS.map(path => fetchJsonSchema(path, inventoryModuleVersion, okapi)); diff --git a/src/utils/fetchJsonShemas.js b/src/utils/fetchJsonShemas.js index dadde6408..4a6ad17c8 100644 --- a/src/utils/fetchJsonShemas.js +++ b/src/utils/fetchJsonShemas.js @@ -1,7 +1,7 @@ export const getModuleVersion = (modules, moduleName) => { - const version = modules.find(module => module.name === moduleName); + const version = Object.keys(modules).find(key => modules[key] === moduleName); - return version ? version.id : undefined; + return version || undefined; }; export const fetchJsonSchema = async (path, module, okapi) => { diff --git a/src/utils/tests/fetchJsonSchemas.test.js b/src/utils/tests/fetchJsonSchemas.test.js index 59d021a6f..0b8637684 100644 --- a/src/utils/tests/fetchJsonSchemas.test.js +++ b/src/utils/tests/fetchJsonSchemas.test.js @@ -9,15 +9,12 @@ import { STATUS_CODES } from '../constants'; describe('getModuleVersion function', () => { it('returns module version of a module with given name', () => { - const testModules = [{ - name: 'module1', - id: 'testId1', - }, { - name: 'module2', - id: 'testId2', - }]; + const testModules = { + testId1: 'module1', + testId2: 'module2', + }; - expect(getModuleVersion(testModules, 'module2')).toBe(testModules[1].id); + expect(getModuleVersion(testModules, 'module2')).toBe('testId2'); expect(getModuleVersion(testModules, 'module3')).toBeUndefined(); }); });