diff --git a/CHANGELOG.md b/CHANGELOG.md index c17da097..dcde2ace 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ * Review and cleanup Module Descriptor. Refs UIREQ-1156. * Add `tlr.settings.get` permission. Refs UIREQ-1169. * Add `mod-settings.global.read.circulation` permission. Refs UIREQ-1170. +* *BREAKING* Migrate to new `mod-circulation-bff` endpoints. Refs UIREQ-1134. ## [9.1.2] (https://github.com/folio-org/ui-requests/tree/v9.1.2) (2024-09-13) [Full Changelog](https://github.com/folio-org/ui-requests/compare/v9.1.1...v9.1.2) diff --git a/package.json b/package.json index 51e5bd8c..5426ec7f 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "pick-slips": "0.1", "search-slips": "0.1", "automated-patron-blocks": "0.1", - "instance-items": "0.1" + "circulation-bff-requests": "1.0" }, "permissionSets": [ { @@ -58,7 +58,7 @@ "subPermissions": [ "circulation.requests.queue.collection.get", "circulation.requests.queue.reorder.collection.post", - "circulation.requests.allowed-service-points.get", + "circulation-bff.requests.allowed-service-points.get", "circulation.rules.request-policy.get" ] }, @@ -121,8 +121,7 @@ "subPermissions": [ "ui-requests.view", "automated-patron-blocks.collection.get", - "circulation.requests.item.post", - "circulation.requests.allowed-service-points.get", + "circulation-bff.requests.allowed-service-points.get", "circulation-storage.requests.item.post", "circulation-storage.request-preferences.collection.get", "circulation-storage.staff-slips.collection.get", @@ -130,9 +129,8 @@ "circulation.search-slips.get", "circulation.print-events-entry.item.post", "inventory-storage.locations.item.get", - "circulation.items-by-instance.get", - "tlr.ecs-tlr-allowed-service-points.get", - "tlr.ecs-tlr.post" + "circulation-bff.requests.search-instances.get", + "circulation-bff.requests.post" ], "visible": true }, @@ -144,7 +142,7 @@ "circulation.pick-slips.get", "circulation.search-slips.get", "circulation.requests.item.put", - "circulation.requests.allowed-service-points.get", + "circulation-bff.requests.allowed-service-points.get", "circulation.print-events-entry.item.post", "circulation-storage.staff-slips.collection.get", "circulation-storage.requests.collection.delete", diff --git a/src/ItemsDialog.js b/src/ItemsDialog.js index d6db7840..1dd77754 100644 --- a/src/ItemsDialog.js +++ b/src/ItemsDialog.js @@ -220,7 +220,7 @@ ItemsDialog.manifest = { items: { type: 'okapi', records: 'items', - path: 'circulation/items-by-instance', + path: 'circulation-bff/requests/search-instances', accumulate: true, fetch: false, }, diff --git a/src/MoveRequestManager.js b/src/MoveRequestManager.js index 027b5add..c73c0db6 100644 --- a/src/MoveRequestManager.js +++ b/src/MoveRequestManager.js @@ -156,7 +156,7 @@ class MoveRequestManager extends React.Component { token: stripes.store.getState().okapi.token, }) }; - const url = `${stripes.okapi.url}/circulation/requests/allowed-service-points?requestId=${request.id}&itemId=${selectedItem.id}&operation=${REQUEST_OPERATIONS.MOVE}`; + const url = `${stripes.okapi.url}/circulation-bff/requests/allowed-service-points?requestId=${request.id}&itemId=${selectedItem.id}&operation=${REQUEST_OPERATIONS.MOVE}`; this.setState({ isRequestTypesLoading: true, diff --git a/src/MoveRequestManager.test.js b/src/MoveRequestManager.test.js index 0629d5ff..7aa4518a 100644 --- a/src/MoveRequestManager.test.js +++ b/src/MoveRequestManager.test.js @@ -188,7 +188,7 @@ describe('MoveRequestManager', () => { }); it('should trigger fetch with correct argument', () => { - const expectedUrl = `${basicProps.stripes.okapi.url}/circulation/requests/allowed-service-points?requestId=${basicProps.request.id}&itemId=${selectedItem.id}&operation=${REQUEST_OPERATIONS.MOVE}`; + const expectedUrl = `${basicProps.stripes.okapi.url}/circulation-bff/requests/allowed-service-points?requestId=${basicProps.request.id}&itemId=${selectedItem.id}&operation=${REQUEST_OPERATIONS.MOVE}`; expect(global.fetch).toHaveBeenCalledWith(expectedUrl, {}); }); diff --git a/src/constants.js b/src/constants.js index c328eca4..a4d7c6ae 100644 --- a/src/constants.js +++ b/src/constants.js @@ -424,18 +424,3 @@ export const SETTINGS_SCOPES = { export const SETTINGS_KEYS = { GENERAL_TLR: 'generalTlr', }; - -export const REQUEST_ACTION_NAMES = { - CREATE_REQUEST: 'CREATE_REQUEST', - GET_SERVICE_POINTS: 'GET_SERVICE_POINTS', -}; - -export const SINGLE_TENANT_URLS = { - [REQUEST_ACTION_NAMES.CREATE_REQUEST]: 'circulation/requests', - [REQUEST_ACTION_NAMES.GET_SERVICE_POINTS]: 'circulation/requests/allowed-service-points', -}; - -export const CENTRAL_TENANT_URLS = { - [REQUEST_ACTION_NAMES.CREATE_REQUEST]: 'tlr/ecs-tlr', - [REQUEST_ACTION_NAMES.GET_SERVICE_POINTS]: 'tlr/allowed-service-points', -}; diff --git a/src/routes/RequestsRoute.js b/src/routes/RequestsRoute.js index 4aa0e895..178b3015 100644 --- a/src/routes/RequestsRoute.js +++ b/src/routes/RequestsRoute.js @@ -3,7 +3,6 @@ import { isEmpty, isArray, size, - unset, cloneDeep, } from 'lodash'; import React from 'react'; @@ -70,8 +69,6 @@ import { SETTINGS_SCOPES, SETTINGS_KEYS, ITEM_QUERIES, - REQUEST_ACTION_NAMES, - CENTRAL_TENANT_URLS, PRINT_DETAILS_COLUMNS, RESOURCE_TYPES, requestFilterTypes, @@ -89,7 +86,6 @@ import { getSelectedSlipDataMulti, selectedRowsNonPrintable, getNextSelectedRowsState, - getRequestUrl, isMultiDataTenant, } from '../utils'; import packageInfo from '../../package'; @@ -167,12 +163,12 @@ export const urls = { query = stringify({ query }); - return `circulation/items-by-instance?${query}`; + return `circulation-bff/requests/search-instances?${query}`; }, instance: (value) => { const query = stringify({ query: getInstanceQueryString(value) }); - return `circulation/items-by-instance?${query}`; + return `circulation-bff/requests/search-instances?${query}`; }, loan: (value) => { const query = stringify({ query: `(itemId=="${value}") and status.name==Open` }); @@ -208,14 +204,12 @@ export const urls = { instanceId, requestId, operation, - }, idType, stripes) => { - const url = getRequestUrl(REQUEST_ACTION_NAMES.GET_SERVICE_POINTS, stripes); - + }) => { if (requestId) { - return `${url}?operation=${operation}&requestId=${requestId}`; + return `circulation-bff/requests/allowed-service-points?operation=${operation}&requestId=${requestId}`; } - let requestUrl = `${url}?requesterId=${requesterId}&operation=${operation}`; + let requestUrl = `circulation-bff/requests/allowed-service-points?requesterId=${requesterId}&operation=${operation}`; if (itemId) { requestUrl = `${requestUrl}&itemId=${itemId}`; @@ -369,9 +363,9 @@ class RequestsRoute extends React.Component { staticFallback: { params: {} }, }, }, - ecsTlrRecords: { + circulationRequests: { type: 'okapi', - path: CENTRAL_TENANT_URLS[REQUEST_ACTION_NAMES.CREATE_REQUEST], + path: 'circulation-bff/requests', fetch: false, throwErrors: false, }, @@ -514,7 +508,7 @@ class RequestsRoute extends React.Component { GET: PropTypes.func, POST: PropTypes.func, }), - ecsTlrRecords: PropTypes.shape({ + circulationRequests: PropTypes.shape({ POST: PropTypes.func, }), reportRecords: PropTypes.shape({ @@ -1109,21 +1103,11 @@ class RequestsRoute extends React.Component { }; create = (requestData) => { - const { stripes } = this.props; const userPersonalData = cloneDeep(requestData?.requester?.personal); - let mutator = this.props.mutator.records; - - if (isMultiDataTenant(stripes) && checkIfUserInCentralTenant(stripes)) { - unset(requestData, 'item'); - unset(requestData, 'requester'); - - mutator = this.props.mutator.ecsTlrRecords; - } - const query = new URLSearchParams(this.props.location.search); const mode = query.get('mode'); - return mutator.POST(requestData) + return this.props.mutator.circulationRequests.POST(requestData) .then((res) => { const { match: { diff --git a/src/routes/RequestsRoute.test.js b/src/routes/RequestsRoute.test.js index f895c1f4..7ef69477 100644 --- a/src/routes/RequestsRoute.test.js +++ b/src/routes/RequestsRoute.test.js @@ -88,8 +88,6 @@ const testIds = { rowCheckbox: 'rowCheckbox', selectRequestCheckbox: 'selectRequestCheckbox', }; -const requestUrl = 'url'; - const intlCache = createIntlCache(); const intl = createIntl( { @@ -117,7 +115,6 @@ jest.mock('../utils', () => ({ extractPickSlipRequestIds: jest.fn(), isMultiDataTenant: jest.fn(), generateUserName: jest.fn(), - getRequestUrl: jest.fn(() => requestUrl), })); jest.mock('./utils', () => ({ ...jest.requireActual('./utils'), @@ -444,6 +441,9 @@ describe('RequestsRoute', () => { GET: jest.fn(), POST: jest.fn().mockResolvedValue(), }, + circulationRequests: { + POST: jest.fn().mockResolvedValue(), + }, reportRecords: { GET: jest.fn().mockReturnValueOnce(mockRecordValues).mockRejectedValue(), reset: jest.fn(), @@ -704,8 +704,7 @@ describe('RequestsRoute', () => { ...defaultProps, mutator: { ...defaultProps.mutator, - records: { - ...defaultProps.mutator.records, + circulationRequests: { POST: jest.fn().mockResolvedValue(response), }, }, @@ -721,7 +720,7 @@ describe('RequestsRoute', () => { fireEvent.click(createRequestButton); - expect(props.mutator.records.POST).toHaveBeenCalledWith(userData); + expect(props.mutator.circulationRequests.POST).toHaveBeenCalledWith(userData); }); it('should redirect to details page', async () => { @@ -756,7 +755,7 @@ describe('RequestsRoute', () => { ...defaultProps, mutator: { ...defaultProps.mutator, - ecsTlrRecords: { + circulationRequests: { POST: jest.fn().mockResolvedValue(response), }, }, @@ -801,7 +800,7 @@ describe('RequestsRoute', () => { fireEvent.click(createRequestButton); - expect(props.mutator.ecsTlrRecords.POST).toHaveBeenCalledWith(userData); + expect(props.mutator.circulationRequests.POST).toHaveBeenCalledWith(userData); }); }); @@ -1662,7 +1661,7 @@ describe('RequestsRoute', () => { }); it('should return correct url', () => { - const expectedResult = `circulation/items-by-instance?${mockedQueryValue}`; + const expectedResult = `circulation-bff/requests/search-instances?${mockedQueryValue}`; expect(queryString).toBe(expectedResult); }); @@ -1685,7 +1684,7 @@ describe('RequestsRoute', () => { }); it('should return correct url', () => { - const expectedResult = `circulation/items-by-instance?${mockedQueryValue}`; + const expectedResult = `circulation-bff/requests/search-instances?${mockedQueryValue}`; expect(queryString).toBe(expectedResult); }); @@ -1715,7 +1714,7 @@ describe('RequestsRoute', () => { }); it('should return correct url', () => { - const expectedResult = `circulation/items-by-instance?${mockedQueryValue}`; + const expectedResult = `circulation-bff/requests/search-instances?${mockedQueryValue}`; expect(queryString).toBe(expectedResult); }); @@ -1832,6 +1831,7 @@ describe('RequestsRoute', () => { const operation = REQUEST_OPERATIONS.CREATE; const itemId = 'itemIdUrl'; const instanceId = 'instanceIdUrl'; + const requestUrl = 'circulation-bff/requests/allowed-service-points'; it('should return url with "itemId"', () => { const expectedResult = `${requestUrl}?requesterId=${requesterId}&operation=${operation}&itemId=${itemId}`; diff --git a/src/utils.js b/src/utils.js index 0dbbf057..cdaf3962 100644 --- a/src/utils.js +++ b/src/utils.js @@ -23,7 +23,6 @@ import { Row, NoValue, } from '@folio/stripes/components'; -import { checkIfUserInCentralTenant } from '@folio/stripes/core'; import { requestTypeOptionMap, @@ -38,8 +37,6 @@ import { DCB_USER, SLIPS_TYPE, REQUEST_ERROR_MESSAGE_TRANSLATION_KEYS, - CENTRAL_TENANT_URLS, - SINGLE_TENANT_URLS, } from './constants'; import css from './requests.css'; @@ -531,14 +528,3 @@ export const getRequester = (proxy, selectedUser) => { return selectedUser; }; - -export const getRequestUrl = (actionName, stripes) => { - const isMultiTenant = isMultiDataTenant(stripes); - const isUserInCentralTenant = checkIfUserInCentralTenant(stripes); - - if (isMultiTenant && isUserInCentralTenant) { - return CENTRAL_TENANT_URLS[actionName]; - } - - return SINGLE_TENANT_URLS[actionName]; -}; diff --git a/src/utils.test.js b/src/utils.test.js index 59b3ec0e..0a30183d 100644 --- a/src/utils.test.js +++ b/src/utils.test.js @@ -3,8 +3,6 @@ import { noop, } from 'lodash'; -import { checkIfUserInCentralTenant } from '@folio/stripes/core'; - import { buildTemplate, createUserHighlightBoxLink, @@ -37,7 +35,6 @@ import { isPrintable, getNextSelectedRowsState, isMultiDataTenant, - getRequestUrl, getRequester, getFullName, } from './utils'; @@ -1130,35 +1127,6 @@ describe('isMultiDataTenant', () => { }); }); -describe('getRequestUrl', () => { - describe('When central tenant is selected', () => { - const stripes = { - hasInterface: () => true, - }; - - checkIfUserInCentralTenant.mockReturnValueOnce(true); - - it('should return url for central tenant env', () => { - const url = getRequestUrl(REQUEST_ACTION_NAMES.CREATE_REQUEST, stripes); - - expect(url).toEqual(CENTRAL_TENANT_URLS[REQUEST_ACTION_NAMES.CREATE_REQUEST]); - }); - }); - - describe('When single tenant env', () => { - const stripes = { - hasInterface: () => false, - }; - checkIfUserInCentralTenant.mockReturnValueOnce(false); - - it('should return url for multi tenant env', () => { - const url = getRequestUrl(REQUEST_ACTION_NAMES.CREATE_REQUEST, stripes); - - expect(url).toEqual(SINGLE_TENANT_URLS[REQUEST_ACTION_NAMES.CREATE_REQUEST]); - }); - }); -}); - describe('getRequester', () => { const selectedUser = { id: 'selectedUserId',