Skip to content

Commit 9d8b1c9

Browse files
authored
Merge branch 'master' into rich-text-versioning
2 parents 3065c78 + 431d964 commit 9d8b1c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3127
-3496
lines changed

apps/braze/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
"build": "tsc && vite build --outDir build && npm run build:functions",
2525
"test": "vitest",
2626
"create-app-definition": "contentful-app-scripts create-app-definition",
27-
"deploy": "contentful-app-scripts upload --ci --bundle-dir ./dist --organization-id ${DEFINITIONS_ORG_ID} --definition-id gWLhC7MnK2rgcvifgE4do --token ${CONTENTFUL_CMA_TOKEN}",
27+
"deploy": "contentful-app-scripts upload --ci --bundle-dir ./build --organization-id ${DEFINITIONS_ORG_ID} --definition-id gWLhC7MnK2rgcvifgE4do --token ${CONTENTFUL_CMA_TOKEN}",
2828
"upload": "contentful-app-scripts upload --bundle-dir ./build",
2929
"upload-ci": "contentful-app-scripts upload --ci --bundle-dir ./build --organization-id $CONTENTFUL_ORG_ID --definition-id $CONTENTFUL_APP_DEF_ID --token $CONTENTFUL_ACCESS_TOKEN",
3030
"upsert-actions": "contentful-app-scripts upsert-actions --ci --organization-id $CONTENTFUL_ORG_ID --definition-id $CONTENTFUL_APP_DEF_ID --token $CONTENTFUL_ACCESS_TOKEN",
3131
"build:functions": "contentful-app-scripts build-functions --ci",
32-
"deploy:dev": "source .env && contentful-app-scripts upload --ci --bundle-dir ./dist --organization-id \"$DEFINITIONS_ORG_ID\" --definition-id gWLhC7MnK2rgcvifgE4do --token \"$CONTENTFUL_CMA_TOKEN\"",
32+
"deploy:dev": "source .env && contentful-app-scripts upload --ci --bundle-dir ./build --organization-id \"$DEFINITIONS_ORG_ID\" --definition-id gWLhC7MnK2rgcvifgE4do --token \"$CONTENTFUL_CMA_TOKEN\"",
3333
"upload-ci:dev": "source .env && contentful-app-scripts upload --ci --bundle-dir ./build --organization-id \"$CONTENTFUL_ORG_ID\" --definition-id \"$CONTENTFUL_APP_DEF_ID\" --token \"$CONTENTFUL_ACCESS_TOKEN\"",
3434
"upsert-actions:dev": "source .env && contentful-app-scripts upsert-actions --ci --organization-id \"$CONTENTFUL_ORG_ID\" --definition-id \"$CONTENTFUL_APP_DEF_ID\" --token \"$CONTENTFUL_ACCESS_TOKEN\"",
3535
"create-app-event": "tsx -r dotenv/config src/scripts/createAppEvents.ts"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Field } from './Field';
2+
import { FieldRegistry } from './fieldRegistry';
3+
4+
export class ExternalResourceField extends Field {
5+
constructor(id: string, name: string, entryContentTypeId: string, localized: boolean) {
6+
super(id, name, entryContentTypeId, localized);
7+
}
8+
9+
get type(): string {
10+
return 'ExternalResourceField';
11+
}
12+
13+
public override set selected(value: boolean) {
14+
return;
15+
}
16+
17+
static fromSerialized(serializedField: any): ExternalResourceField {
18+
const field = new ExternalResourceField(
19+
serializedField.id,
20+
serializedField.name,
21+
serializedField.entryContentTypeId,
22+
serializedField.localized
23+
);
24+
return field;
25+
}
26+
27+
generateQuery(): string {
28+
throw new Error('External resource not supported');
29+
}
30+
31+
generateLiquidTagForType(template: string): string[] {
32+
throw new Error('External resource not supported');
33+
}
34+
35+
isEnabledForGenerate(): boolean {
36+
return false;
37+
}
38+
39+
isEnabledForCreate(): boolean {
40+
return false;
41+
}
42+
}
43+
44+
FieldRegistry.registerFieldType('ExternalResourceField', ExternalResourceField.fromSerialized);

