Skip to content

Commit

Permalink
Merge pull request #260 from IQSS/feature/249-boilerplate-file-page
Browse files Browse the repository at this point in the history
249 - File Page boilerplate
  • Loading branch information
GPortas authored Jan 19, 2024
2 parents baa7faf + 1f28e78 commit 4dba60a
Show file tree
Hide file tree
Showing 167 changed files with 1,999 additions and 1,597 deletions.
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
199 changes: 109 additions & 90 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,112 @@ 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.createLabels()
}

createLabels() {
const statusLabels = this.createStatusLabels()
const versionLabels = this.createVersionNumberLabel()
this.labels.push(...statusLabels, ...versionLabels)
}

createStatusLabels(): DatasetLabel[] {
const labels: DatasetLabel[] = []

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

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

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

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

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

return labels
}

createVersionNumberLabel(): DatasetLabel[] {
const labels: DatasetLabel[] = []
if (this.publishingStatus === DatasetPublishingStatus.RELEASED) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.number.toString()}`)
)
}
return labels
}

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 +361,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 +370,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 @@ -354,72 +436,12 @@ export class Dataset {
return false
}

static createDatasetLabels(version: DatasetVersion, isReleased: boolean): DatasetLabel[] {
const statusLabels = Dataset.createStatusLabels(
version.publishingStatus,
version.isInReview,
isReleased
)
const versionLabels = Dataset.createVersionLabel(version)
return [...statusLabels, ...versionLabels] // combine and return
}

static createStatusLabels(
publishingStatus: DatasetPublishingStatus,
isInReview: boolean,
isReleased: boolean
): DatasetLabel[] {
const labels: DatasetLabel[] = []

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

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

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

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

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

return labels
}

static createVersionLabel(version: DatasetVersion): DatasetLabel[] {
const labels: DatasetLabel[] = []
if (version.publishingStatus === DatasetPublishingStatus.RELEASED) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${version.toString()}`)
)
}
return labels
}

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 @@ -428,13 +450,12 @@ 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.labels = Dataset.createDatasetLabels(version, isReleased)
this.withAlerts()
}

Expand All @@ -445,18 +466,18 @@ export class Dataset {
) {
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 @@ -483,8 +504,6 @@ export class Dataset {
return new Dataset(
this.persistentId,
this.version,
this.citation,
this.labels,
this.alerts,
this.summaryFields,
this.license,
Expand All @@ -494,11 +513,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
16 changes: 2 additions & 14 deletions src/dataset/domain/models/DatasetPreview.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { DatasetLabel, DatasetVersion, Dataset } from './Dataset'
import { DatasetVersion } from './Dataset'

export class DatasetPreview {
public labels: DatasetLabel[]

constructor(
public persistentId: string,
public title: string,
public version: DatasetVersion,
public isReleased: boolean,
public citation: string,
public isDeaccessioned: boolean,
public releaseOrCreateDate: Date,
public description: string,
public thumbnail?: string
) {
this.labels = Dataset.createStatusLabels(
version.publishingStatus,
version.isInReview,
this.isReleased
)
}
) {}

get abbreviatedDescription(): string {
if (this.description.length > 280) {
Expand Down
Loading

0 comments on commit 4dba60a

Please sign in to comment.