Skip to content

Commit

Permalink
fix(download-item): use link name as filename
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Dec 19, 2024
1 parent 73cd07d commit 9bf3549
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions apps/datahub-e2e/src/e2e/dataset.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,14 @@ 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"]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 9bf3549

Please sign in to comment.