From a079e2347f3b155b7bd9f31d7c62a6b480ca931c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure-H=C3=A9l=C3=A8ne=20Bruneton?= Date: Wed, 5 Feb 2025 14:44:55 +0100 Subject: [PATCH] feat(ui-elements): remove extension from file description --- .../form-field-overviews.component.spec.ts | 10 +++++----- .../form-field-overviews.component.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-overviews/form-field-overviews.component.spec.ts b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-overviews/form-field-overviews.component.spec.ts index e17615ac4e..e72be89a13 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-overviews/form-field-overviews.component.spec.ts +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-overviews/form-field-overviews.component.spec.ts @@ -62,13 +62,13 @@ describe('FormFieldOverviewsComponent', () => { component.metadataUuid = '8505d991-e38f-4704-a47a-e7d335dfbef5' component.value = [ { - description: 'doge.jpg', + description: 'doge', url: new URL( 'http://localhost:8080/geonetwork/srv/api/0.1/records/8505d991-e38f-4704-a47a-e7d335dfbef5/attachments/doge.jpg' ), }, { - description: 'flower.jpg', + description: 'flower', url: new URL( 'http://localhost:8080/geonetwork/srv/api/0.1/records/8505d991-e38f-4704-a47a-e7d335dfbef5/attachments/flower.jpg' ), @@ -114,7 +114,7 @@ describe('FormFieldOverviewsComponent', () => { expect(component.uploadProgress).toBeUndefined() expect(valueChange).toEqual([ { - description: 'test.png', + description: 'test', url: new URL('http://example.com/test.png'), }, ]) @@ -157,10 +157,10 @@ describe('FormFieldOverviewsComponent', () => { component.valueChange.subscribe((v) => (valueChange = v)) }) it('emits the new resources along with the other ones', () => { - component.handleUrlChange('http://my.org/aaa/file.png') + component.handleUrlChange('http://my.org/aaa/file.png.ext') expect(valueChange).toEqual([ { - url: new URL('http://my.org/aaa/file.png'), + url: new URL('http://my.org/aaa/file.png.ext'), description: 'file.png', }, ]) diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-overviews/form-field-overviews.component.ts b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-overviews/form-field-overviews.component.ts index fad8d0d1d0..3c403c5145 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-overviews/form-field-overviews.component.ts +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-overviews/form-field-overviews.component.ts @@ -70,7 +70,7 @@ export class FormFieldOverviewsComponent { this.cd.detectChanges() this.emitOverview({ url: event.attachment.url, - description: event.attachment.fileName, + description: this.removeFileExtension(event.attachment.fileName), }) } }, @@ -90,7 +90,7 @@ export class FormFieldOverviewsComponent { const filename = url.split('/').pop() this.emitOverview({ url: new URL(url), - description: filename, + description: this.removeFileExtension(filename), }) } catch (e) { this.handleError(e as Error) @@ -112,6 +112,10 @@ export class FormFieldOverviewsComponent { this.valueChange.emit(overView ? [overView] : []) } + private removeFileExtension(filename: string) { + return filename.replace(/\.[^/.]+$/, '') + } + private handleError = (error: Error) => { this.uploadProgress = undefined this.cd.markForCheck()