Skip to content

Commit

Permalink
STCOR-890 useUserTenantPermissions hook - provide isFetched property (
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis authored Sep 24, 2024
1 parent 61ff854 commit 181b42a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* When re-authenticating after logout timeout, return to previous location. Refs STCOR-849.
* Add `nl` (Dutch, Flemish) to the supported locales. Refs STCOR-878.
* Include optional okapi interfaces, `consortia`, `roles`, `users-keycloak`. Refs STCOR-889.
* useUserTenantPermissions hook - provide `isFetched` property. Refs STCOR-890.

## [10.1.1](https://github.com/folio-org/stripes-core/tree/v10.1.1) (2024-03-25)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v10.1.0...v10.1.1)
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useUserSelfTenantPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const useUserSelfTenantPermissions = (

const {
isFetching,
isFetched,
isLoading,
data,
} = useQuery(
Expand All @@ -42,6 +43,7 @@ const useUserSelfTenantPermissions = (

return ({
isFetching,
isFetched,
isLoading,
userPermissions: data?.permissions.permissions || INITIAL_DATA,
totalRecords: data?.permissions.permissions.length || 0,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useUserTenantPermissionNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const useUserTenantPermissionNames = (

const {
isFetching,
isFetched,
isLoading,
data = {},
} = useQuery(
Expand All @@ -50,6 +51,7 @@ const useUserTenantPermissionNames = (

return ({
isFetching,
isFetched,
isLoading,
userPermissions: data.permissionNames || INITIAL_DATA,
totalRecords: data.totalRecords,
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useUserTenantPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ const useUserTenantPermissions = (

const {
isFetching: isPermissionsFetching,
isFetched: isPermissionsFetched,
isLoading: isPermissionsLoading,
userPermissions: permissionsData = {},
totalRecords: permissionsTotalRecords
} = useUserTenantPermissionNames({ tenantId }, options);

const {
isFetching: isSelfPermissionsFetching,
isFetched: isSelfPermissionsFetched,
isLoading: isSelfPermissionsLoading,
userPermissions:selfPermissionsData = {},
totalRecords: selfPermissionsTotalRecords
} = useUserSelfTenantPermissions({ tenantId }, options);

const isFetching = stripes.hasInterface('roles') ? isSelfPermissionsFetching : isPermissionsFetching;
const isFetched = stripes.hasInterface('roles') ? isSelfPermissionsFetched : isPermissionsFetched;
const isLoading = stripes.hasInterface('roles') ? isSelfPermissionsLoading : isPermissionsLoading;
const userPermissions = stripes.hasInterface('roles') ? selfPermissionsData : permissionsData;
const totalRecords = stripes.hasInterface('roles') ? selfPermissionsTotalRecords : permissionsTotalRecords;

return ({
isFetching,
isFetched,
isLoading,
userPermissions,
totalRecords
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useUserTenantPermissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ describe('useUserTenantPermissions', () => {

useUserSelfTenantPermissions.mockReturnValue({
isFetching: true,
isFetched: true,
isLoading: true,
userPermissions: ['self'],
totalRecords: 1
});

useUserTenantPermissionNames.mockReturnValue({
isFetching: false,
isFetched: false,
isLoading: false,
userPermissions: ['permission name'],
totalRecords: 1
Expand All @@ -39,6 +41,7 @@ describe('useUserTenantPermissions', () => {

expect(result.current).toStrictEqual({
isFetching: true,
isFetched: true,
isLoading: true,
userPermissions: ['self'],
totalRecords: 1
Expand All @@ -50,13 +53,15 @@ describe('useUserTenantPermissions', () => {

useUserSelfTenantPermissions.mockReturnValue({
isFetching: true,
isFetched: true,
isLoading: true,
userPermissions: ['self'],
totalRecords: 1
});

useUserTenantPermissionNames.mockReturnValue({
isFetching: false,
isFetched: false,
isLoading: false,
userPermissions: ['permission name'],
totalRecords: 1
Expand All @@ -66,6 +71,7 @@ describe('useUserTenantPermissions', () => {

expect(result.current).toStrictEqual({
isFetching: false,
isFetched: false,
isLoading: false,
userPermissions: ['permission name'],
totalRecords: 1
Expand Down

0 comments on commit 181b42a

Please sign in to comment.