Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/IQSS/dataverse-frontend
Browse files Browse the repository at this point in the history
…into feature/249-boilerplate-file-page
  • Loading branch information
MellyGray committed Dec 19, 2023
2 parents e1ed09a + 48c2521 commit be47437
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 153 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## Demo videos

- 2023-08-01: [View mode of the dataset page](https://groups.google.com/g/dataverse-community/c/cxZ3Bal_-uo/m/h3kh3iVNCwAJ)
- 2023-12-13: [Files table on the dataset page](https://groups.google.com/g/dataverse-community/c/w_rEMddESYc/m/6F7QC1p-AgAJ)

## Getting Started

Expand Down
9 changes: 6 additions & 3 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@
},
"accessDataset": {
"title": "Access Dataset",
"downloadZip": "Download ZIP",
"downloadOriginalZip": "Original Format ZIP",
"downloadArchiveZip": "Archive Format (.tab) ZIP"
"downloadOptions": {
"header": "Download Options",
"zip": "Download ZIP",
"originalZip": "Original Format ZIP",
"archivalZip": "Archival Format (.tab) ZIP"
}
},
"uploadFiles": "Upload Files"
},
Expand Down
6 changes: 3 additions & 3 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ export class Dataset {
public readonly hasOneTabularFileAtLeast: boolean,
public readonly isValid: boolean,
public readonly downloadUrls: DatasetDownloadUrls,
public readonly fileDownloadSizes: FileDownloadSize[],
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl,
public readonly fileDownloadSizes?: FileDownloadSize[],
public readonly requestedVersion?: string // will be set if the user requested a version that did not exist
) {}

Expand Down Expand Up @@ -446,9 +446,9 @@ export class Dataset {
public readonly hasOneTabularFileAtLeast: boolean,
public readonly isValid: boolean,
public readonly downloadUrls: DatasetDownloadUrls,
public readonly fileDownloadSizes: FileDownloadSize[],
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl,
public readonly fileDownloadSizes?: FileDownloadSize[],
public readonly requestedVersion?: string // will be set if the user requested a version that did not exist
) {
this.withAlerts()
Expand Down Expand Up @@ -509,9 +509,9 @@ export class Dataset {
this.hasOneTabularFileAtLeast,
this.isValid,
this.downloadUrls,
this.fileDownloadSizes,
this.thumbnail,
this.privateUrl,
this.fileDownloadSizes,
this.requestedVersion
)
}
Expand Down
45 changes: 37 additions & 8 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import {
Dataset as JSDataset,
DatasetLock as JSDatasetLock,
DatasetMetadataBlock as JSDatasetMetadataBlock,
DatasetMetadataBlocks as JSDatasetMetadataBlocks,
DatasetMetadataFields as JSDatasetMetadataFields,
DatasetVersionInfo as JSDatasetVersionInfo,
DatasetUserPermissions as JSDatasetPermissions,
DatasetLock as JSDatasetLock
DatasetVersionInfo as JSDatasetVersionInfo
} from '@iqss/dataverse-client-javascript'
import { DatasetVersionState as JSDatasetVersionState } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset'
import {
Dataset,
DatasetPublishingStatus,
DatasetDownloadUrls,
DatasetLock,
DatasetLockReason,
DatasetMetadataBlock,
DatasetMetadataBlocks,
DatasetMetadataFields,
DatasetPermissions,
DatasetPublishingStatus,
DatasetVersion,
MetadataBlockName,
PrivateUrl,
DatasetDownloadUrls,
DatasetPermissions,
DatasetLock,
DatasetLockReason,
DatasetVersionNumber
} from '../../domain/models/Dataset'
import {
FileDownloadMode,
FileDownloadSize,
FileSizeUnit
} from '../../../files/domain/models/FilePreview'

export class JSDatasetMapper {
static toDataset(
Expand All @@ -31,6 +36,8 @@ export class JSDatasetMapper {
jsDatasetSummaryFieldsNames: string[],
jsDatasetPermissions: JSDatasetPermissions,
jsDatasetLocks: JSDatasetLock[],
jsDatasetFilesTotalOriginalDownloadSize: number,
jsDatasetFilesTotalArchivalDownloadSize: number,
requestedVersion?: string,
privateUrl?: PrivateUrl
): Dataset {
Expand All @@ -57,9 +64,12 @@ export class JSDatasetMapper {
true, // TODO Connect with dataset hasOneTabularFileAtLeast
true, // TODO Connect with dataset isValid
JSDatasetMapper.toDownloadUrls(jsDataset.persistentId, version),
JSDatasetMapper.toFileDownloadSizes(
jsDatasetFilesTotalOriginalDownloadSize,
jsDatasetFilesTotalArchivalDownloadSize
),
undefined, // TODO: get dataset thumbnail from Dataverse https://github.com/IQSS/dataverse-frontend/issues/203
privateUrl,
[], // TODO: Connect with file download use case,
requestedVersion
).build()
}
Expand Down Expand Up @@ -217,6 +227,7 @@ export class JSDatasetMapper {
archival: `/api/access/dataset/:persistentId/versions/${version.number.toString()}?persistentId=${jsDatasetPersistentId}`
}
}

static toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean {
return (
jsDatasetVersionInfo.releaseTime !== undefined &&
Expand All @@ -242,4 +253,22 @@ export class JSDatasetMapper {
}
})
}

