Merge pull request #16965 from strapi/chore/fix-styling

This commit is contained in:
Marc 2023-06-09 12:00:33 +02:00 committed by GitHub
commit 6cd60520fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 73 deletions

View File

@ -54,7 +54,6 @@ const useSettingsForm = (endPoint, schema, cbSuccess, fieldsToPick) => {
}; };
const handleChange = ({ target: { name, value, type: inputType } }) => { const handleChange = ({ target: { name, value, type: inputType } }) => {
dispatch({ dispatch({
type: 'ON_CHANGE', type: 'ON_CHANGE',
inputType, inputType,
@ -82,7 +81,6 @@ const useSettingsForm = (endPoint, schema, cbSuccess, fieldsToPick) => {
}); });
if (!errors) { if (!errors) {
try { try {
lockApp(); lockApp();

View File

@ -12,8 +12,8 @@ jest.mock('@strapi/helper-plugin', () => ({
})); }));
const mockSchema = { const mockSchema = {
validate: () => true validate: () => true,
} };
const handlers = [ const handlers = [
rest.put('*/providers/options', (req, res, ctx) => rest.put('*/providers/options', (req, res, ctx) =>
@ -22,9 +22,9 @@ const handlers = [
ctx.json({ ctx.json({
data: { data: {
autoRegister: false, autoRegister: false,
defaultRole: "1", defaultRole: '1',
ssoLockedRoles: ["1","2","3"] ssoLockedRoles: ['1', '2', '3'],
} },
}) })
) )
), ),
@ -34,18 +34,17 @@ const handlers = [
ctx.json({ ctx.json({
data: { data: {
autoRegister: false, autoRegister: false,
defaultRole: "1", defaultRole: '1',
ssoLockedRoles: ["1","2"] ssoLockedRoles: ['1', '2'],
} },
}) })
) )
) ),
]; ];
const server = setupServer(...handlers); const server = setupServer(...handlers);
const setup = (...args) => const setup = (...args) => renderHook(() => useSettingsForm(...args));
renderHook(() => useSettingsForm(...args));
describe('useSettingsForm', () => { describe('useSettingsForm', () => {
beforeAll(() => { beforeAll(() => {
@ -56,7 +55,11 @@ describe('useSettingsForm', () => {
server.close(); server.close();
}); });
test('fetches all the providers options', async () => { test('fetches all the providers options', async () => {
const { result } = setup('/admin/providers/options', mockSchema, jest.fn(), ['autoRegister', 'defaultRole', 'ssoLockedRoles'] ); const { result } = setup('/admin/providers/options', mockSchema, jest.fn(), [
'autoRegister',
'defaultRole',
'ssoLockedRoles',
]);
expect(result.current[0].isLoading).toBe(true); expect(result.current[0].isLoading).toBe(true);
expect(result.current[0].formErrors).toStrictEqual({}); expect(result.current[0].formErrors).toStrictEqual({});
@ -66,21 +69,21 @@ describe('useSettingsForm', () => {
expect(result.current[0].showHeaderLoader).toBeTruthy(); expect(result.current[0].showHeaderLoader).toBeTruthy();
await waitFor(() => expect(result.current[0].isLoading).toBe(false)); await waitFor(() => expect(result.current[0].isLoading).toBe(false));
expect(result.current[0].formErrors).toStrictEqual({}); expect(result.current[0].formErrors).toStrictEqual({});
expect(result.current[0].initialData).toStrictEqual( expect(result.current[0].initialData).toStrictEqual(
expect.objectContaining({ expect.objectContaining({
autoRegister: false, autoRegister: false,
defaultRole: "1", defaultRole: '1',
ssoLockedRoles: ["1","2"] ssoLockedRoles: ['1', '2'],
}) })
); );
expect(result.current[0].modifiedData).toStrictEqual( expect(result.current[0].modifiedData).toStrictEqual(
expect.objectContaining({ expect.objectContaining({
autoRegister: false, autoRegister: false,
defaultRole: "1", defaultRole: '1',
ssoLockedRoles: ["1","2"] ssoLockedRoles: ['1', '2'],
}) })
); );
@ -89,7 +92,7 @@ describe('useSettingsForm', () => {
}); });
test('submit new providers options with duplications', async () => { test('submit new providers options with duplications', async () => {
const ssoLockedRolesWithDuplications = [ '1', '2', '2', '3' ]; const ssoLockedRolesWithDuplications = ['1', '2', '2', '3'];
server.use( server.use(
rest.get('*/providers/options', (req, res, ctx) => rest.get('*/providers/options', (req, res, ctx) =>
res.once( res.once(
@ -97,17 +100,21 @@ describe('useSettingsForm', () => {
ctx.json({ ctx.json({
data: { data: {
autoRegister: false, autoRegister: false,
defaultRole: "1", defaultRole: '1',
ssoLockedRoles: ssoLockedRolesWithDuplications ssoLockedRoles: ssoLockedRolesWithDuplications,
} },
}) })
) )
) )
) );
const cbSucc = jest.fn(); const cbSucc = jest.fn();
const { result } = setup('/admin/providers/options', mockSchema, cbSucc, ['autoRegister', 'defaultRole', 'ssoLockedRoles'] ); const { result } = setup('/admin/providers/options', mockSchema, cbSucc, [
'autoRegister',
'defaultRole',
'ssoLockedRoles',
]);
await waitFor(() => expect(result.current[0].isLoading).toBe(false)); await waitFor(() => expect(result.current[0].isLoading).toBe(false));
// call the handleSubmit handler to see if the data provided in modified data are cleaned without duplicates in the ssoLockedRoles list // call the handleSubmit handler to see if the data provided in modified data are cleaned without duplicates in the ssoLockedRoles list
const e = { preventDefault: jest.fn() }; const e = { preventDefault: jest.fn() };
@ -115,6 +122,8 @@ describe('useSettingsForm', () => {
await result.current[2].handleSubmit(e); await result.current[2].handleSubmit(e);
}); });
expect(result.current[0].modifiedData.ssoLockedRoles.length).not.toBe(ssoLockedRolesWithDuplications.length); expect(result.current[0].modifiedData.ssoLockedRoles.length).not.toBe(
ssoLockedRolesWithDuplications.length
);
}); });
}); });

View File

@ -1,14 +1,6 @@
import React from "react"; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import { Typography, Box, Grid, GridItem, Flex, Select, Option } from '@strapi/design-system';
Typography,
Box,
Grid,
GridItem,
Flex,
Select,
Option
} from '@strapi/design-system';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import upperFirst from 'lodash/upperFirst'; import upperFirst from 'lodash/upperFirst';
@ -75,8 +67,7 @@ const Preferences = ({ onChange, values, localeNames, allApplicationThemes }) =>
})} })}
hint={formatMessage({ hint={formatMessage({
id: 'Settings.profile.form.section.experience.interfaceLanguage.hint', id: 'Settings.profile.form.section.experience.interfaceLanguage.hint',
defaultMessage: defaultMessage: 'This will only display your own interface in the chosen language.',
'This will only display your own interface in the chosen language.',
})} })}
onClear={() => { onClear={() => {
onChange({ onChange({
@ -94,13 +85,11 @@ const Preferences = ({ onChange, values, localeNames, allApplicationThemes }) =>
}); });
}} }}
> >
{ {Object.entries(localeNames).map(([language, langName]) => (
Object.entries(localeNames).map(([ language, langName ]) => ( <Option value={language} key={language}>
<Option value={language} key={language}> {langName}
{ langName } </Option>
</Option> ))}
))
}
</Select> </Select>
</GridItem> </GridItem>
<GridItem s={12} col={6}> <GridItem s={12} col={6}>
@ -146,7 +135,7 @@ const Preferences = ({ onChange, values, localeNames, allApplicationThemes }) =>
</Flex> </Flex>
</Box> </Box>
); );
} };
Preferences.propTypes = { Preferences.propTypes = {
allApplicationThemes: PropTypes.object, allApplicationThemes: PropTypes.object,

View File

@ -1,22 +1,12 @@
import React from "react"; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { GenericInput } from '@strapi/helper-plugin'; import { GenericInput } from '@strapi/helper-plugin';
import { import { Typography, Box, Grid, GridItem, Flex } from '@strapi/design-system';
Typography,
Box,
Grid,
GridItem,
Flex,
} from '@strapi/design-system';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
const UserInfo = ({ const UserInfo = ({ errors, onChange, values }) => {
errors,
onChange,
values
}) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
return ( return (
<Box <Box
background="neutral0" background="neutral0"
@ -89,8 +79,8 @@ const UserInfo = ({
</Grid> </Grid>
</Flex> </Flex>
</Box> </Box>
) );
} };
UserInfo.propTypes = { UserInfo.propTypes = {
errors: PropTypes.shape({ errors: PropTypes.shape({
@ -115,7 +105,7 @@ UserInfo.defaultProps = {
firstname: '', firstname: '',
lastname: '', lastname: '',
username: '', username: '',
email: '' email: '',
}, },
}; };

View File

@ -6,9 +6,11 @@ const schema = yup.object().shape({
defaultRole: yup.mixed().when('autoRegister', (value, initSchema) => { defaultRole: yup.mixed().when('autoRegister', (value, initSchema) => {
return value ? initSchema.required(translatedErrors.required) : initSchema.nullable(); return value ? initSchema.required(translatedErrors.required) : initSchema.nullable();
}), }),
ssoLockedRoles: yup.array().of(yup.mixed().when('ssoLockedRoles', (value, initSchema) => { ssoLockedRoles: yup.array().of(
return value ? initSchema.required(translatedErrors.required) : initSchema.nullable(); yup.mixed().when('ssoLockedRoles', (value, initSchema) => {
})), return value ? initSchema.required(translatedErrors.required) : initSchema.nullable();
})
),
}); });
export default schema; export default schema;

View File

@ -10,12 +10,14 @@ const providerOptionsUpdateSchema = yup.object().shape({
.test('is-valid-role', 'You must submit a valid default role', (roleId) => { .test('is-valid-role', 'You must submit a valid default role', (roleId) => {
return strapi.admin.services.role.exists({ id: roleId }); return strapi.admin.services.role.exists({ id: roleId });
}), }),
ssoLockedRoles: yup.array().of(yup ssoLockedRoles: yup.array().of(
.strapiID() yup
.required() .strapiID()
.test('is-valid-role', 'You must submit a valid role for the SSO Locked roles', (roleId) => { .required()
return strapi.admin.services.role.exists({ id: roleId }); .test('is-valid-role', 'You must submit a valid role for the SSO Locked roles', (roleId) => {
})), return strapi.admin.services.role.exists({ id: roleId });
})
),
}); });
module.exports = { module.exports = {