-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove history & clean up some U&P tests (#16992)
- Loading branch information
1 parent
86eaf9f
commit bc6034c
Showing
35 changed files
with
669 additions
and
3,568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as useFetchRole } from './useFetchRole'; | ||
export { default as useForm } from './useForm'; | ||
export { default as usePlugins } from './usePlugins'; | ||
export { default as useRolesList } from './useRolesList'; | ||
export * from './usePlugins'; | ||
export { default as useFetchRole } from './useFetchRole'; |
71 changes: 71 additions & 0 deletions
71
packages/plugins/users-permissions/admin/src/hooks/usePlugins.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { useNotification, useFetchClient, useAPIErrorHandler } from '@strapi/helper-plugin'; | ||
import { useQueries } from 'react-query'; | ||
|
||
import pluginId from '../pluginId'; | ||
import { cleanPermissions, getTrad } from '../utils'; | ||
|
||
export const usePlugins = () => { | ||
const toggleNotification = useNotification(); | ||
const { get } = useFetchClient(); | ||
const { formatAPIError } = useAPIErrorHandler(getTrad); | ||
|
||
const [ | ||
{ | ||
data: permissions, | ||
isLoading: isLoadingPermissions, | ||
error: permissionsError, | ||
refetch: refetchPermissions, | ||
}, | ||
{ data: routes, isLoading: isLoadingRoutes, error: routesError, refetch: refetchRoutes }, | ||
] = useQueries([ | ||
{ | ||
queryKey: [pluginId, 'permissions'], | ||
async queryFn() { | ||
const res = await get(`/${pluginId}/permissions`); | ||
|
||
return res.data.permissions; | ||
}, | ||
}, | ||
{ | ||
queryKey: [pluginId, 'routes'], | ||
async queryFn() { | ||
const res = await get(`/${pluginId}/routes`); | ||
|
||
return res.data.routes; | ||
}, | ||
}, | ||
]); | ||
|
||
const refetchQueries = async () => { | ||
await Promise.all([refetchPermissions(), refetchRoutes()]); | ||
}; | ||
|
||
useEffect(() => { | ||
if (permissionsError) { | ||
toggleNotification({ | ||
type: 'warning', | ||
message: formatAPIError(permissionsError), | ||
}); | ||
} | ||
}, [toggleNotification, permissionsError, formatAPIError]); | ||
|
||
useEffect(() => { | ||
if (routesError) { | ||
toggleNotification({ | ||
type: 'warning', | ||
message: formatAPIError(routesError), | ||
}); | ||
} | ||
}, [toggleNotification, routesError, formatAPIError]); | ||
|
||
const isLoading = isLoadingPermissions || isLoadingRoutes; | ||
|
||
return { | ||
permissions: permissions ? cleanPermissions(permissions) : {}, | ||
routes: routes ?? {}, | ||
getData: refetchQueries, | ||
isLoading, | ||
}; | ||
}; |
70 changes: 0 additions & 70 deletions
70
packages/plugins/users-permissions/admin/src/hooks/usePlugins/index.js
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
packages/plugins/users-permissions/admin/src/hooks/usePlugins/init.js
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
packages/plugins/users-permissions/admin/src/hooks/usePlugins/reducer.js
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
packages/plugins/users-permissions/admin/src/hooks/usePlugins/tests/init.test.js
This file was deleted.
Oops, something went wrong.
96 changes: 0 additions & 96 deletions
96
packages/plugins/users-permissions/admin/src/hooks/usePlugins/tests/reducer.test.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.