Skip to content

Commit

Permalink
Merge pull request #14588 from wusuopu/fix-edit-json-field
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Nov 17, 2022
2 parents c1a9e7a + 6677b31 commit 70d7bbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
},
};

Expand Down Expand Up @@ -119,6 +120,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => {
],
jsonString: 'hello',
jsonObject: { hello: true },
jsonBool: false,
};

const expected = {
Expand All @@ -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);
Expand Down

0 comments on commit 70d7bbc

Please sign in to comment.