Skip to content

Commit

Permalink
feat(FileMetadata): add Download Url
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Jan 15, 2024
1 parent 3c680c8 commit f1bdd1d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $danger: $dv-danger-color;
// Body
$body-color: $dv-text-color;
$headings-color: $dv-headings-color;
$code-color: $dv-text-color;

// Typography
$font-family-base: $dv-font-family;
Expand Down Expand Up @@ -125,4 +126,4 @@ th {
.btn-group > div:not(:first-child) > .btn-group > .btn, .btn-group-vertical > div:not(:first-child) > .btn-group > .btn {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
3 changes: 2 additions & 1 deletion src/files/domain/models/File.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DatasetVersion } from '../../../dataset/domain/models/Dataset'
import { FileLabel, FileType } from './FilePreview'
import { FileDownloadUrls, FileLabel, FileType } from './FilePreview'

export interface FilePermissions {
canDownloadFile: boolean
Expand All @@ -12,6 +12,7 @@ export interface File {
restricted: boolean
permissions: FilePermissions
labels: FileLabel[]
downloadUrls: FileDownloadUrls
persistentId?: string
thumbnail?: string
}
10 changes: 10 additions & 0 deletions src/sections/file/file-metadata/FileMetadata.module.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module";

.row {
margin: 12px 0;
}

.help-text {
color: $dv-subtext-color;
}

.code {
background-color: #F0F0F0;
}
22 changes: 22 additions & 0 deletions src/sections/file/file-metadata/FileMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface FileMetadataProps {
file: File
}

const BASE_URL = (import.meta.env.VITE_DATAVERSE_BACKEND_URL as string) ?? ''

export function FileMetadata({ file }: FileMetadataProps) {
return (
<Accordion defaultActiveKey="0">
Expand Down Expand Up @@ -40,6 +42,26 @@ export function FileMetadata({ file }: FileMetadataProps) {
<Col>{file.persistentId}</Col>
</Row>
)}
{file.permissions.canDownloadFile && (
<Row className={styles.row}>
<Col sm={3}>
<strong>Download URL</strong>
</Col>
<Col>
<p className={styles['help-text']}>
Use the Download URL in a Wget command or a download manager to avoid interrupted
downloads, time outs or other failures.{' '}
<a href="https://guides.dataverse.org/en/6.1/user/find-use-data.html#downloading-via-url">
User Guide - Downloading via URL
</a>
</p>
<code className={styles.code}>
{BASE_URL}
{file.downloadUrls.original}
</code>
</Col>
</Row>
)}
</Accordion.Body>
</Accordion.Item>
</Accordion>
Expand Down
21 changes: 15 additions & 6 deletions tests/component/files/domain/models/FileMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export class FileMother {
labels: faker.datatype.boolean() ? FileLabelMother.createMany(3) : [],
thumbnail: faker.datatype.boolean() ? faker.image.imageUrl() : undefined,
persistentId: faker.datatype.boolean() ? faker.datatype.uuid() : undefined,
downloadUrls: {
original: '/api/access/datafile/107',
tabular: '/api/access/datafile/107',
rData: '/api/access/datafile/107'
},
...props
}
}
Expand Down Expand Up @@ -46,12 +51,7 @@ export class FileMother {
}

static createRestrictedWithAccessGranted(props?: Partial<File>): File {
return this.createRestricted({
permissions: {
canDownloadFile: true
},
...props
})
return this.createRestricted(this.createWithDownloadPermissionGranted(props))
}

static createWithThumbnail(props?: Partial<File>): File {
Expand All @@ -67,4 +67,13 @@ export class FileMother {
...props
})
}

static createWithDownloadPermissionGranted(props?: Partial<File>): File {
return this.create({
permissions: {
canDownloadFile: true
},
...props
})
}
}
27 changes: 27 additions & 0 deletions tests/component/sections/file/file-metadata/FileMetadata.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,31 @@ describe('FileMetadata', () => {
cy.findByText('File Persistent ID').should('exist')
cy.findByText('doi:10.5072/FK2/ABC123').should('exist')
})

it('does not render the file persistent id when there is no persistent id', () => {
cy.customMount(<FileMetadata file={FileMother.create({ persistentId: undefined })} />)

cy.findByText('File Persistent ID').should('not.exist')
})

it('renders the download url if the user has file download permissions', () => {
cy.customMount(
<FileMetadata
file={FileMother.createWithDownloadPermissionGranted({
downloadUrls: { original: '/api/access/datafile/123' }
})}
/>
)

cy.findByText('Download URL').should('exist')
cy.findByText('/api/access/datafile/123', { exact: false }).should('exist')
cy.findByText(
'Use the Download URL in a Wget command or a download manager to avoid interrupted downloads, time outs or other failures.'
).should('exist')
cy.findByRole('link', { name: 'User Guide - Downloading via URL' }).should(
'have.attr',
'href',
'https://guides.dataverse.org/en/6.1/user/find-use-data.html#downloading-via-url'
)
})
})

0 comments on commit f1bdd1d

Please sign in to comment.