Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIOR-1251 Apply changes in the fund schema for the locations field #1582

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/common/utils/locationsRestrictedFunds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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));
Expand All @@ -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 }) => {
Expand Down
43 changes: 32 additions & 11 deletions src/common/utils/locationsRestrictedFunds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -66,7 +72,10 @@ describe('Filtering funds and locations', () => {
{
id: '2',
restrictByLocations: true,
locationIds: ['1', '2'],
locations: [
{ locationId: '1' },
{ locationId: '2' },
],
},
];
const holdings = [
Expand All @@ -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 = [
Expand All @@ -114,7 +126,7 @@ describe('Filtering funds and locations', () => {
{
id: '1',
restrictByLocations: true,
locationIds: ['4'],
locations: [{ locationId: '4' }],
},
];
const holdings = [
Expand Down Expand Up @@ -153,7 +165,10 @@ describe('Filtering funds and locations', () => {
{
id: '2',
restrictByLocations: true,
locationIds: ['1', '2'],
locationIds: [
{ locationId: '1' },
{ locationId: '2' },
],
},
];
const locations = [
Expand All @@ -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 = [
Expand All @@ -193,7 +211,10 @@ describe('Filtering funds and locations', () => {
{
id: '1',
restrictByLocations: true,
locationIds: ['1', '3'],
locations: [
{ locationId: '1' },
{ locationId: '3' },
],
},
];
const locations = [
Expand Down
Loading