Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

249 - File Page boilerplate #260

Merged
merged 20 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c5852c6
feat(FilePage): add the File Page
MellyGray Dec 13, 2023
df0a00b
feat(FilePage): add loading state
MellyGray Dec 13, 2023
4090af5
feat(FilePage): add file not found state
MellyGray Dec 13, 2023
9864ba1
feat(FilePage): add route to the page
MellyGray Dec 13, 2023
9c3a455
Merge branch 'develop' of https://github.com/IQSS/dataverse-frontend …
MellyGray Dec 15, 2023
37180ad
refactor: move citation to DatasetVersion
MellyGray Dec 15, 2023
62b69b2
refactor: move title to DatasetVersion
MellyGray Dec 15, 2023
030b794
refactor: move labels to DatasetVersion
MellyGray Dec 18, 2023
3d4c78a
feat(FilePage): add datasetVersion property to File model
MellyGray Dec 18, 2023
e1ed09a
refactor: pass datasetVersionNumber as files use cases argument
MellyGray Dec 19, 2023
be47437
Merge branch 'develop' of https://github.com/IQSS/dataverse-frontend …
MellyGray Dec 19, 2023
83748bf
Merge branch 'develop' of https://github.com/IQSS/dataverse-frontend …
MellyGray Dec 20, 2023
8665490
feat(DatsetCard): refactor with the new DatasetVersion
MellyGray Dec 21, 2023
3cbbd40
feat(FileLabels): add DatasetLabels to File Page
MellyGray Dec 21, 2023
b7bc8ce
refactor: FileFileAccessRestrictedIcon move to file folder
MellyGray Dec 21, 2023
9b1c321
feat(FileLabels): add Restricted icon to File Labels
MellyGray Dec 22, 2023
95fd1a3
fix: remove demo dataverse reference in page not found message
MellyGray Jan 8, 2024
4f9728e
fix: e2e test year dependence
MellyGray Jan 8, 2024
b5f65e2
Merge pull request #271 from IQSS/feature/262-file-labels-section-of-…
ekraffmiller Jan 8, 2024
1f28e78
Merge branch 'develop' of https://github.com/IQSS/dataverse-frontend …
MellyGray Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions public/locales/en/file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"tabs": {
"metadata": "Metadata"
},
"subtext": "This file is part of \"{{datasetTitle}}\".",
"fileAccess": {
"title": "File Access",
"restricted": {
"name": "Restricted",
"icon": "Restricted File Icon"
},
"restrictedWithAccess": {
"name": "Restricted with Access Granted",
"icon": "Restricted with access Icon"
},
"embargoed": {
"name": "Embargoed"
},
"public": {
"name": "Public",
"icon": "Public File Icon"
}
}
}
18 changes: 0 additions & 18 deletions public/locales/en/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@
"published": "Published",
"deposited": "Deposited"
},
"fileAccess": {
"title": "File Access",
"restricted": {
"name": "Restricted",
"icon": "Restricted File Icon"
},
"restrictedWithAccess": {
"name": "Restricted with Access Granted",
"icon": "Restricted with access Icon"
},
"embargoed": {
"name": "Embargoed"
},
"public": {
"name": "Public",
"icon": "Public File Icon"
}
},
"copyToClipboard": {
"clickToCopy": "Click to copy",
"correctlyCopiedIcon": "Correctly copied to clipboard icon",
Expand Down
2 changes: 1 addition & 1 deletion public/locales/en/pageNotFound.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"heading": "Page Not Found",
"message": "The page you are looking for was not found. If you believe this is an error, please contact Demo Dataverse Support for assistance."
"message": "The page you are looking for was not found."
}
7 changes: 6 additions & 1 deletion src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createBrowserRouter, RouterProvider } from 'react-router-dom'
import { Layout } from './sections/layout/Layout'
import { Route } from './sections/Route.enum'
import { DatasetFactory } from './sections/dataset/DatasetFactory'
import { FileFactory } from './sections/file/FileFactory'
import { HomeFactory } from './sections/home/HomeFactory'

