diff --git a/CHANGELOG.md b/CHANGELOG.md index a8cfdaef4..ffe26941c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * UX Consistency: HTML page title display when third pane (detail record) displays. Refs UIOR-1202. * *BREAKING* Settings - implement Routing list configuration. Refs UIOR-1249. * *BREAKING* Implement central ordering settings for receiving search configuration. Refs UIOR-1232. +* *BREAKING* Apply changes in the fund schema for the locations field. Refs UIOR-1251. ## [6.0.2](https://github.com/folio-org/ui-orders/tree/v6.0.2) (2024-04-01) [Full Changelog](https://github.com/folio-org/ui-orders/compare/v6.0.1...v6.0.2) diff --git a/package.json b/package.json index 5869e503e..52a2aefc8 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "finance.budgets": "1.3 2.0", "finance.exchange-rate": "1.0", "finance.expense-classes": "2.0 3.0", - "finance.funds": "1.0 2.0", + "finance.funds": "3.0", "finance.transactions": "4.0 5.0", "holdings-storage": "4.4 5.0 6.0", "identifier-types": "1.2", diff --git a/src/common/utils/locationsRestrictedFunds.js b/src/common/utils/locationsRestrictedFunds.js index 2b398d06c..f2ef03000 100644 --- a/src/common/utils/locationsRestrictedFunds.js +++ b/src/common/utils/locationsRestrictedFunds.js @@ -10,7 +10,9 @@ import partition from 'lodash/partition'; export const filterFundsRestrictedByLocations = (locationIds, funds) => { if (!locationIds?.length) return funds; - const filteredFunds = funds.filter(({ restrictByLocations, locationIds: fundLocationIds }) => { + const filteredFunds = funds.filter(({ restrictByLocations, locations }) => { + const fundLocationIds = locations?.map(({ locationId }) => locationId); + return !restrictByLocations || (intersection(locationIds, fundLocationIds).length > 0); }); @@ -32,7 +34,7 @@ export const filterLocationsByRestrictedFunds = (funds, locations, includeLocati const validLocationSet = new Set( restrictedFunds - .flatMap(({ locationIds }) => locationIds) + .flatMap(({ locations: fundLocations }) => fundLocations.map(({ locationId }) => locationId)) .concat(includeLocationIds), ); const validLocations = locations.filter(({ id }) => validLocationSet.has(id)); @@ -53,7 +55,9 @@ export const filterHoldingsByRestrictedFunds = (funds, holdings, includeHoldingI if (!funds?.length || unrestrictedFunds.length) return holdings; - const validLocationSet = new Set(restrictedFunds.flatMap(({ locationIds }) => locationIds)); + const validLocationSet = new Set( + restrictedFunds.flatMap(({ locations: fundLocations }) => fundLocations.map(({ locationId }) => locationId)), + ); const persistedHoldingIdsSet = new Set(includeHoldingIds); const validHoldings = holdings.filter(({ id, permanentLocationId }) => { diff --git a/src/common/utils/locationsRestrictedFunds.test.js b/src/common/utils/locationsRestrictedFunds.test.js index 4fa74e471..da6e61cd9 100644 --- a/src/common/utils/locationsRestrictedFunds.test.js +++ b/src/common/utils/locationsRestrictedFunds.test.js @@ -23,17 +23,23 @@ describe('Filtering funds and locations', () => { { id: '1', restrictByLocations: true, - locationIds: ['2', '4'], + locations: [ + { locationId: '2' }, + { locationId: '4' }, + ], }, { id: '2', restrictByLocations: true, - locationIds: ['3', '4'], + locations: [ + { locationId: '3' }, + { locationId: '4' }, + ], }, { id: '3', restrictByLocations: true, - locationIds: ['5'], + locations: [{ locationId: '5' }], }, { id: '4', @@ -66,7 +72,10 @@ describe('Filtering funds and locations', () => { { id: '2', restrictByLocations: true, - locationIds: ['1', '2'], + locations: [ + { locationId: '1' }, + { locationId: '2' }, + ], }, ]; const holdings = [ @@ -83,12 +92,15 @@ describe('Filtering funds and locations', () => { { id: '1', restrictByLocations: true, - locationIds: ['4'], + locations: [{ locationId: '4' }], }, { id: '2', restrictByLocations: true, - locationIds: ['1', '2'], + locations: [ + { locationId: '1' }, + { locationId: '2' }, + ], }, ]; const holdings = [ @@ -114,7 +126,7 @@ describe('Filtering funds and locations', () => { { id: '1', restrictByLocations: true, - locationIds: ['4'], + locations: [{ locationId: '4' }], }, ]; const holdings = [ @@ -153,7 +165,10 @@ describe('Filtering funds and locations', () => { { id: '2', restrictByLocations: true, - locationIds: ['1', '2'], + locationIds: [ + { locationId: '1' }, + { locationId: '2' }, + ], }, ]; const locations = [ @@ -170,12 +185,15 @@ describe('Filtering funds and locations', () => { { id: '1', restrictByLocations: true, - locationIds: ['4'], + locations: [{ locationId: '4' }], }, { id: '2', restrictByLocations: true, - locationIds: ['1', '2'], + locations: [ + { locationId: '1' }, + { locationId: '2' }, + ], }, ]; const locations = [ @@ -193,7 +211,10 @@ describe('Filtering funds and locations', () => { { id: '1', restrictByLocations: true, - locationIds: ['1', '3'], + locations: [ + { locationId: '1' }, + { locationId: '3' }, + ], }, ]; const locations = [