Skip to content

Commit

Permalink
chore: remove history & clean up some U&P tests (#16992)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Jun 19, 2023
1 parent 86eaf9f commit bc6034c
Show file tree
Hide file tree
Showing 35 changed files with 669 additions and 3,568 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import React, { useCallback, useMemo } from 'react';

import { Box, Checkbox, Flex, Grid, GridItem, Typography } from '@strapi/design-system';
import {
Box,
Checkbox,
Flex,
Typography,
Grid,
GridItem,
VisuallyHidden,
} from '@strapi/design-system';
import { Cog as CogIcon } from '@strapi/icons';
import get from 'lodash/get';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -90,10 +98,20 @@ const SubCategory = ({ subCategory }) => {
</Checkbox>
<button
type="button"
data-testid="action-cog"
onClick={() => onSelectedAction(action.name)}
style={{ display: 'inline-flex', alignItems: 'center' }}
>
<VisuallyHidden as="span">
{formatMessage(
{
id: 'app.utils.show-bound-route',
defaultMessage: 'Show bound route for {route}',
},
{
route: action.name,
}
)}
</VisuallyHidden>
<CogIcon />
</button>
</CheckboxWrapper>
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/users-permissions/admin/src/hooks/index.js
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 packages/plugins/users-permissions/admin/src/hooks/usePlugins.js
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,
};
};

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { QueryClient, QueryClientProvider } from 'react-query';

import ProtectedAdvancedSettingsPage from '../index';

import server from './utils/server';

jest.mock('@strapi/helper-plugin', () => ({
...jest.requireActual('@strapi/helper-plugin'),
useNotification: jest.fn(),
Expand Down Expand Up @@ -38,19 +36,12 @@ const App = (
);

describe('ADMIN | Pages | Settings | Advanced Settings', () => {
beforeAll(() => server.listen());

beforeEach(() => {
jest.clearAllMocks();
});

afterEach(() => {
server.resetHandlers();
});

afterAll(() => {
jest.resetAllMocks();
server.close();
});

it('renders and matches the snapshot', async () => {
Expand Down

0 comments on commit bc6034c

Please sign in to comment.