diff --git a/examples/43-assign-field-annotations.js b/examples/43-assign-field-annotations.js index ceacfe464..f9d4257e7 100644 --- a/examples/43-assign-field-annotations.js +++ b/examples/43-assign-field-annotations.js @@ -1,17 +1,10 @@ module.exports = function (migration) { const annotatedContentType = migration.editContentType('annotated') annotatedContentType.editField('sources').setAnnotations(['Contentful:AggregateComponent']) - annotatedContentType.editField('title').setAnnotations([ - { - sys: { - type: 'Link', - linkType: 'Annotation', - id: 'Contentful:GraphQLFieldResolver' - }, - parameters: { - appFunctionId: '123', - appDefinitionId: '456' - } + annotatedContentType.editField('title').setAnnotations(['Contentful:GraphQLFieldResolver'], { + parameters: { + appFunctionId: '123', + appDefinitionId: '456' } - ]) + }) } diff --git a/examples/44-clear-field-annotations.js b/examples/44-clear-field-annotations.js index 799be0e05..ae0db7161 100644 --- a/examples/44-clear-field-annotations.js +++ b/examples/44-clear-field-annotations.js @@ -1,4 +1,5 @@ module.exports = function (migration) { const annotatedContentType = migration.editContentType('annotated') annotatedContentType.editField('sources').clearAnnotations() + annotatedContentType.editField('title').clearAnnotations() } diff --git a/src/lib/action/field-annotate.ts b/src/lib/action/field-annotate.ts index 3d07c73bf..3ca2e669a 100644 --- a/src/lib/action/field-annotate.ts +++ b/src/lib/action/field-annotate.ts @@ -5,12 +5,19 @@ class FieldAnnotateAction extends EntityAction { private contentTypeId: string private fieldId: string private annotations: AnnotationLink[] + private fieldAnnotationPayload: Record - constructor(contentTypeId: string, fieldId: string, annotations?: AnnotationLink[]) { + constructor( + contentTypeId: string, + fieldId: string, + annotations?: AnnotationLink[], + fieldAnnotationPayload?: Record + ) { super() this.contentTypeId = contentTypeId this.fieldId = fieldId this.annotations = annotations + this.fieldAnnotationPayload = fieldAnnotationPayload } getEntityId(): string { @@ -25,7 +32,7 @@ class FieldAnnotateAction extends EntityAction { if (!this.annotations || !this.annotations.length) { ct.clearFieldAnnotations(this.fieldId) } else { - ct.setFieldAnnotations(this.fieldId, this.annotations) + ct.setFieldAnnotations(this.fieldId, this.annotations, this.fieldAnnotationPayload) } } } diff --git a/src/lib/entities/content-type.ts b/src/lib/entities/content-type.ts index b5a1609c1..57807737a 100644 --- a/src/lib/entities/content-type.ts +++ b/src/lib/entities/content-type.ts @@ -711,8 +711,16 @@ class ContentType { delete this._metadata?.annotations?.ContentType } - setFieldAnnotations(fieldId: string, annotations: AnnotationLink[]) { - set(this, `_metadata.annotations.ContentTypeField.${fieldId}`, annotations) + setFieldAnnotations( + fieldId: string, + annotations: AnnotationLink[], + fieldAnnotationPayload?: Record + ) { + set( + this, + `_metadata.annotations.ContentTypeField.${fieldId}`, + Object.assign(annotations, fieldAnnotationPayload) + ) } getFieldAnnotations(fieldId: string) { diff --git a/src/lib/intent/field-annotate.ts b/src/lib/intent/field-annotate.ts index 1a6631fb6..c3555c89e 100644 --- a/src/lib/intent/field-annotate.ts +++ b/src/lib/intent/field-annotate.ts @@ -31,7 +31,8 @@ export default class FieldAnnotateIntent extends Intent { id, type: 'Link', linkType: 'Annotation' - } + }, + ...this.payload.fieldAnnotationPayload })) return [new FieldAnnotateAction(this.getContentTypeId(), this.getFieldId(), annotationLinks)] } diff --git a/src/lib/interfaces/raw-step.ts b/src/lib/interfaces/raw-step.ts index 54d8b2bac..68d14081a 100644 --- a/src/lib/interfaces/raw-step.ts +++ b/src/lib/interfaces/raw-step.ts @@ -52,6 +52,7 @@ interface RawStepPayload { tagVisibility?: TagVisibility entryTransformationForTags?: EntrySetTags annotations?: AnnotationId[] + fieldAnnotationPayload?: Record } interface EditorInterfaceInfo { diff --git a/src/lib/migration-steps/action-creators.ts b/src/lib/migration-steps/action-creators.ts index b4786e94c..9ddac4ff3 100644 --- a/src/lib/migration-steps/action-creators.ts +++ b/src/lib/migration-steps/action-creators.ts @@ -674,7 +674,8 @@ const actionCreators = { fieldId, fieldInstanceId, callsite, - annotationIds + annotationIds, + fieldAnnotationPayload? ): Intents.FieldAnnotate => new Intents.FieldAnnotate({ type: 'field/annotate', @@ -689,7 +690,8 @@ const actionCreators = { payload: { contentTypeId, fieldId, - annotations: annotationIds + annotations: annotationIds, + fieldAnnotationPayload } }) }, diff --git a/src/lib/migration-steps/index.ts b/src/lib/migration-steps/index.ts index 334222365..fa8a0c34a 100644 --- a/src/lib/migration-steps/index.ts +++ b/src/lib/migration-steps/index.ts @@ -52,7 +52,7 @@ class Field extends DispatchProxy { }) } - setAnnotations(annotationIds: string[]) { + setAnnotations(annotationIds: string[], fieldAnnotationPayload?: Record) { const callsite = getFirstExternalCaller() const fieldInstanceId = this.contentType.fieldInstanceIds.getNew(this.id) this.contentType.dispatch( @@ -62,7 +62,8 @@ class Field extends DispatchProxy { this.id, fieldInstanceId, callsite, - annotationIds + annotationIds, + fieldAnnotationPayload ) )