Skip to content

Commit

Permalink
feat: support long text for csm (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
YvesRijckaert authored Jul 23, 2024
1 parent c2380ae commit bae2dce
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 3 deletions.
74 changes: 74 additions & 0 deletions packages/content-source-maps/src/__tests__/graphql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const UNSUPPORTED_WIDGETS = [
'assetLinkEditor',
'assetLinksEditor',
'assetGalleryEditor',
'markdown',
];

describe('Content Source Maps with the GraphQL API', () => {
Expand Down Expand Up @@ -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: {
Expand Down
52 changes: 50 additions & 2 deletions packages/content-source-maps/src/__tests__/rest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -114,6 +118,12 @@ describe('Content Source Maps with the CPA', () => {
editorInterface: 2,
},
},
'fields/longText': {
source: {
fieldType: 3,
editorInterface: 3,
},
},
},
},
});
Expand Down Expand Up @@ -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'],
},
});

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion packages/content-source-maps/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const SUPPORTED_WIDGETS: WidgetId[] = [
'checkbox',
'richTextEditor',
'multipleLine',
'markdown',
];

export function encodeField(
Expand All @@ -109,6 +108,12 @@ export function encodeField(
break;
}

case 'Text': {
const encodedValue = combine(value, hiddenStrings);
set(target, pointer, encodedValue);
break;
}

case 'RichText': {
encodeRichTextValue({
pointer: '',
Expand Down

0 comments on commit bae2dce

Please sign in to comment.