Skip to content

Commit

Permalink
Merge pull request #190 from IQSS/feature/99-alert-mechanism
Browse files Browse the repository at this point in the history
Feature/99 alert mechanism
  • Loading branch information
kcondon authored Oct 18, 2023
2 parents 403f161 + 9718e1e commit 74bb2de
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 43 deletions.
15 changes: 14 additions & 1 deletion package-lock.json

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

18 changes: 9 additions & 9 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@
},
"dependencies": {
"@types/react": "18.0.27",
"typescript": "4.9.5",
"vite-plugin-istanbul": "4.0.1",
"bootstrap": "5.2.3",
"react-bootstrap": "2.7.2",
"react-bootstrap-icons": "1.10.3",
"sass": "1.58.1"
"sass": "1.58.1",
"vite-plugin-istanbul": "4.0.1"
},
"devDependencies": {
"@vitejs/plugin-react": "3.1.0",
"@testing-library/cypress": "9.0.0",
"@storybook/react": "7.0.2",
"@storybook/test-runner": "0.10.0",
"@testing-library/cypress": "9.0.0",
"@vitejs/plugin-react": "3.1.0",
"axe-playwright": "1.2.3",
"chromatic": "6.17.4",
"cypress": "12.5.1",
"react": "18.2.0",
"typescript": "^5.2.2",
"vite": "4.1.5",
"vite-plugin-dts": "2.3.0",
"vite-plugin-libcss": "1.0.6",
"react": "18.2.0",
"axe-playwright": "1.2.3",
"chromatic": "6.17.4"
"vite-plugin-libcss": "1.0.6"
},
"files": [
"dist",
Expand Down
5 changes: 5 additions & 0 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@
"title": "Access Dataset"
},
"uploadFiles": "Upload Files"
},
"alerts": {
"draftVersion": "<b>This draft version needs to be published</b>. When ready for sharing, please <b>publish</b> it so that others can see these changes",
"requestedVersionNotFound": "Info – Version {0} was not found. This is version {1}",
"unpublishedDataset": "Privately share this dataset before it is published: {0}"
}
}
59 changes: 57 additions & 2 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AlertVariant } from '@iqss/dataverse-design-system/dist/components/alert/AlertVariant'

export enum DatasetLabelSemanticMeaning {
DATASET = 'dataset',
FILE = 'file',
Expand All @@ -22,6 +24,21 @@ export class DatasetLabel {
) {}
}

export enum DatasetAlertMessageKey {
DRAFT_VERSION = 'draftVersion',
REQUESTED_VERSION_NOT_FOUND = 'requestedVersionNotFound',
UNPUBLISHED_DATASET = 'unpublishedDataset'
}

export class DatasetAlert {
constructor(
public readonly variant: AlertVariant,
public readonly message: DatasetAlertMessageKey,
public readonly dynamicFields?: string[],
public readonly customHeading?: string
) {}
}

