Update Edit page

This commit is contained in:
bulby97 2021-08-30 09:26:22 +02:00
parent a640881964
commit f16f4ba4ef
6 changed files with 856 additions and 9 deletions

View File

@ -48,6 +48,8 @@ const RoleForm = ({ disabled, role, values, errors, onChange, onBlur }) => {
{formatMessage(
{
id: 'Settings.roles.form.button.users-with-role',
defaultMessage:
'{number, plural, =0 {# users} one {# user} other {# users}} with this role',
},
{ number: role.usersCount }
)}
@ -59,7 +61,10 @@ const RoleForm = ({ disabled, role, values, errors, onChange, onBlur }) => {
disabled={disabled}
name="name"
error={errors.name && formatMessage({ id: errors.name })}
label={formatMessage({ id: 'Settings.roles.form.input.name' })}
label={formatMessage({
id: 'Settings.roles.form.input.name',
defaultMessage: 'Name',
})}
onChange={onChange}
onBlur={onBlur}
value={values.name || ''}
@ -68,7 +73,10 @@ const RoleForm = ({ disabled, role, values, errors, onChange, onBlur }) => {
<GridItem col={6}>
<Textarea
disabled={disabled}
label={formatMessage({ id: 'Settings.roles.form.input.description' })}
label={formatMessage({
id: 'Settings.roles.form.input.description',
defaultMessage: 'Description',
})}
name="description"
error={errors.name && formatMessage({ id: errors.name })}
onChange={onChange}

View File

@ -1,4 +1,10 @@
import { request, useNotification, useOverlayBlocker, useTracking } from '@strapi/helper-plugin';
import {
request,
useNotification,
useOverlayBlocker,
useTracking,
LoadingIndicatorPage,
} from '@strapi/helper-plugin';
import { Box, Button, HeaderLayout, Main, Stack, ContentLayout } from '@strapi/parts';
import { Formik } from 'formik';
import get from 'lodash/get';
@ -140,7 +146,7 @@ const EditPage = () => {
onBlur={handleBlur}
role={role}
/>
{!isLayoutLoading && !isRoleLoading && (
{!isLayoutLoading && !isRoleLoading ? (
<Box paddingTop={6} paddingBottom={6}>
<Permissions
isFormDisabled={isFormDisabled}
@ -149,6 +155,8 @@ const EditPage = () => {
layout={permissionsLayout}
/>
</Box>
) : (
<LoadingIndicatorPage />
)}
</ContentLayout>
</>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,64 @@
/**
*
* Tests for EditPage
*
*/
import React from 'react';
import { render } from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import { Router, Switch, Route } from 'react-router';
import { createMemoryHistory } from 'history';
import moment from 'moment';
import Theme from '../../../../components/Theme';
import EditPage from '../index';
jest.mock('moment', () => {
const mMoment = {
format: jest.fn().mockReturnThis(),
valueOf: jest.fn(),
};
return jest.fn(() => mMoment);
});
jest.mock('@strapi/helper-plugin', () => ({
...jest.requireActual('@strapi/helper-plugin'),
useNotification: jest.fn(() => jest.fn()),
useOverlayBlocker: jest.fn(() => ({ lockApp: jest.fn(), unlockApp: jest.fn() })),
useTracking: jest.fn(() => ({ trackUsage: jest.fn() })),
}));
const makeApp = history => (
<IntlProvider
messages={{ en: { 'Settings.roles.form.created': 'created' } }}
textComponent="span"
locale="en"
>
<Theme>
<Router history={history}>
<Switch>
<Route path="/settings/roles/:id">
<EditPage />
</Route>
</Switch>
</Router>
</Theme>
</IntlProvider>
);
describe('<EditPage />', () => {
it('renders and matches the snapshot', () => {
moment()
.format.mockReturnValueOnce('20210130T12:34:56+00:00')
.mockReturnValueOnce('0130-2021');
const history = createMemoryHistory();
const App = makeApp(history);
const { container } = render(App);
history.push('/settings/roles/1');
expect(container).toMatchSnapshot();
});
});

View File

@ -40,8 +40,8 @@
"@fortawesome/react-fontawesome": "^0.1.14",
"@strapi/babel-plugin-switch-ee-ce": "1.0.0",
"@strapi/helper-plugin": "3.6.7",
"@strapi/icons": "0.0.1-alpha.15",
"@strapi/parts": "0.0.1-alpha.15",
"@strapi/icons": "0.0.1-alpha.16",
"@strapi/parts": "0.0.1-alpha.16",
"@strapi/utils": "3.6.7",
"axios": "^0.21.1",
"babel-loader": "8.2.2",

View File

@ -4079,7 +4079,6 @@
tslib "^2.0.0"
upath "2.0.1"
<<<<<<< HEAD
"@storybook/addon-actions@6.3.7", "@storybook/addon-actions@^6.3.7":
version "6.3.7"
resolved "https://registry.yarnpkg.com/@storybook/addon-actions/-/addon-actions-6.3.7.tgz#b25434972bef351aceb3f7ec6fd66e210f256aac"
@ -4916,13 +4915,16 @@
resolve-from "^5.0.0"
store2 "^2.12.0"
=======
>>>>>>> ade0a8767 (Fix conflicts with yarn lock)
"@strapi/icons@0.0.1-alpha.15":
version "0.0.1-alpha.15"
resolved "https://registry.yarnpkg.com/@strapi/icons/-/icons-0.0.1-alpha.15.tgz#32fc824b732b4a21d5282f84696d6207ac5cbea1"
integrity sha512-FIczXDSEBPXTfptgqR6Hjh65Fpf4XF+kEm3o53PQX8G0GZ0Udpcbspqf2Kieeocg8TePgRkTI/oU6KS1aJbXrg==
"@strapi/icons@0.0.1-alpha.16":
version "0.0.1-alpha.16"
resolved "https://registry.yarnpkg.com/@strapi/icons/-/icons-0.0.1-alpha.16.tgz#0906c0c36b1f27b46ba9f3011216cb63671839eb"
integrity sha512-6veZv8rnX+IVZUf5Di3CSQYgjaUEJiJ6CuE03HSi5R3MixsHUXc3Q/7R4oj+U6eswz/FIaSRcJcPCJ0pw4Dm8g==
"@strapi/parts@0.0.1-alpha.15":
version "0.0.1-alpha.15"
resolved "https://registry.yarnpkg.com/@strapi/parts/-/parts-0.0.1-alpha.15.tgz#250cc29be0fa4cc2b91c8c0be49e1c2070a25450"
@ -4932,6 +4934,15 @@
compute-scroll-into-view "^1.0.17"
prop-types "^15.7.2"
"@strapi/parts@0.0.1-alpha.16":
version "0.0.1-alpha.16"
resolved "https://registry.yarnpkg.com/@strapi/parts/-/parts-0.0.1-alpha.16.tgz#afb9b6c269a8afdfb1ea324dc9f56ee94f1ab985"
integrity sha512-KBK/JrhFLgicmRmqMjzP1eSWu4+UN0EA4Hz203tmaNs+U6sZHzsygQ2yVYFfNd2MuIkiimeW8WwMwT+QLhiw+A==
dependencies:
"@internationalized/number" "^3.0.2"
compute-scroll-into-view "^1.0.17"
prop-types "^15.7.2"
"@stylelint/postcss-css-in-js@^0.37.2":
version "0.37.2"
resolved "https://registry.yarnpkg.com/@stylelint/postcss-css-in-js/-/postcss-css-in-js-0.37.2.tgz#7e5a84ad181f4234a2480803422a47b8749af3d2"