Merge pull request #14588 from wusuopu/fix-edit-json-field

This commit is contained in:
Josh 2022-11-17 12:41:40 +00:00 committed by GitHub
commit 70d7bbcb53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -12,14 +12,14 @@ const formatContentTypeData = (data, ct, composSchema) => {
const compoUid = getOtherInfos(schema, [current, 'component']);
const isRepeatable = getOtherInfos(schema, [current, 'repeatable']);
if (!value) {
acc[current] = value;
if (type === 'json' && value !== undefined) {
acc[current] = JSON.stringify(value, null, 2);
return acc;
}
if (type === 'json') {
acc[current] = JSON.stringify(value, null, 2);
if (!value) {
acc[current] = value;
return acc;
}

View File

@ -87,6 +87,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => {
dz: { type: 'dynamiczone', components: ['compos.sub-compo'] },
jsonString: { type: 'json' },
jsonObject: { type: 'json' },
jsonBool: { type: 'json' },
},
};
@ -119,6 +120,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => {
],
jsonString: 'hello',
jsonObject: { hello: true },
jsonBool: false,
};
const expected = {
@ -136,6 +138,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => {
],
jsonString: '"hello"',
jsonObject: '{\n "hello": true\n}',
jsonBool: 'false',
};
expect(formatContentTypeData(data, contentType, components)).toEqual(expected);