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/229-basic-home-page-with-the-list-of-datasets
  • Loading branch information
MellyGray committed Dec 19, 2023
2 parents ff238ce + 48c2521 commit 99e16d3
Show file tree
Hide file tree
Showing 45 changed files with 1,119 additions and 279 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ interface DropdownItemProps extends React.HTMLAttributes<HTMLElement> {
href?: string
eventKey?: string
disabled?: boolean
download?: string
children: ReactNode
}

export function DropdownButtonItem({
href,
eventKey,
disabled,
download,
children,
...props
}: DropdownItemProps) {
return (
<DropdownBS.Item href={href} eventKey={eventKey} disabled={disabled} {...props}>
<DropdownBS.Item
href={href}
eventKey={eventKey}
disabled={disabled}
download={download}
{...props}>
{children}
</DropdownBS.Item>
)
Expand Down
8 changes: 7 additions & 1 deletion public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@
}
},
"accessDataset": {
"title": "Access Dataset"
"title": "Access Dataset",
"downloadOptions": {
"header": "Download Options",
"zip": "Download ZIP",
"originalZip": "Original Format ZIP",
"archivalZip": "Archival Format (.tab) ZIP"
}
},
"uploadFiles": "Upload Files"
},
Expand Down
15 changes: 15 additions & 0 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Alert, AlertMessageKey } from '../../../alert/domain/models/Alert'
import { FileDownloadSize } from '../../../files/domain/models/File'

export enum DatasetLabelSemanticMeaning {
DATASET = 'dataset',
Expand Down Expand Up @@ -263,6 +264,11 @@ export interface PrivateUrl {
urlSnippet: string
}

export interface DatasetDownloadUrls {
original: string
archival: string
}

export class Dataset {
constructor(
public readonly persistentId: string,
Expand All @@ -276,8 +282,11 @@ export class Dataset {
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly hasOneTabularFileAtLeast: boolean,
public readonly isValid: boolean,
public readonly isReleased: boolean,
public readonly downloadUrls: DatasetDownloadUrls,
public readonly fileDownloadSizes: FileDownloadSize[],
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl
) {}
Expand Down Expand Up @@ -359,8 +368,11 @@ export class Dataset {
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly hasOneTabularFileAtLeast: boolean,
public readonly isValid: boolean,
public readonly isReleased: boolean,
public readonly downloadUrls: DatasetDownloadUrls,
public readonly fileDownloadSizes: FileDownloadSize[],
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl
) {
Expand Down Expand Up @@ -467,8 +479,11 @@ export class Dataset {
this.permissions,
this.locks,
this.hasValidTermsOfAccess,
this.hasOneTabularFileAtLeast,
this.isValid,
this.isReleased,
this.downloadUrls,
this.fileDownloadSizes,
this.thumbnail,
this.privateUrl
)
Expand Down
57 changes: 50 additions & 7 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
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,
DatasetPermissions,
DatasetLock,
DatasetLockReason,
PrivateUrl
} from '../../domain/models/Dataset'
import { FileDownloadMode, FileDownloadSize, FileSizeUnit } from '../../../files/domain/models/File'

export class JSDatasetMapper {
static toDataset(
Expand All @@ -29,12 +31,19 @@ export class JSDatasetMapper {
summaryFieldsNames: string[],
jsDatasetPermissions: JSDatasetPermissions,
jsDatasetLocks: JSDatasetLock[],
jsDatasetFilesTotalOriginalDownloadSize: number,
jsDatasetFilesTotalArchivalDownloadSize: number,
requestedVersion?: string,
privateUrl?: PrivateUrl
): Dataset {
const version = JSDatasetMapper.toVersion(
jsDataset.versionId,
jsDataset.versionInfo,
requestedVersion
)
return new Dataset.Builder(
jsDataset.persistentId,
JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo, requestedVersion),
version,
citation,
JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, summaryFieldsNames),
jsDataset.license,
Expand All @@ -47,8 +56,14 @@ export class JSDatasetMapper {
JSDatasetMapper.toDatasetPermissions(jsDatasetPermissions),
JSDatasetMapper.toLocks(jsDatasetLocks),
true, // TODO Connect with dataset hasValidTermsOfAccess
true, // TODO Connect with dataset hasOneTabularFileAtLeast
true, // TODO Connect with dataset isValid
JSDatasetMapper.toIsReleased(jsDataset.versionInfo),
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
).build()
Expand Down Expand Up @@ -210,4 +225,32 @@ export class JSDatasetMapper {
}
})
}

static toDownloadUrls(
jsDatasetPersistentId: string,
version: DatasetVersion
): DatasetDownloadUrls {
return {
original: `/api/access/dataset/:persistentId/versions/${version.toString()}?persistentId=${jsDatasetPersistentId}&format=original`,
archival: `/api/access/dataset/:persistentId/versions/${version.toString()}?persistentId=${jsDatasetPersistentId}`
}
}

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,7 +11,9 @@ import {
getDatasetUserPermissions,
ReadError,
getDatasetLocks,
DatasetLock as JSDatasetLock
DatasetLock as JSDatasetLock,
getDatasetFilesTotalDownloadSize,
FileDownloadSizeMode
} from '@iqss/dataverse-client-javascript'
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'
import { TotalDatasetsCount } from '../../domain/models/TotalDatasetsCount'
Expand All @@ -20,7 +22,6 @@ import { DatasetPreview } from '../../domain/models/DatasetPreview'
import { DatasetPreviewMother } from '../../../../tests/component/dataset/domain/models/DatasetPreviewMother'

const includeDeaccessioned = true

export class DatasetJSDataverseRepository implements DatasetRepository {
// eslint-disable-next-line unused-imports/no-unused-vars
getAll(paginationInfo: DatasetPaginationInfo): Promise<DatasetPreview[]> {
Expand Down Expand Up @@ -54,23 +55,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 @@ -99,10 +118,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
36 changes: 30 additions & 6 deletions src/files/domain/models/File.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,6 +63,22 @@ 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)
}
}

export interface FileAccess {
restricted: boolean
latestVersionRestricted: boolean
Expand Down Expand Up @@ -115,6 +131,7 @@ export enum FileLabelType {
CATEGORY = 'category',
TAG = 'tag'
}

export interface FileLabel {
type: FileLabelType
value: string
Expand Down Expand Up @@ -145,6 +162,12 @@ export interface FileIngest {
reportMessage?: string
}

export interface FileDownloadUrls {
original: string
tabular?: string
rData?: string
}

export class File {
constructor(
readonly id: number,
Expand All @@ -158,12 +181,13 @@ export class File {
readonly labels: FileLabel[],
public readonly isDeleted: boolean,
public readonly ingest: FileIngest,
readonly checksum?: FileChecksum,
readonly thumbnail?: string,
public readonly downloadUrls: FileDownloadUrls,
public thumbnail?: string,
readonly directory?: string,
readonly embargo?: FileEmbargo,
readonly tabularData?: FileTabularData,
readonly description?: string
readonly description?: string,
readonly checksum?: FileChecksum
) {}

getLink(): string {
Expand Down
9 changes: 9 additions & 0 deletions src/files/domain/models/FileCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ export class FileCriteria {
searchText
)
}

get someFilterApplied(): boolean {
return (
this.filterByType !== undefined ||
this.filterByAccess !== undefined ||
this.filterByTag !== undefined ||
this.searchText !== undefined
)
}
}

export enum FileSortByOption {
Expand Down
Loading

0 comments on commit 99e16d3

Please sign in to comment.