const router = createBrowserRouter(
Expand All @@ -15,8 +16,12 @@ const router = createBrowserRouter(
element: HomeFactory.create()
},
{
path: `${Route.DATASETS}`,
path: Route.DATASETS,
element: DatasetFactory.create()
},
{
path: Route.FILES,
element: FileFactory.create()
}
]
}
Expand Down
181 changes: 104 additions & 77 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alert, AlertMessageKey } from '../../../alert/domain/models/Alert'
import { FileDownloadSize } from '../../../files/domain/models/File'
import { FileDownloadSize } from '../../../files/domain/models/FilePreview'

export enum DatasetLabelSemanticMeaning {
DATASET = 'dataset',
Expand Down Expand Up @@ -213,24 +213,107 @@ export enum DatasetNonNumericVersion {
DRAFT = ':draft'
}

export class DatasetVersionNumber {
constructor(public readonly majorNumber?: number, public readonly minorNumber?: number) {}

toString(): string | DatasetNonNumericVersion {
if (this.majorNumber === undefined || this.minorNumber === undefined) {
return DatasetNonNumericVersion.DRAFT
}
return `${this.majorNumber}.${this.minorNumber}`
}
}

export class DatasetVersion {
constructor(
public readonly id: number,
public readonly title: string,
public readonly number: DatasetVersionNumber,
public readonly publishingStatus: DatasetPublishingStatus,
public readonly citation: string,
public readonly labels: DatasetLabel[],
public readonly isLatest: boolean,
public readonly isInReview: boolean,
public readonly latestVersionStatus: DatasetPublishingStatus,
public readonly majorNumber?: number,
public readonly minorNumber?: number,
// requestedVersion will be set if the user requested a version that did not exist.
public readonly requestedVersion?: string
public readonly latestVersionPublishingStatus: DatasetPublishingStatus,
public readonly someDatasetVersionHasBeenReleased: boolean
) {}

toString(): string | DatasetNonNumericVersion {
if (this.majorNumber === undefined || this.minorNumber === undefined) {
return DatasetNonNumericVersion.DRAFT
static Builder = class {
public readonly labels: DatasetLabel[] = []

constructor(
public readonly id: number,
public readonly title: string,
public readonly number: DatasetVersionNumber,
public readonly publishingStatus: DatasetPublishingStatus,
public readonly citation: string,
public readonly isLatest: boolean,
public readonly isInReview: boolean,
public readonly latestVersionPublishingStatus: DatasetPublishingStatus,
public readonly someDatasetVersionHasBeenReleased: boolean
) {
this.withLabels()
}

withLabels() {
this.withStatusLabel()
this.withVersionLabel()
}

private withStatusLabel(): void {
if (this.publishingStatus === DatasetPublishingStatus.DRAFT) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT)
)
}

if (!this.someDatasetVersionHasBeenReleased) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.WARNING, DatasetLabelValue.UNPUBLISHED)
)
}

if (this.publishingStatus === DatasetPublishingStatus.DEACCESSIONED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DANGER, DatasetLabelValue.DEACCESSIONED)
)
}

if (this.publishingStatus === DatasetPublishingStatus.EMBARGOED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.EMBARGOED)
)
}

if (this.isInReview) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.SUCCESS, DatasetLabelValue.IN_REVIEW)
)
}
}