export enum MetadataBlockName {
CITATION = 'citation',
GEOSPATIAL = 'geospatial',
Expand Down Expand Up @@ -191,6 +208,7 @@ export interface DatasetLicense {
uri: string
iconUri?: string
}

const defaultLicense: DatasetLicense = {
name: 'CC0 1.0',
uri: 'https://creativecommons.org/publicdomain/zero/1.0',
Expand All @@ -217,7 +235,9 @@ export class DatasetVersion {
public readonly isInReview: boolean,
public readonly latestVersionStatus: DatasetPublishingStatus,
public readonly majorNumber?: number,
public readonly minorNumber?: number
public readonly minorNumber?: number,
// requestedVersion will be set if the user requested a version that did not exist.
public readonly requestedVersion?: string
) {}

toString(): string | DatasetNonNumericVersion {
Expand Down Expand Up @@ -260,6 +280,7 @@ export class Dataset {
public readonly version: DatasetVersion,
public readonly citation: string,
public readonly labels: DatasetLabel[],
public readonly alerts: DatasetAlert[],
public readonly summaryFields: DatasetMetadataBlock[],
public readonly license: DatasetLicense,
public readonly metadataBlocks: DatasetMetadataBlocks,
Expand Down Expand Up @@ -298,6 +319,7 @@ export class Dataset {

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

constructor(
public readonly persistentId: string,
Expand All @@ -310,9 +332,11 @@ export class Dataset {
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly isValid: boolean,
public readonly isReleased: boolean
public readonly isReleased: boolean,
public readonly privateUrl?: string
) {
this.withLabels()
this.withAlerts()
}

withLabels() {
Expand Down Expand Up @@ -360,12 +384,43 @@ export class Dataset {
}
}

private withAlerts(): void {
if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) {
this.alerts.push(
new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION, undefined, 'Info')
)
}
if (this.version.requestedVersion) {
const dynamicFields = [this.version.requestedVersion, `${this.version.toString()}`]

this.alerts.push(
new DatasetAlert(
'info',
DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND,
dynamicFields
)
)
}
if (this.privateUrl) {
const dynamicFields = [this.privateUrl]
this.alerts.push(
new DatasetAlert(
'info',
DatasetAlertMessageKey.UNPUBLISHED_DATASET,
dynamicFields,
'Unpublished Dataset Private URL'
)
)
}
}

build(): Dataset {
return new Dataset(
this.persistentId,
this.version,
this.citation,
this.labels,
this.alerts,
this.summaryFields,
this.license,
this.metadataBlocks,
Expand Down
43 changes: 38 additions & 5 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,41 @@ import {
MetadataBlockName
} from '../../domain/models/Dataset'

/*
static Builder = class {
public readonly labels: DatasetLabel[] = []
public readonly alerts: DatasetAlert[] = []
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,
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly isValid: boolean,
public readonly isReleased: boolean,
public readonly privateUrl?: string
) {
this.withLabels()
this.withAlerts()
}
*/
export class JSDatasetMapper {
static toDataset(jsDataset: JSDataset, citation: string, summaryFieldsNames: string[]): Dataset {
static toDataset(
jsDataset: JSDataset,
citation: string,
summaryFieldsNames: string[],
requestedVersion?: string,
privateUrl?: string
): Dataset {
return new Dataset.Builder(
jsDataset.persistentId,
JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo),
JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo, requestedVersion),
citation,
JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, summaryFieldsNames),
jsDataset.license,
Expand All @@ -41,13 +71,15 @@ export class JSDatasetMapper {
[], // TODO Connect with dataset locks
true, // TODO Connect with dataset hasValidTermsOfAccess
true, // TODO Connect with dataset isValid
!!jsDataset.versionInfo.releaseTime // TODO Connect with dataset isReleased
!!jsDataset.versionInfo.releaseTime, // TODO Connect with dataset isReleased,
privateUrl
).build()
}

static toVersion(
jDatasetVersionId: number,
jsDatasetVersionInfo: JSDatasetVersionInfo
jsDatasetVersionInfo: JSDatasetVersionInfo,
requestedVersion?: string
): DatasetVersion {
return new DatasetVersion(
jDatasetVersionId,
Expand All @@ -56,7 +88,8 @@ export class JSDatasetMapper {
false, // TODO Connect with dataset version isInReview
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), // TODO Connect with dataset version latestVersionState
jsDatasetVersionInfo.majorNumber,
jsDatasetVersionInfo.minorNumber
jsDatasetVersionInfo.minorNumber,
requestedVersion
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'

export class DatasetJSDataverseRepository implements DatasetRepository {
getByPersistentId(persistentId: string, version?: string): Promise<Dataset | undefined> {
getByPersistentId(
persistentId: string,
version?: string,
requestedVersion?: string
): Promise<Dataset | undefined> {
return getDataset
.execute(persistentId, this.versionToVersionId(version))
.then((jsDataset) =>
Expand All @@ -23,13 +27,13 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
])
)
.then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) =>
JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames)
JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, requestedVersion)
)
.catch((error: WriteError) => {
if (!version) {
throw new Error(error.message)
}
return this.getByPersistentId(persistentId)
return this.getByPersistentId(persistentId, undefined, (requestedVersion = version))
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function FileDate({ date }: { date: FileDateModel }) {
<div>
<span>
{t(`table.date.${date.type}`)}{' '}
{date.date.toLocaleDateString('en-US', {
{date.date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, {
year: 'numeric',
month: 'short',
day: 'numeric'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function FileEmbargoDate({ embargo, publishingStatus }: FileEmbargoDatePr
<div>
<span>
{t(embargoTypeOfDate(embargo.isActive, publishingStatus))}{' '}
{embargo.dateAvailable.toLocaleDateString('en-US', {
{embargo.dateAvailable.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, {
year: 'numeric',
month: 'short',
day: 'numeric'
Expand Down
Loading

0 comments on commit 74bb2de

Please sign in to comment.