From 5311a0bb910b5664e0786bc00a9d521bfc3634af Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Thu, 19 Dec 2024 09:48:27 +0100 Subject: [PATCH] fix(download-item): use link name as filename --- apps/datahub-e2e/src/e2e/dataset.cy.ts | 4 ++-- .../download-item/download-item.component.ts | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/datahub-e2e/src/e2e/dataset.cy.ts b/apps/datahub-e2e/src/e2e/dataset.cy.ts index ac17d89..b467a40 100644 --- a/apps/datahub-e2e/src/e2e/dataset.cy.ts +++ b/apps/datahub-e2e/src/e2e/dataset.cy.ts @@ -263,10 +263,10 @@ describe('datasets', () => { .first() .should('have.attr', 'download', '') }) - it('should contain download attribute with filename data.json for json files', () => { + it('should contain download attribute with filename for json files', () => { cy.get('[data-cy="download-button"]') .eq(2) - .should('have.attr', 'download', 'data.json') + .should('have.attr', 'download', 'insee:rectangles_200m_menage_erbm.json') }) it('should open link in new tab as fallback (if download attribute is ignored, for not same-origin)', () => { cy.get('[data-cy="download-button"]') diff --git a/apps/datahub/src/app/dataset/dataset-downloads/download-item/download-item.component.ts b/apps/datahub/src/app/dataset/dataset-downloads/download-item/download-item.component.ts index ea77063..5721643 100644 --- a/apps/datahub/src/app/dataset/dataset-downloads/download-item/download-item.component.ts +++ b/apps/datahub/src/app/dataset/dataset-downloads/download-item/download-item.component.ts @@ -15,12 +15,13 @@ export class MelDownloadItemComponent extends DownloadItemComponent { // note that the download attribute calling this getter only takes effect on same-origin resources get downloadFileName() { - let fileName = '' + let completeFileName = '' + const fileName = this.link.name ?? 'data' if (this.format === 'geojson') { - fileName = 'data.geojson' + completeFileName = `${fileName}.geojson` } else if (this.format === 'json') { - fileName = 'data.json' + completeFileName = `${fileName}.json` } - return fileName + return completeFileName } }