private withVersionLabel(): void {
if (this.publishingStatus === DatasetPublishingStatus.RELEASED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.number.toString()}`)
)
}
}

build(): DatasetVersion {
return new DatasetVersion(
this.id,
this.title,
this.number,
this.publishingStatus,
this.citation,
this.labels,
this.isLatest,
this.isInReview,
this.latestVersionPublishingStatus,
this.someDatasetVersionHasBeenReleased
)
}
return `${this.majorNumber}.${this.minorNumber}`
}
}

Expand Down Expand Up @@ -273,8 +356,6 @@ export class Dataset {
constructor(
public readonly persistentId: string,
public readonly version: DatasetVersion,
public readonly citation: string,
public readonly labels: DatasetLabel[],
public readonly alerts: Alert[],
public readonly summaryFields: DatasetMetadataBlock[],
public readonly license: DatasetLicense,
Expand All @@ -284,17 +365,13 @@ export class Dataset {
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
public readonly privateUrl?: PrivateUrl,
public readonly requestedVersion?: string // will be set if the user requested a version that did not exist
) {}

public get title(): string {
return this.metadataBlocks[0].fields.title
}

public checkIsLockedFromPublishing(userPersistentId: string): boolean {
return this.checkIsLockedFromEdits(userPersistentId)
}
Expand Down Expand Up @@ -355,13 +432,11 @@ export class Dataset {
}

static Builder = class {
public readonly labels: DatasetLabel[] = []
public readonly alerts: Alert[] = []

constructor(
public readonly persistentId: string,
public readonly version: DatasetVersion,
public readonly citation: string,
public readonly summaryFields: DatasetMetadataBlock[],
public readonly license: DatasetLicense = defaultLicense,
public readonly metadataBlocks: DatasetMetadataBlocks,
Expand All @@ -370,80 +445,34 @@ export class Dataset {
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
public readonly privateUrl?: PrivateUrl,
public readonly requestedVersion?: string // will be set if the user requested a version that did not exist
) {
this.withLabels()
this.withAlerts()
}

withLabels() {
this.withStatusLabel()
this.withVersionLabel()
}

private withStatusLabel(): void {
if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT)
)
}

if (!this.isReleased) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.WARNING, DatasetLabelValue.UNPUBLISHED)
)
}

if (this.version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DANGER, DatasetLabelValue.DEACCESSIONED)
)
}

if (this.version.publishingStatus === DatasetPublishingStatus.EMBARGOED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.EMBARGOED)
)
}

if (this.version.isInReview) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.SUCCESS, DatasetLabelValue.IN_REVIEW)
)
}
}

private withVersionLabel(): void {
if (this.version.publishingStatus === DatasetPublishingStatus.RELEASED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.version.toString()}`)
)
}
}

private withAlerts(): void {
if (
this.version.publishingStatus === DatasetPublishingStatus.DRAFT &&
this.permissions.canPublishDataset
) {
this.alerts.push(new Alert('warning', AlertMessageKey.DRAFT_VERSION))
}
if (this.version.requestedVersion) {
if (this.version.latestVersionStatus == DatasetPublishingStatus.RELEASED) {
if (this.requestedVersion) {
if (this.version.latestVersionPublishingStatus == DatasetPublishingStatus.RELEASED) {
const dynamicFields = {
requestedVersion: this.version.requestedVersion,
returnedVersion: `${this.version.toString()}`
requestedVersion: this.requestedVersion,
returnedVersion: `${this.version.number.toString()}`
}
this.alerts.push(
new Alert('warning', AlertMessageKey.REQUESTED_VERSION_NOT_FOUND, dynamicFields)
)
} else {
const dynamicFields = {
requestedVersion: this.version.requestedVersion
requestedVersion: this.requestedVersion
}
this.alerts.push(
new Alert(
Expand All @@ -470,8 +499,6 @@ export class Dataset {
return new Dataset(
this.persistentId,
this.version,
this.citation,
this.labels,
this.alerts,
this.summaryFields,
this.license,
Expand All @@ -481,11 +508,11 @@ export class Dataset {
this.hasValidTermsOfAccess,
this.hasOneTabularFileAtLeast,
this.isValid,
this.isReleased,
this.downloadUrls,
this.fileDownloadSizes,
this.thumbnail,
this.privateUrl
this.privateUrl,
this.requestedVersion
)
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/dataset/domain/models/DatasetPreview.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { DatasetLabel, DatasetVersion } from './Dataset'
import { DatasetVersion } from './Dataset'

export class DatasetPreview {
constructor(
public persistentId: string,
public title: string,
public version: DatasetVersion,
public citation: string,
public labels: DatasetLabel[],
public isDeaccessioned: boolean,
public releaseOrCreateDate: Date,
public description: string,
public thumbnail?: string
Expand Down
Loading