apps/braze/src/fields/FieldsFactory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ReferenceItem } from './ReferenceItem';
1515
import { RichTextField } from './RichTextField';
1616
import { TextArrayField } from './TextArrayField';
1717
import resolveResponse from 'contentful-resolve-response';
18+
import { ExternalResourceField } from './ExternalResourceField';
1819

1920
export class FieldsFactory {
2021
private contentTypes: { [key: string]: ContentTypeProps };
@@ -134,6 +135,8 @@ export class FieldsFactory {
134135
fieldClass = RichTextField;
135136
} else if (fieldInfo.type === 'Location') {
136137
fieldClass = LocationField;
138+
} else if (fieldInfo.type === 'ResourceLink') {
139+
fieldClass = ExternalResourceField;
137140
} else {
138141
fieldClass = BasicField;
139142
}

apps/braze/src/fields/RichTextField.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class RichTextField extends Field {
2222
serializedField.entryContentTypeId,
2323
serializedField.localized
2424
);
25-
field.selected = serializedField.selected;
2625
return field;
2726
}
2827

@@ -37,14 +36,6 @@ export class RichTextField extends Field {
3736
isEnabledForGenerate(): boolean {
3837
return false;
3938
}
40-
41-
displayNameForGenerate(): string {
42-
return `${this.name} (Support for rich text fields coming soon)`;
43-
}
44-
45-
displayNameForCreate(): string {
46-
return this.name;
47-
}
4839
}
4940

5041
FieldRegistry.registerFieldType('RichTextField', RichTextField.fromSerialized);

apps/braze/test/fields/FieldsFactory.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ vi.mock('contentful-resolve-response', () => {
1717

1818
// Import the mocked function for use in tests
1919
import resolveResponse from 'contentful-resolve-response';
20+
import { ExternalResourceField } from '../../src/fields/ExternalResourceField';
2021

2122
describe('FieldsFactory', () => {
2223
const mockCma = {
@@ -475,6 +476,34 @@ describe('FieldsFactory', () => {
475476
'English Title'
476477
);
477478
});
479+
480+
it('should create an ExternalResourceField instance with correct properties', async () => {
481+
const mockEntry = [
482+
{
483+
fields: {
484+
externalReference: {
485+
sys: { type: 'ResourceLink', linkType: 'Contentful:Entry', urn: 'an-id' },
486+
},
487+
},
488+
},
489+
];
490+
(resolveResponse as any).mockReturnValue(mockEntry);
491+
492+
mockCma.contentType.get.mockResolvedValue({
493+
fields: [{ id: 'externalReference', type: 'ResourceLink', localized: false }],
494+
sys: {
495+
id: 'externalArticle',
496+
},
497+
});
498+
499+
const result = await createFields(entryId, entryContentTypeId, mockCma);
500+
expect(result).toHaveLength(1);
501+
expect(result[0]).toBeInstanceOf(ExternalResourceField);
502+
const fieldInstance = result[0] as ExternalResourceField;
503+
expect(fieldInstance.id).toBe('externalReference');
504+
expect(fieldInstance.entryContentTypeId).toBe('externalArticle');
505+
expect(fieldInstance.localized).toBe(false);
506+
});
478507
});
479508
});
480509

apps/bulk-edit/package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/bulk-edit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@contentful/f36-tokens": "4.2.0",
1010
"@contentful/field-editor-json": "^3.3.38",
1111
"@contentful/react-apps-toolkit": "1.2.16",
12+
"@contentful/rich-text-html-renderer": "^17.1.0",
1213
"@phosphor-icons/react": "^2.1.10",
1314
"contentful-management": "^11.52.0",
1415
"emotion": "10.0.27",

apps/bulk-edit/src/locations/Page/utils/entryUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { documentToHtmlString } from '@contentful/rich-text-html-renderer';
2+
import { Document } from '@contentful/rich-text-types';
13
import { Entry, ContentTypeField, Status, Fields } from '../types';
24
import { ContentTypeProps } from 'contentful-management';
35

@@ -67,6 +69,10 @@ export const renderFieldValue = (field: ContentTypeField, value: unknown): strin
6769
return `1 reference field`;
6870
}
6971

72+
if (field.type === 'RichText' && typeof value === 'object' && value !== null) {
73+
return truncate(documentToHtmlString(value as Document));
74+
}
75+
7076
if (typeof value === 'object' && value !== null) {
7177
return '';
7278
}

0 commit comments

Comments
 (0)