Skip to content

Commit

Permalink
feat(ui-elements): remove extension from file description
Browse files Browse the repository at this point in the history
  • Loading branch information
LHBruneton-C2C committed Feb 5, 2025
1 parent fce1ed1 commit a079e23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
),
Expand Down Expand Up @@ -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'),
},
])
Expand Down Expand Up @@ -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',
},
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}
},
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit a079e23

Please sign in to comment.