diff --git a/packages/content-source-maps/src/__tests__/graphql.spec.ts b/packages/content-source-maps/src/__tests__/graphql.spec.ts index afc24669..7dbe1904 100644 --- a/packages/content-source-maps/src/__tests__/graphql.spec.ts +++ b/packages/content-source-maps/src/__tests__/graphql.spec.ts @@ -24,6 +24,7 @@ const UNSUPPORTED_WIDGETS = [ 'assetLinkEditor', 'assetLinksEditor', 'assetGalleryEditor', + 'markdown', ]; describe('Content Source Maps with the GraphQL API', () => { @@ -112,6 +113,79 @@ describe('Content Source Maps with the GraphQL API', () => { }); }); + test('works for Text fields, except markdown', () => { + const graphQLResponse: GraphQLResponse = { + data: { + post: { + longText: 'Title of the post', + markdown: 'markdown content', + }, + }, + extensions: { + contentSourceMaps: { + spaces: ['foo'], + environments: ['master'], + fieldTypes: ['Text'], + editorInterfaces: [ + { + widgetId: 'multipleLine', + widgetNamespace: 'builtin', + }, + { + widgetId: 'markdown', + widgetNamespace: 'builtin', + }, + ], + fields: ['longText', 'markdown'], + locales: ['en-US'], + entries: [{ space: 0, environment: 0, id: 'a1b2c3' }], + assets: [], + mappings: { + '/data/post/longText': { + source: { + entry: 0, + field: 0, + locale: 0, + fieldType: 0, + editorInterface: 0, + }, + }, + '/data/post/markdown': { + source: { + entry: 0, + field: 1, + locale: 0, + fieldType: 0, + editorInterface: 1, + }, + }, + }, + }, + }, + }; + const encodedGraphQLResponse = encodeGraphQLResponse(graphQLResponse); + testEncodingDecoding(encodedGraphQLResponse.data.post, { + '/longText': { + origin: 'contentful.com', + href: 'https://app.contentful.com/spaces/foo/environments/master/entries/a1b2c3/?focusedField=longText&focusedLocale=en-US', + contentful: { + space: 'foo', + environment: 'master', + field: 'longText', + locale: 'en-US', + entity: 'a1b2c3', + entityType: 'Entry', + editorInterface: { + widgetId: 'multipleLine', + widgetNamespace: 'builtin', + }, + fieldType: 'Text', + }, + }, + '/markdown': undefined, + }); + }); + test('works for lists of Symbol fields', () => { const graphQLResponse: GraphQLResponse = { data: { diff --git a/packages/content-source-maps/src/__tests__/rest.spec.ts b/packages/content-source-maps/src/__tests__/rest.spec.ts index b8bb3dc7..0add5a46 100644 --- a/packages/content-source-maps/src/__tests__/rest.spec.ts +++ b/packages/content-source-maps/src/__tests__/rest.spec.ts @@ -22,6 +22,10 @@ describe('Content Source Maps with the CPA', () => { 'en-US': 'English title', af: 'Afrikaans title', }, + longText: { + 'en-US': 'English long text', + af: 'Afrikaans long text', + }, richText: { 'en-US': { data: {}, @@ -114,6 +118,12 @@ describe('Content Source Maps with the CPA', () => { editorInterface: 2, }, }, + 'fields/longText': { + source: { + fieldType: 3, + editorInterface: 3, + }, + }, }, }, }); @@ -211,8 +221,12 @@ describe('Content Source Maps with the CPA', () => { widgetId: 'tagEditor', widgetNamespace: 'builtin', }, + { + widgetId: 'multipleLine', + widgetNamespace: 'builtin', + }, ], - fieldTypes: ['Symbol', 'RichText', 'Array'], + fieldTypes: ['Symbol', 'RichText', 'Array', 'Text'], }, }); @@ -253,6 +267,40 @@ describe('Content Source Maps with the CPA', () => { fieldType: 'Symbol', }, }, + '/items/0/fields/longText/en-US': { + origin: 'contentful.com', + href: 'https://app.contentful.com/spaces/spaceId/environments/master/entries/entryId/?focusedField=longText&focusedLocale=en-US', + contentful: { + space: 'spaceId', + environment: 'master', + field: 'longText', + locale: 'en-US', + entity: 'entryId', + entityType: 'Entry', + editorInterface: { + widgetId: 'multipleLine', + widgetNamespace: 'builtin', + }, + fieldType: 'Text', + }, + }, + '/items/0/fields/longText/af': { + origin: 'contentful.com', + href: 'https://app.contentful.com/spaces/spaceId/environments/master/entries/entryId/?focusedField=longText&focusedLocale=af', + contentful: { + space: 'spaceId', + environment: 'master', + field: 'longText', + locale: 'af', + entity: 'entryId', + entityType: 'Entry', + editorInterface: { + widgetId: 'multipleLine', + widgetNamespace: 'builtin', + }, + fieldType: 'Text', + }, + }, '/items/0/fields/richText/en-US/content/0/content/0/value': { origin: 'contentful.com', href: 'https://app.contentful.com/spaces/spaceId/environments/master/entries/entryId/?focusedField=richText&focusedLocale=en-US', @@ -923,7 +971,7 @@ describe('Content Source Maps with the CPA', () => { }); }); - describe('allows configureing a platform to reduce the payload', () => { + describe('allows configuring a platform to reduce the payload', () => { const response = createEntry({ id: 'entryId', contentType: 'ctId', diff --git a/packages/content-source-maps/src/utils.ts b/packages/content-source-maps/src/utils.ts index fad7cb42..36d451c7 100644 --- a/packages/content-source-maps/src/utils.ts +++ b/packages/content-source-maps/src/utils.ts @@ -86,7 +86,6 @@ export const SUPPORTED_WIDGETS: WidgetId[] = [ 'checkbox', 'richTextEditor', 'multipleLine', - 'markdown', ]; export function encodeField( @@ -109,6 +108,12 @@ export function encodeField( break; } + case 'Text': { + const encodedValue = combine(value, hiddenStrings); + set(target, pointer, encodedValue); + break; + } + case 'RichText': { encodeRichTextValue({ pointer: '',