Skip to content

Commit

Permalink
UIDATIMP-1686: Replace _/proxy/tenants/${tenant}/modules with `stri…
Browse files Browse the repository at this point in the history
…pes.discovery.modules` object
  • Loading branch information
mariia-aloshyna committed Dec 4, 2024
1 parent aab1593 commit ecc0be5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 6 additions & 16 deletions src/settings/MatchProfiles/MatchProfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/utils/fetchJsonShemas.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
13 changes: 5 additions & 8 deletions src/utils/tests/fetchJsonSchemas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit ecc0be5

Please sign in to comment.