From 624c7a5b1e405f7a6ebad491c1a10ca0425b5654 Mon Sep 17 00:00:00 2001 From: Rafael Velazco Date: Fri, 19 Apr 2024 17:09:34 -0400 Subject: [PATCH] chore: restore edit button (#28307) --- ...dot-binary-field-preview.component.spec.ts | 6 ++++++ .../dot-binary-field-preview.component.ts | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-binary-field/components/dot-binary-field-preview/dot-binary-field-preview.component.spec.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-binary-field/components/dot-binary-field-preview/dot-binary-field-preview.component.spec.ts index 8a9b65273c35..f3e963bde4bf 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-binary-field/components/dot-binary-field-preview/dot-binary-field-preview.component.spec.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-binary-field/components/dot-binary-field-preview/dot-binary-field-preview.component.spec.ts @@ -112,6 +112,12 @@ describe('DotBinaryFieldPreviewComponent', () => { ); }); + it('should be editable', () => { + spectator.detectChanges(); + const editButton = spectator.query(byTestId('edit-button')); + expect(editButton).toBeTruthy(); + }); + it('should show download button responsive', () => { spectator.detectChanges(); const downloadButtonResponsive = spectator.query(byTestId('download-btn-responsive')); diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-binary-field/components/dot-binary-field-preview/dot-binary-field-preview.component.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-binary-field/components/dot-binary-field-preview/dot-binary-field-preview.component.ts index e3cf39b1160c..ad74b14f4bac 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-binary-field/components/dot-binary-field-preview/dot-binary-field-preview.component.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-binary-field/components/dot-binary-field-preview/dot-binary-field-preview.component.ts @@ -99,14 +99,17 @@ export class DotBinaryFieldPreviewComponent implements OnInit, OnChanges { } ngOnInit() { - this.isEditable = this.metadata.editableAsText || this.isEditableImage(); if (this.contentlet) { this.content.set(this.contentlet?.content); this.fetchResourceLinks(); } } - ngOnChanges({ tempFile }: SimpleChanges): void { + ngOnChanges({ tempFile, editableImage }: SimpleChanges): void { + if (editableImage) { + this.isEditable = this.isFileEditable(); + } + if (tempFile?.currentValue) { this.content.set(tempFile.currentValue.content); } @@ -190,7 +193,17 @@ export class DotBinaryFieldPreviewComponent implements OnInit, OnChanges { } /** - * Emits event to remove the file + * Check if the file is editable + * + * @return {*} {boolean} + * @memberof DotBinaryFieldPreviewComponent + */ + private isFileEditable(): boolean { + return this.metadata.editableAsText || this.isEditableImage(); + } + + /** + * Check if the file is an editable image * * @private * @return {*} {boolean}