From d72d4489ccf66ef22128906c8aa3f178b28bb4f3 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Fri, 10 Feb 2023 10:33:34 +0100 Subject: [PATCH 01/13] Fix non required json input setting a value when empty --- .../helper-plugin/lib/src/components/GenericInput/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js index b7d5b491cd..e63cada7a8 100644 --- a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js +++ b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js @@ -146,8 +146,7 @@ const GenericInput = ({ hint={hint} required={required} onChange={(json) => { - // Default to null when the field is not required and there is no input value - const value = !attribute.required && !json.length ? 'null' : json; + const value = !attribute.required && !json.length ? null : json; onChange({ target: { name, value } }); }} minHeight={pxToRem(252)} From 1945fd3748fc580cefe260ecb3b77a682a0f349f Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Fri, 10 Feb 2023 11:59:39 +0100 Subject: [PATCH 02/13] Keep comment --- .../core/helper-plugin/lib/src/components/GenericInput/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js index e63cada7a8..daded2ea94 100644 --- a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js +++ b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js @@ -146,6 +146,7 @@ const GenericInput = ({ hint={hint} required={required} onChange={(json) => { + // Default to null when the field is not required and there is no input value const value = !attribute.required && !json.length ? null : json; onChange({ target: { name, value } }); }} From 849f16eec6cb83991e49ee964c60d5b7dac17724 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Tue, 14 Feb 2023 11:55:35 +0530 Subject: [PATCH 03/13] Remove JSON default values being set by the content manager --- .../EditViewDataManagerProvider/utils/schema.js | 8 +++++++- .../admin/src/content-manager/utils/createDefaultForm.js | 8 -------- .../content-manager/utils/tests/createDefaultForm.test.js | 5 ----- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js index 52bb5bb2f4..2cb2204fe9 100644 --- a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js +++ b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js @@ -216,6 +216,10 @@ const createYupSchemaAttribute = (type, validations, options) => { schema = yup .mixed(errorsTrads.json) .test('isJSON', errorsTrads.json, (value) => { + if (!value || !value.length) { + return true; + } + try { JSON.parse(value); @@ -226,7 +230,9 @@ const createYupSchemaAttribute = (type, validations, options) => { }) .nullable() .test('required', errorsTrads.required, (value) => { - if (validations.required && !value.length) return false; + if (validations.required && (!value || !value.length)) { + return false; + } return true; }); diff --git a/packages/core/admin/admin/src/content-manager/utils/createDefaultForm.js b/packages/core/admin/admin/src/content-manager/utils/createDefaultForm.js index 3b50f33ae8..65ee4315b3 100644 --- a/packages/core/admin/admin/src/content-manager/utils/createDefaultForm.js +++ b/packages/core/admin/admin/src/content-manager/utils/createDefaultForm.js @@ -5,14 +5,6 @@ const createDefaultForm = (attributes, allComponentsSchema) => { const attribute = get(attributes, [current], {}); const { default: defaultValue, component, type, required, min, repeatable } = attribute; - if (type === 'json') { - acc[current] = null; - } - - if (type === 'json' && required === true) { - acc[current] = {}; - } - if (defaultValue !== undefined) { acc[current] = defaultValue; } diff --git a/packages/core/admin/admin/src/content-manager/utils/tests/createDefaultForm.test.js b/packages/core/admin/admin/src/content-manager/utils/tests/createDefaultForm.test.js index f5431024d6..b14a4da65f 100644 --- a/packages/core/admin/admin/src/content-manager/utils/tests/createDefaultForm.test.js +++ b/packages/core/admin/admin/src/content-manager/utils/tests/createDefaultForm.test.js @@ -11,11 +11,6 @@ describe('CONTENT MANAGER | utils | createDefaultForm', () => { expect(createDefaultForm(attributes, {})).toEqual({}); }); - it('should set the json type with the correct value', () => { - expect(createDefaultForm({ test: { type: 'json' } }, {})).toEqual({ test: null }); - expect(createDefaultForm({ test: { type: 'json', required: true } }, {})).toEqual({ test: {} }); - }); - it('should init the requide dynamic zone type with an empty array', () => { expect(createDefaultForm({ test: { type: 'dynamiczone', required: true } })).toEqual({ test: [], From f6da34d1e71ac6681663121f397a3c4c6c7f790f Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Wed, 15 Feb 2023 17:11:37 +0530 Subject: [PATCH 04/13] Fix null being set on save --- .../core/helper-plugin/lib/src/components/GenericInput/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js index daded2ea94..1f0fdb5b46 100644 --- a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js +++ b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js @@ -141,7 +141,7 @@ const GenericInput = ({ Date: Wed, 15 Feb 2023 18:30:28 +0530 Subject: [PATCH 05/13] Revert change disallowing null as a value --- .../core/helper-plugin/lib/src/components/GenericInput/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js index 1f0fdb5b46..daded2ea94 100644 --- a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js +++ b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js @@ -141,7 +141,7 @@ const GenericInput = ({ Date: Wed, 22 Feb 2023 16:04:30 +0100 Subject: [PATCH 06/13] add limitation on the schema validation of the name API and Transfer token --- .../pages/SettingsPage/pages/ApiTokens/EditView/utils/schema.js | 2 +- .../SettingsPage/pages/TransferTokens/EditView/utils/schema.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/schema.js b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/schema.js index 4d6686c7ec..626080eef1 100644 --- a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/schema.js +++ b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/schema.js @@ -2,7 +2,7 @@ import * as yup from 'yup'; import { translatedErrors } from '@strapi/helper-plugin'; const schema = yup.object().shape({ - name: yup.string(translatedErrors.string).required(translatedErrors.required), + name: yup.string(translatedErrors.string).max(100).required(translatedErrors.required), type: yup .string(translatedErrors.string) .oneOf(['read-only', 'full-access', 'custom']) diff --git a/packages/core/admin/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/utils/schema.js b/packages/core/admin/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/utils/schema.js index ccaded4103..ca6efd5060 100644 --- a/packages/core/admin/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/utils/schema.js +++ b/packages/core/admin/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/utils/schema.js @@ -2,7 +2,7 @@ import * as yup from 'yup'; import { translatedErrors } from '@strapi/helper-plugin'; const schema = yup.object().shape({ - name: yup.string(translatedErrors.string).required(translatedErrors.required), + name: yup.string(translatedErrors.string).max(100).required(translatedErrors.required), description: yup.string().nullable(), lifespan: yup.number().integer().min(0).nullable().defined(translatedErrors.required), }); From 7dac99e011922c3c416e1d8a3482002c20bc4750 Mon Sep 17 00:00:00 2001 From: Simone Taeggi Date: Wed, 22 Feb 2023 16:11:03 +0100 Subject: [PATCH 07/13] update snapshots --- .../tests/__snapshots__/index.test.js.snap | 184 +- .../tests/__snapshots__/index.test.js.snap | 1689 +++++++++-------- .../ListView/tests/index.test.js | 621 +++--- 3 files changed, 1384 insertions(+), 1110 deletions(-) diff --git a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/tests/__snapshots__/index.test.js.snap b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/tests/__snapshots__/index.test.js.snap index 71244fe533..2e3934ca66 100644 --- a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/tests/__snapshots__/index.test.js.snap +++ b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/tests/__snapshots__/index.test.js.snap @@ -15,7 +15,7 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot color: #32324d; } -.c25 { +.c24 { font-weight: 500; font-size: 1rem; line-height: 1.25; @@ -61,6 +61,11 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot padding-right: 8px; } +.c19 { + padding-right: 56px; + padding-left: 56px; +} + .c22 { background: #ffffff; padding-top: 24px; @@ -179,7 +184,7 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot flex-direction: row; } -.c23 { +.c20 { -webkit-align-items: stretch; -webkit-box-align: stretch; -ms-flex-align: stretch; @@ -311,12 +316,21 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot border: 2px solid #4945ff; } -.c24 > * { +.c21 > * { margin-top: 0; margin-bottom: 0; } -.c24 > * + * { +.c21 > * + * { + margin-top: 24px; +} + +.c23 > * { + margin-top: 0; + margin-bottom: 0; +} + +.c23 > * + * { margin-top: 16px; } @@ -519,7 +533,7 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot fill: #ffffff; } -.c26 { +.c25 { display: grid; grid-template-columns: repeat(12,1fr); gap: 20px; @@ -530,7 +544,7 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot grid-template-columns: repeat(12,1fr); } -.c27 { +.c26 { grid-column: span 6; max-width: 100%; } @@ -553,11 +567,6 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot padding-right: 8px; } -.c19 { - padding-right: 56px; - padding-left: 56px; -} - .c42 { padding-right: 16px; padding-left: 16px; @@ -602,7 +611,7 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot color: #666687; } -.c20 { +.c27 { -webkit-align-items: stretch; -webkit-box-align: stretch; -ms-flex-align: stretch; @@ -708,15 +717,6 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot display: flex; } -.c21 > * { - margin-top: 0; - margin-bottom: 0; -} - -.c21 > * + * { - margin-top: 24px; -} - .c28 > * { margin-top: 0; margin-bottom: 0; @@ -958,13 +958,13 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot } @media (max-width:68.75rem) { - .c27 { + .c26 { grid-column: span; } } @media (max-width:34.375rem) { - .c27 { + .c26 { grid-column: span 12; } } @@ -1091,27 +1091,27 @@ exports[`ADMIN | Pages | API TOKENS | EditView renders and matches the snapshot

Details