static toFileDownloadSizes(
jsDatasetFilesTotalOriginalDownloadSize: number,
jsDatasetFilesTotalArchivalDownloadSize: number
): FileDownloadSize[] {
return [
new FileDownloadSize(
jsDatasetFilesTotalOriginalDownloadSize,
FileSizeUnit.BYTES,
FileDownloadMode.ORIGINAL
),
new FileDownloadSize(
jsDatasetFilesTotalArchivalDownloadSize,
FileSizeUnit.BYTES,
FileDownloadMode.ARCHIVAL
)
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
getDatasetUserPermissions,
ReadError,
getDatasetLocks,
DatasetLock as JSDatasetLock
DatasetLock as JSDatasetLock,
getDatasetFilesTotalDownloadSize,
FileDownloadSizeMode
} from '@iqss/dataverse-client-javascript'
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'

const includeDeaccessioned = true

export class DatasetJSDataverseRepository implements DatasetRepository {
getByPersistentId(
persistentId: string,
Expand All @@ -31,23 +32,41 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
getDatasetSummaryFieldNames.execute(),
getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)),
getDatasetUserPermissions.execute(jsDataset.id),
getDatasetLocks.execute(jsDataset.id)
getDatasetLocks.execute(jsDataset.id),
getDatasetFilesTotalDownloadSize.execute(
persistentId,
this.versionToVersionId(version),
FileDownloadSizeMode.ORIGINAL,
undefined,
includeDeaccessioned
),
getDatasetFilesTotalDownloadSize.execute(
persistentId,
this.versionToVersionId(version),
FileDownloadSizeMode.ARCHIVAL,
undefined,
includeDeaccessioned
)
])
)
.then(
([jsDataset, summaryFieldsNames, citation, jsDatasetPermissions, jsDatasetLocks]: [
JSDataset,
string[],
string,
JSDatasetPermissions,
JSDatasetLock[]
]) =>
([
jsDataset,
summaryFieldsNames,
citation,
jsDatasetPermissions,
jsDatasetLocks,
jsDatasetFilesTotalOriginalDownloadSize,
jsDatasetFilesTotalArchivalDownloadSize
]: [JSDataset, string[], string, JSDatasetPermissions, JSDatasetLock[], number, number]) =>
JSDatasetMapper.toDataset(
jsDataset,
citation,
summaryFieldsNames,
jsDatasetPermissions,
jsDatasetLocks,
jsDatasetFilesTotalOriginalDownloadSize,
jsDatasetFilesTotalArchivalDownloadSize,
requestedVersion
)
)
Expand Down Expand Up @@ -76,10 +95,12 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
canManageDatasetPermissions: true,
canDeleteDatasetDraft: true,
canViewUnpublishedDataset: true
},
[]
}, // TODO Connect with JS dataset permissions for privateUrl when it is available in js-dataverse
[], // TODO Connect with JS dataset locks for privateUrl when it is available in js-dataverse
0, // TODO Connect with JS dataset filesTotalDownloadSize for privateUrl when it is available in js-dataverse
0 // TODO Connect with JS dataset filesTotalDownloadSize for privateUrl when it is available in js-dataverse
)
) // TODO Connect with JS dataset permissions and getDatasetLocks.execute(privateUrlToken) when it is available in js-dataverse
)
.catch((error: ReadError) => {
throw new Error(error.message)
})
Expand Down
17 changes: 9 additions & 8 deletions src/files/domain/models/FilePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FileSize {
}

constructor(readonly value: number, readonly unit: FileSizeUnit) {
;[this.value, this.unit] = this.convertToLargestUnit(value, unit)
;[this.value, this.unit] = FileSize.convertToLargestUnit(value, unit)
}

toString(): string {
Expand All @@ -33,7 +33,7 @@ export class FileSize {
return this.value * FileSize.multiplier[this.unit]
}

private convertToLargestUnit(value: number, unit: FileSizeUnit): [number, FileSizeUnit] {
static convertToLargestUnit(value: number, unit: FileSizeUnit): [number, FileSizeUnit] {
let convertedValue = value
let convertedUnit = unit

Expand All @@ -45,7 +45,7 @@ export class FileSize {
return [convertedValue, convertedUnit]
}

private getNextUnit(unit: FileSizeUnit): FileSizeUnit {
static getNextUnit(unit: FileSizeUnit): FileSizeUnit {
switch (unit) {
case FileSizeUnit.BYTES:
return FileSizeUnit.KILOBYTES
Expand All @@ -63,13 +63,19 @@ export class FileSize {
}
}

export enum FileDownloadMode {
ORIGINAL = 'original',
ARCHIVAL = 'archival'
}

export class FileDownloadSize extends FileSize {
constructor(
readonly value: number,
readonly unit: FileSizeUnit,
readonly mode: FileDownloadMode
) {
super(value, unit)
;[this.value, this.unit] = FileDownloadSize.convertToLargestUnit(value, unit)
}
}

Expand Down Expand Up @@ -121,11 +127,6 @@ export interface FileTabularData {
unf?: string
}

export enum FileDownloadMode {
ARCHIVAL = 'archival',
ORIGINAL = 'original'
}

export enum FileLabelType {
CATEGORY = 'category',
TAG = 'tag'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function DatasetActionButtons({ dataset }: DatasetActionButtonsProps) {
permissions={dataset.permissions}
hasOneTabularFileAtLeast={dataset.hasOneTabularFileAtLeast}
fileDownloadSizes={dataset.fileDownloadSizes}
downloadUrls={dataset.downloadUrls}
/>
<PublishDatasetMenu dataset={dataset} />
<SubmitForReviewButton dataset={dataset} />
Expand Down
Loading

0 comments on commit be47437

Please sign in to comment.