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 compoUid = getOtherInfos(schema, [current, 'component']);
const isRepeatable = getOtherInfos(schema, [current, 'repeatable']); const isRepeatable = getOtherInfos(schema, [current, 'repeatable']);
if (!value) { if (type === 'json' && value !== undefined) {
acc[current] = value; acc[current] = JSON.stringify(value, null, 2);
return acc; return acc;
} }
if (type === 'json') { if (!value) {
acc[current] = JSON.stringify(value, null, 2); acc[current] = value;
return acc; return acc;
} }

View File

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