From 653db314747dab2f98e5bdfeb65c44e536ecbf72 Mon Sep 17 00:00:00 2001 From: Dmytro-Melnyshyn <77053927+Dmytro-Melnyshyn@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:16:03 +0300 Subject: [PATCH 1/2] Release v11.0.4 (#2473) --- CHANGELOG.md | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d61aa5eb..8980a21db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,6 @@ ## [11.1.0] (IN PROGRESS) * Remove unused code related to auto-open record detail view. Refs UIIN-2819. -* Replace `all` with the `=` operator to get correct results when using the `All` search option. Refs UIIN-2816. * Keyboard shortcuts modal: Add quickMARC shortcuts to modal. Refs UIIN-2795. * Create new settings for classification type sorting. Refs UIIN-2775. * Add "Display to public" column to receiving history on Holdings. Refs UIIN-2826. @@ -17,6 +16,11 @@ * Jest/RTL: Cover ImportRecord component with unit test. Refs UIIN-2667. * Jest/RTL: Cover MoveHoldingContext component with unit tests. Refs UIIN-2664. +## [11.0.4](https://github.com/folio-org/ui-inventory/tree/v11.0.4) (2024-04-30) +[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v11.0.3...v11.0.4) + +* Replace `all` with the `=` operator to get correct results when using the `All` search option. Refs UIIN-2816. + ## [11.0.3](https://github.com/folio-org/ui-inventory/tree/v11.0.3) (2024-04-26) [Full Changelog](https://github.com/folio-org/ui-inventory/compare/v11.0.2...v11.0.3) diff --git a/package.json b/package.json index 7cfe8c5db..7da61052d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@folio/inventory", - "version": "11.0.3", + "version": "11.0.4", "description": "Inventory manager", "repository": "folio-org/ui-inventory", "publishConfig": { From bf8021ea9ceb3964ab5e9dde0ce05063ff801005 Mon Sep 17 00:00:00 2001 From: Denys Bohdan Date: Thu, 2 May 2024 16:24:57 +0200 Subject: [PATCH 2/2] UIIN-2811 Use consolidated locations endpoint to fetch all locations when in central tenant context. (#2471) --- CHANGELOG.md | 1 + package.json | 3 +- .../useLocationsForTenants.js | 22 +++++-- .../useLocationsForTenants.test.js | 65 +++++++++++++++---- src/providers/DataProvider.js | 4 ++ 5 files changed, 78 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8980a21db..22de8b30b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Jest/RTL: Cover InstancePlugin component with unit tests. Refs UIIN-2668. * Jest/RTL: Cover ImportRecord component with unit test. Refs UIIN-2667. * Jest/RTL: Cover MoveHoldingContext component with unit tests. Refs UIIN-2664. +* Use consolidated locations endpoint to fetch all locations when in central tenant context. Refs UIIN-2811. ## [11.0.4](https://github.com/folio-org/ui-inventory/tree/v11.0.4) (2024-04-30) [Full Changelog](https://github.com/folio-org/ui-inventory/compare/v11.0.3...v11.0.4) diff --git a/package.json b/package.json index 7da61052d..99b084da0 100644 --- a/package.json +++ b/package.json @@ -569,7 +569,8 @@ "browse.subjects.instances.collection.get", "browse.classification-numbers.instances.collection.get", "perms.users.get", - "inventory-storage.bound-with-parts.collection.get" + "inventory-storage.bound-with-parts.collection.get", + "consortium-search.locations.collection.get" ], "visible": true }, diff --git a/src/hooks/useLocationsForTenants/useLocationsForTenants.js b/src/hooks/useLocationsForTenants/useLocationsForTenants.js index 05a0e738b..04cc6c9c1 100644 --- a/src/hooks/useLocationsForTenants/useLocationsForTenants.js +++ b/src/hooks/useLocationsForTenants/useLocationsForTenants.js @@ -1,9 +1,13 @@ -import { useQueries } from 'react-query'; +import { + useQueries, + useQuery, +} from 'react-query'; import { useNamespace, useOkapiKy, useStripes, + checkIfUserInCentralTenant, } from '@folio/stripes/core'; import { isUserInConsortiumMode } from '../../utils'; @@ -18,9 +22,11 @@ const useLocationsForTenants = ({ tenantIds = [] }) => { const stripes = useStripes(); const ky = useOkapiKy(); + const isUserInCentralTenant = checkIfUserInCentralTenant(stripes); + const queries = useQueries(tenantIds.map(tenantId => { return { - enabled: Boolean(tenantIds.length && isUserInConsortiumMode(stripes)), + enabled: Boolean(tenantIds.length && isUserInConsortiumMode(stripes) && !isUserInCentralTenant), queryKey: [namespace, 'locations', tenantId], queryFn: () => ky.get('locations', { searchParams: { @@ -38,10 +44,18 @@ const useLocationsForTenants = ({ tenantIds = [] }) => { }; })); - const locationsFromAllTenants = queries.map(({ data }) => data?.locations).filter(Boolean).flat(); + const { data: consolidatedLocations } = useQuery({ + queryKey: [namespace, 'consolidatedLocations'], + queryFn: () => ky.get('search/consortium/locations').json(), + enabled: Boolean(isUserInConsortiumMode(stripes) && isUserInCentralTenant), + }); + + const locationsFromAllTenants = isUserInCentralTenant + ? consolidatedLocations?.locations + : queries.map(({ data }) => data?.locations).filter(Boolean).flat(); return { - data: locationsFromAllTenants, + data: locationsFromAllTenants || [], isLoading: queries.some(({ isFetching }) => isFetching), }; }; diff --git a/src/hooks/useLocationsForTenants/useLocationsForTenants.test.js b/src/hooks/useLocationsForTenants/useLocationsForTenants.test.js index 455d198c7..d4cdd7058 100644 --- a/src/hooks/useLocationsForTenants/useLocationsForTenants.test.js +++ b/src/hooks/useLocationsForTenants/useLocationsForTenants.test.js @@ -3,7 +3,10 @@ import { QueryClientProvider, } from 'react-query'; -import { useOkapiKy } from '@folio/stripes/core'; +import { + useOkapiKy, + checkIfUserInCentralTenant, +} from '@folio/stripes/core'; import { renderHook, @@ -37,22 +40,60 @@ describe('useLocationsForTenants', () => { const tenantIds = ['cs00000int', 'cs00000int_0002']; - it('should fetch locations of all tenants', async () => { - const { result } = renderHook(() => useLocationsForTenants({ tenantIds }), { wrapper }); + describe('when user is in a member tenant', () => { + it('should fetch locations of all tenants via multiple requests', async () => { + const { result } = renderHook(() => useLocationsForTenants({ tenantIds }), { wrapper }); + + await act(() => !result.current.isLoading); + + expect(mockGet.mock.calls[0][0]).toBe('locations'); + expect(mockGet.mock.calls[1][0]).toBe('locations'); + expect(result.current.data).toEqual([ + { id: 'location-id' }, + { id: 'location-id' }, + ]); + }); + + it('should not call consolidated locations endpoint', async () => { + const { result } = renderHook(() => useLocationsForTenants({ tenantIds }), { wrapper }); - await act(() => !result.current.isLoading); + await act(() => !result.current.isLoading); - expect(result.current.data).toEqual([ - { id: 'location-id' }, - { id: 'location-id' }, - ]); + expect(mockGet).not.toHaveBeenCalledWith('search/consortium/locations'); + }); + + describe('when tenantIds is empty', () => { + it('should not make a request', () => { + renderHook(() => useLocationsForTenants({ tenantIds: [] }), { wrapper }); + + expect(mockGet).not.toHaveBeenCalled(); + }); + }); }); - describe('when tenantIds is empty', () => { - it('should not make a request', () => { - renderHook(() => useLocationsForTenants({ tenantIds: [] }), { wrapper }); + describe('when user is in a central tenant', () => { + beforeEach(() => { + checkIfUserInCentralTenant.mockClear().mockReturnValue(true); + }); + + it('should fetch locations of all tenants via consolidated endpoint', async () => { + const { result } = renderHook(() => useLocationsForTenants({ tenantIds }), { wrapper }); + + await act(() => !result.current.isLoading); + + expect(mockGet).toHaveBeenCalledWith('search/consortium/locations'); + + expect(result.current.data).toEqual([ + { id: 'location-id' }, + ]); + }); + + it('should not call multiple locations endpoints', async () => { + const { result } = renderHook(() => useLocationsForTenants({ tenantIds }), { wrapper }); + + await act(() => !result.current.isLoading); - expect(mockGet).not.toHaveBeenCalled(); + expect(mockGet).not.toHaveBeenCalledWith('locations'); }); }); }); diff --git a/src/providers/DataProvider.js b/src/providers/DataProvider.js index 5ded60ae4..5c8b9aa34 100644 --- a/src/providers/DataProvider.js +++ b/src/providers/DataProvider.js @@ -47,6 +47,10 @@ const DataProvider = ({ const { data: locationsOfAllTenants } = useLocationsForTenants({ tenantIds }); useEffect(() => { + if (isUserInConsortiumMode(stripes)) { + return; + } + mutator.locations.GET({ tenant: stripes.okapi.tenant }); }, [stripes.okapi.tenant]);