From 373b887ff9ace50fbd16263613b94c55120435ed Mon Sep 17 00:00:00 2001 From: Priyanka Terala <104053200+Terala-Priyanka@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:05:41 +0530 Subject: [PATCH] UIU-3284-R-bugfix (#2812) * Show all patron notice print jobs, in correct order (#2806) We now show the top 100 patron notice print jobs, not 10. More importantly, they are now sorted correctly (reverse chronological) on the server side, so even if the list grows past 100 and so is truncated in the UI at the first hundred, they will be the _right_ (most recent) first hundred. Fixes UIU-3269. * UIU-3249 - Leverage API supported sorting of columns on pre-registrations records list. (#2808) * UIU-3279 supply tenantId in all useUserTenantRoles queries (#2809) Supply the `tenantId` argument in all queries. It was present in the query for a user's roles, but missing from the follow-up join-query that retrieved those roles' details, and thus returned an empty list unless the selected-tenant matched that of the currently-authenticated user. Refs UIU-3279 * Release v11.0.6 --------- Co-authored-by: Mike Taylor Co-authored-by: Zak Burke --- CHANGELOG.md | 7 ++ package.json | 2 +- .../useUserTenantRoles/useUserTenantRoles.js | 1 + .../useUserTenantRoles.test.js | 80 +++---------------- src/routes/PatronNoticePrintJobsContainer.js | 4 +- .../PatronNoticePrintJobs.js | 3 +- .../PatronsPreRegistrationList.js | 51 +++--------- .../PatronsPreRegistrationList.test.js | 2 + .../PatronsPreRegistrationListContainer.js | 4 + 9 files changed, 40 insertions(+), 114 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c28266d25..0da3ff55f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change history for ui-users +## [11.0.6](https://github.com/folio-org/ui-users/tree/v11.0.6) (2024-11-28) +[Full Changelog](https://github.com/folio-org/ui-users/compare/v11.0.5...v11.0.6) + +* `useUserTenantRoles` supplies `tenantId` in all its queries. Refs UIU-3279. +* Leverage API supported sorting of columns on pre-registrations records list. Refs UIU-3249. +* Show all patron notice print jobs (not just ten random ones), in correct order. Fixes UIU-3269. + ## [11.0.5](https://github.com/folio-org/ui-users/tree/v11.0.5) (2024-11-20) [Full Changelog](https://github.com/folio-org/ui-users/compare/v11.0.3...v11.0.5) diff --git a/package.json b/package.json index edf87a041..b86e1b429 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@folio/users", - "version": "11.0.5", + "version": "11.0.6", "description": "User management", "repository": "folio-org/ui-users", "publishConfig": { diff --git a/src/hooks/useUserTenantRoles/useUserTenantRoles.js b/src/hooks/useUserTenantRoles/useUserTenantRoles.js index ca2460ec2..bcfa686fc 100644 --- a/src/hooks/useUserTenantRoles/useUserTenantRoles.js +++ b/src/hooks/useUserTenantRoles/useUserTenantRoles.js @@ -71,6 +71,7 @@ const useUserTenantRoles = ( ids, queryEnabled: isSuccess, reduceFunction: chunkedRolesReducer, + tenantId, }); return { diff --git a/src/hooks/useUserTenantRoles/useUserTenantRoles.test.js b/src/hooks/useUserTenantRoles/useUserTenantRoles.test.js index ac8ffe0b8..c620f8e8c 100644 --- a/src/hooks/useUserTenantRoles/useUserTenantRoles.test.js +++ b/src/hooks/useUserTenantRoles/useUserTenantRoles.test.js @@ -1,6 +1,6 @@ import { QueryClient, QueryClientProvider } from 'react-query'; -import { act, renderHook } from '@folio/jest-config-stripes/testing-library/react'; - +import { renderHook } from '@folio/jest-config-stripes/testing-library/react'; +import { act } from 'react'; import { useChunkedCQLFetch, useOkapiKy, @@ -73,11 +73,17 @@ describe('useUserTenantRoles', () => { }); it('fetches roles assigned to a user', async () => { - const { result } = renderHook(() => useUserTenantRoles({ userId: 'u', tenantId: 't' }), { wrapper }); + const props = { userId: 'u', tenantId: 't' }; + const { result } = renderHook(() => useUserTenantRoles(props), { wrapper }); await act(() => !result.current.isFetching); expect(result.current.isLoading).toBe(false); expect(result.current.userRoles).toEqual(roleData); + expect(useChunkedCQLFetch).toHaveBeenCalledWith(expect.objectContaining({ + tenantId: props.tenantId, + ids: expect.any(Array), + reduceFunction: expect.any(Function), + })); }); }); @@ -92,71 +98,3 @@ describe('chunkedRolesReducer', () => { expect(result.length).toBe(6); }); }); - - - -// import { renderHook, waitFor } from '@folio/jest-config-stripes/testing-library/react'; -// import { -// QueryClient, -// QueryClientProvider, -// } from 'react-query'; - -// import { useOkapiKy, useStripes } from '@folio/stripes/core'; - -// import roles from 'fixtures/roles'; -// import useUserTenantRoles from './useUserTenantRoles'; - -// const queryClient = new QueryClient(); - -// // eslint-disable-next-line react/prop-types -// const wrapper = ({ children }) => ( -// -// {children} -// -// ); - -// const response = { -// roles, -// totalRecords: roles.length, -// }; - -// describe('useUserTenantRoles', () => { -// const getMock = jest.fn(() => ({ -// json: () => Promise.resolve(response), -// })); -// const setHeaderMock = jest.fn(); -// const kyMock = { -// extend: jest.fn(({ hooks: { beforeRequest } }) => { -// beforeRequest.forEach(handler => handler({ headers: { set: setHeaderMock } })); - -// return { -// get: getMock, -// }; -// }), -// }; - -// beforeEach(() => { -// getMock.mockClear(); - -// useStripes.mockClear().mockReturnValue({ -// okapi: {}, -// config: { -// maxUnpagedResourceCount: 1000, -// } -// }); -// useOkapiKy.mockClear().mockReturnValue(kyMock); -// }); - -// it('should fetch user roles for specified tenant', async () => { -// const options = { -// userId: 'userId', -// tenantId: 'tenantId', -// }; -// const { result } = renderHook(() => useUserTenantRoles(options), { wrapper }); - -// await waitFor(() => !result.current.isLoading); - -// expect(setHeaderMock).toHaveBeenCalledWith('X-Okapi-Tenant', options.tenantId); -// expect(getMock).toHaveBeenCalledWith('roles/users', expect.objectContaining({})); -// }); -// }); diff --git a/src/routes/PatronNoticePrintJobsContainer.js b/src/routes/PatronNoticePrintJobsContainer.js index dd9250af6..6abdffbcc 100644 --- a/src/routes/PatronNoticePrintJobsContainer.js +++ b/src/routes/PatronNoticePrintJobsContainer.js @@ -35,8 +35,8 @@ PatronNoticePrintJobsContainer.manifest = { type: 'okapi', path: 'print/entries', params: { - query: 'type="BATCH"', - sortby: 'created/sort.descending' + query: 'type="BATCH" sortby created/sort.descending', + limit: '100', }, records: 'items', throwErrors: false, diff --git a/src/views/PatronNoticePrintJobs/PatronNoticePrintJobs.js b/src/views/PatronNoticePrintJobs/PatronNoticePrintJobs.js index 9119c2f23..2695c0531 100644 --- a/src/views/PatronNoticePrintJobs/PatronNoticePrintJobs.js +++ b/src/views/PatronNoticePrintJobs/PatronNoticePrintJobs.js @@ -1,5 +1,4 @@ -import { orderBy } from 'lodash'; import { Button, Pane, MenuSection, MultiColumnList, Checkbox, FormattedDate, FormattedTime, TextLink } from '@folio/stripes/components'; import { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; @@ -72,7 +71,7 @@ const PatronNoticePrintJobs = (props) => { useEffect(() => { const updatedRecords = - orderBy(records, (item) => item.created, sortOrder === DESC ? 'desc' : 'asc') + records .map(record => ({ ...record, selected: !!record.selected, diff --git a/src/views/PatronsPreRegistrationListContainer/PatronsPreRegistrationList.js b/src/views/PatronsPreRegistrationListContainer/PatronsPreRegistrationList.js index 09a85568b..22a60e883 100644 --- a/src/views/PatronsPreRegistrationListContainer/PatronsPreRegistrationList.js +++ b/src/views/PatronsPreRegistrationListContainer/PatronsPreRegistrationList.js @@ -1,6 +1,5 @@ -import { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; -import { get, orderBy } from 'lodash'; +import { get } from 'lodash'; import { useIntl, FormattedMessage, @@ -18,34 +17,22 @@ import { COLUMNS_NAME, } from './constants'; import { useNewRecordHandler } from './hooks'; -import { sortTypes } from '../../constants'; const PatronsPreRegistrationList = ({ data, isEmptyMessage, totalCount, - onNeedMoreData + onNeedMoreData, + onSort, + sortOrder, }) => { const intl = useIntl(); - const sortInitialState = { - data: [], - order: '', - direction: sortTypes.ASC, - }; - const [sortedRecordsDetails, setSortedRecordsDetails] = useState(sortInitialState); const { handle, isLoading, } = useNewRecordHandler(); - useEffect(() => { - setSortedRecordsDetails(prev => ({ - ...prev, - data: orderBy(data, prev.order, prev.direction) - })); - }, [data]); - const renderActionColumn = (user) => (