Skip to content

Commit

Permalink
resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Dec 18, 2023
2 parents b4d3a37 + 48c2521 commit 5f42e1b
Show file tree
Hide file tree
Showing 66 changed files with 1,687 additions and 344 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,51 @@
## 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

First install node >=16 and npm >=8. Recommended versions `node v19` and `npm v9`.

### Create a `.npmrc` file and add a token

To install the [@iqss/dataverse-client-javascript](https://github.com/IQSS/dataverse-client-javascript/pkgs/npm/dataverse-client-javascript)
from the GitHub registry, necessary for connecting with the Dataverse API, follow these steps to create an `.npmrc` file in
the root of your project using your GitHub token.

1. **Copy `.npmrc.example`**

Duplicate the `.npmrc.example` file in your project and save it as `.npmrc`.

2. **Replace the Token**

Open the newly created `.npmrc` file and replace `YOUR_GITHUB_TOKEN` with your actual GitHub token.

```plaintext
legacy-peer-deps=true
//npm.pkg.github.com/:_authToken=<YOUR_GITHUB_AUTH_TOKEN>
@iqss:registry=https://npm.pkg.github.com/
```

#### How to Get a GitHub Token

If you don't have a GitHub token yet, follow these steps:

1. Go to your GitHub account settings.

2. Navigate to "Developer settings" -> "Personal access tokens."

3. Click "Personal access tokens" -> "Tokens (classic)" -> "Generate new token (classic)".

4. Give the token a name and select the "read:packages" scope.

5. Copy the generated token.

6. Replace `YOUR_GITHUB_AUTH_TOKEN` in the `.npmrc` file with the copied token.

Now, you should be able to install the Dataverse JavaScript client using npm.

### `npm install`

Run this command to install the dependencies. You may see a message about vulnerabilities after running this command. \
Expand Down
1 change: 1 addition & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN npm run build

WORKDIR /usr/src/app
COPY package.json ./
COPY package-lock.json ./
COPY .npmrc ./
RUN npm install

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"i18next": "22.4.9",
"i18next-browser-languagedetector": "7.0.1",
"i18next-http-backend": "2.1.1",
"moment-timezone": "^0.5.43",
"moment-timezone": "0.5.43",
"react-bootstrap": "2.7.2",
"react-bootstrap-icons": "1.10.3",
"react-i18next": "12.1.5",
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
89 changes: 72 additions & 17 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
import {
Dataset as JSDataset,
DatasetLock as JSDatasetLock,
DatasetMetadataBlock as JSDatasetMetadataBlock,
DatasetMetadataBlocks as JSDatasetMetadataBlocks,
DatasetMetadataFields as JSDatasetMetadataFields,
DatasetVersionInfo as JSDatasetVersionInfo,
DatasetLock as JSDatasetLock
DatasetUserPermissions as JSDatasetPermissions,
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,
DatasetLock,
DatasetLockReason
PrivateUrl
} from '../../domain/models/Dataset'
import { FileDownloadMode, FileDownloadSize, FileSizeUnit } from '../../../files/domain/models/File'

export class JSDatasetMapper {
static toDataset(
jsDataset: JSDataset,
citation: string,
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 @@ -41,19 +53,17 @@ export class JSDatasetMapper {
jsDataset.publicationDate,
jsDataset.citationDate
),
{
canDownloadFiles: true,
canUpdateDataset: true,
canPublishDataset: true,
canManageDatasetPermissions: true,
canManageFilesPermissions: true,
canDeleteDataset: true
}, // TODO Connect with dataset permissions
JSDatasetMapper.toDatasetPermissions(jsDatasetPermissions),
JSDatasetMapper.toLocks(jsDatasetLocks),
true, // TODO Connect with dataset hasValidTermsOfAccess
true, // TODO Connect with dataset hasOneTabularFileAtLeast
true, // TODO Connect with dataset isValid
jsDataset.versionInfo.releaseTime !== undefined &&
!isNaN(jsDataset.versionInfo.releaseTime.getTime()), // TODO Connect with dataset isReleased,
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 @@ -190,6 +200,23 @@ export class JSDatasetMapper {
return extraFields
}

static toIsReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean {
return (
jsDatasetVersionInfo.releaseTime !== undefined &&
!isNaN(jsDatasetVersionInfo.releaseTime.getTime())
)
}

static toDatasetPermissions(jsDatasetPermissions: JSDatasetPermissions): DatasetPermissions {
return {
canDownloadFiles: true, // TODO: connect with js-dataverse
canUpdateDataset: jsDatasetPermissions.canEditDataset,
canPublishDataset: jsDatasetPermissions.canPublishDataset,
canManageDatasetPermissions: jsDatasetPermissions.canManageDatasetPermissions,
canManageFilesPermissions: true, // TODO: connect with js-dataverse DatasetPermissions.canManageFilesPermissions
canDeleteDataset: jsDatasetPermissions.canManageDatasetPermissions
}
}
static toLocks(jsDatasetLocks: JSDatasetLock[]): DatasetLock[] {
return jsDatasetLocks.map((jsDatasetLock) => {
return {
Expand All @@ -198,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
)
]
}
}
Loading

0 comments on commit 5f42e1b

Please sign in to comment.