Skip to content

Commit

Permalink
Add Dataset story; move alert customHeading to translation text
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Oct 6, 2023
1 parent e40738b commit 731997a
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 29 deletions.
15 changes: 12 additions & 3 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@
"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": "Version {{requestedVersion}} was not found. This is version {{returnedVersion}}.",
"unpublishedDataset": "Privately share this dataset before it is published: {{privateUrl}}"
"draftVersion": {
"heading": "This draft version needs to be published",
"alertText": "When ready for sharing, please <b>publish</b> it so that others can see these changes"
},
"requestedVersionNotFound": {
"heading": "Information",
"alertText": "Version {{requestedVersion}} was not found. This is version {{returnedVersion}}."
},
"unpublishedDataset": {
"heading": "Unpublished Dataset Private URL",
"alertText": "Privately share this dataset before it is published: {{privateUrl}}"
}
}
}
14 changes: 3 additions & 11 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export class DatasetAlert {
constructor(
public readonly variant: AlertVariant,
public readonly message: DatasetAlertMessageKey,
public readonly dynamicFields?: {},
public readonly customHeading?: string
public readonly dynamicFields?: object
) {}
}

Expand Down Expand Up @@ -326,9 +325,7 @@ export class Dataset {

private withAlerts(): void {
if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) {
this.alerts.push(
new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION, undefined, 'Info')
)
this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION))
}
if (this.version.requestedVersion) {
const dynamicFields = {
Expand All @@ -347,12 +344,7 @@ export class Dataset {
if (this.privateUrl) {
const dynamicFields = { privateUrl: this.privateUrl }
this.alerts.push(
new DatasetAlert(
'info',
DatasetAlertMessageKey.UNPUBLISHED_DATASET,
dynamicFields,
'Unpublished Dataset Private URL'
)
new DatasetAlert('info', DatasetAlertMessageKey.UNPUBLISHED_DATASET, dynamicFields)
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/sections/dataset/Dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DatasetSummary } from './dataset-summary/DatasetSummary'
import { DatasetCitation } from './dataset-citation/DatasetCitation'
import { DatasetFiles } from './dataset-files/DatasetFiles'
import { FileRepository } from '../../files/domain/repositories/FileRepository'
import { DatasetAlerts } from './dataset-alerts/DatasetAlerts'

interface DatasetProps {
datasetRepository: DatasetRepository
Expand All @@ -38,6 +39,7 @@ export function Dataset({ datasetRepository, fileRepository, searchParams }: Dat
<PageNotFound />
) : (
<article>
<DatasetAlerts alerts={dataset.alerts} />
<header className={styles.header}>
<h1>{dataset.getTitle()}</h1>
<DatasetLabels labels={dataset.labels} />
Expand Down
19 changes: 12 additions & 7 deletions src/sections/dataset/dataset-alerts/DatasetAlerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ export function DatasetAlerts({ alerts }: DatasetAlertsProps) {

return (
<div className={styles.container}>
{alerts.map((alert: DatasetAlert) => {
const translatedHTML = alert.dynamicFields
? t(`alerts.${alert.message}`, alert.dynamicFields)
: t(`alerts.${alert.message}`)

{alerts.map((alert: DatasetAlert, index) => {
const translatedMsg = alert.dynamicFields
? t(`alerts.${alert.message}.alertText`, alert.dynamicFields)
: t(`alerts.${alert.message}.alertText`)
const translatedHeading = t(`alerts.${alert.message}.heading`)
const alertKey = `alert-${index}`
return (
<Alert variant={alert.variant} customHeading={alert.customHeading} dismissible={false}>
{parse(translatedHTML)}
<Alert
key={alertKey}
variant={alert.variant}
customHeading={translatedHeading}
dismissible={false}>
{parse(translatedMsg)}
</Alert>
)
})}
Expand Down
3 changes: 2 additions & 1 deletion src/stories/dataset/Dataset.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { WithSettings } from '../WithSettings'
import { WithLoggedInUser } from '../WithLoggedInUser'
import { WithFilePermissionsDenied } from '../files/file-permission/WithFilePermissionsDenied'
import { WithFilePermissionsGranted } from '../files/file-permission/WithFilePermissionsGranted'
import { DatasetMockDraftVersionRepository } from './DatasetMockDraftVersionRepository'

const meta: Meta<typeof Dataset> = {
title: 'Pages/Dataset',
Expand Down Expand Up @@ -41,7 +42,7 @@ export const LoggedInAsOwner: Story = {
decorators: [WithLayout, WithLoggedInUser, WithFilePermissionsGranted],
render: () => (
<Dataset
datasetRepository={new DatasetMockRepository()}
datasetRepository={new DatasetMockDraftVersionRepository()}
fileRepository={new FileMockRepository()}
searchParams={{ persistentId: 'doi:10.5082/FK2/ABC123' }}
/>
Expand Down
111 changes: 111 additions & 0 deletions src/stories/dataset/DatasetMockDataDraftVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {
ANONYMIZED_FIELD_VALUE,
DatasetPublishingStatus,
DatasetVersion,
DatasetLabelSemanticMeaning,
DatasetLabelValue,
DatasetMetadataBlocks
} from '../../dataset/domain/models/Dataset'
import { MetadataBlockName } from '../../dataset/domain/models/Dataset'
import { Dataset } from '../../dataset/domain/models/Dataset'

export const DatasetMockDataDraftVersion = (
props?: Partial<Dataset>,
anonymized = false
): Dataset => {
const dataset = {
persistentId: 'doi:10.5072/FK2/ABC123',
citation: `${
anonymized ? 'Author name(s) withheld' : 'Bennet, Elizabeth; Darcy, Fitzwilliam'
}, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, V1`,
version: new DatasetVersion(1, DatasetPublishingStatus.DRAFT, 1, 0),
labels: [
{ value: 'Version 1.0', semanticMeaning: DatasetLabelSemanticMeaning.FILE },
{ value: DatasetLabelValue.DRAFT, semanticMeaning: DatasetLabelSemanticMeaning.DATASET }
],
license: {
name: 'CC0 1.0',
uri: 'https://creativecommons.org/publicdomain/zero/1.0/',
iconUri: 'https://licensebuttons.net/p/zero/1.0/88x31.png'
},
summaryFields: [
{
name: MetadataBlockName.CITATION,
fields: {
dsDescription: [
{
dsDescriptionValue:
'This text is *italic* and this is **bold**. Here is an image ![Alt text](https://picsum.photos/id/10/20/20) '
}
],
keyword: 'Malaria, Tuberculosis, Drug Resistant',
subject: 'Medicine, Health and Life Sciences, Social Sciences',
publication: 'CNN Journal [CNN.com](https://cnn.com)',
notesText: 'Here is an image ![Alt text](https://picsum.photos/id/10/40/40)'
}
}
],
metadataBlocks: [
{
name: MetadataBlockName.CITATION,
fields: {
alternativePersistentId: 'doi:10.5072/FK2/ABC123',
publicationDate: anonymized ? ANONYMIZED_FIELD_VALUE : '2021-01-01',
citationDate: '2023-01-01',
title: 'Dataset Title',
subject: ['Subject1', 'Subject2'],
author: anonymized
? ANONYMIZED_FIELD_VALUE
: [
{
authorName: 'Admin, Dataverse',
authorAffiliation: 'Dataverse.org',
authorIdentifierScheme: 'ORCID',
authorIdentifier: '0000-0002-1825-1097'
},
{
authorName: 'Owner, Dataverse',
authorAffiliation: 'Dataverse.org',
authorIdentifierScheme: 'ORCID',
authorIdentifier: '0000-0032-1825-0098'
}
],
datasetContact: anonymized
? ANONYMIZED_FIELD_VALUE
: [
{
datasetContactName: 'Admin, Dataverse'
}
],
dsDescription: [
{
dsDescriptionValue:
'This text is *italic* and this is **bold**. Here is an image ![Alt text](https://picsum.photos/id/10/20/20) '
}
]
}
},
{
name: MetadataBlockName.GEOSPATIAL,
fields: {
geographicUnit: 'km',
geographicCoverage: anonymized
? ANONYMIZED_FIELD_VALUE
: {
geographicCoverageCountry: 'United States',
geographicCoverageCity: 'Cambridge'
}
}
}
] as DatasetMetadataBlocks,
...props
}
return new Dataset.Builder(
dataset.persistentId,
dataset.version,
dataset.citation,
dataset.summaryFields,
dataset.license,
dataset.metadataBlocks
).build()
}
22 changes: 22 additions & 0 deletions src/stories/dataset/DatasetMockDraftVersionRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DatasetRepository } from '../../dataset/domain/repositories/DatasetRepository'
import { Dataset as DatasetModel } from '../../dataset/domain/models/Dataset'
import { DatasetMockDataDraftVersion } from './DatasetMockDataDraftVersion'

export class DatasetMockDraftVersionRepository implements DatasetRepository {
getByPersistentId(persistentId: string): Promise<DatasetModel | undefined> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(DatasetMockDataDraftVersion({ persistentId: persistentId }))
}, 1000)
})
}

// eslint-disable-next-line unused-imports/no-unused-vars
getByPrivateUrlToken(privateUrlToken: string): Promise<DatasetModel | undefined> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(DatasetMockDataDraftVersion({}, true))
}, 1000)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ const expectedDataset = {
{ semanticMeaning: 'dataset', value: 'Draft' },
{ semanticMeaning: 'warning', value: 'Unpublished' }
],
alerts: [
{ variant: 'warning', message: 'draftVersion', dynamicFields: undefined, customHeading: 'Info' }
],
alerts: [{ variant: 'warning', message: 'draftVersion', dynamicFields: undefined }],
summaryFields: [
{
name: 'citation',
Expand Down Expand Up @@ -126,14 +124,12 @@ const expectedDatasetAlternateVersion = {
{
variant: 'warning',
message: 'draftVersion',
dynamicFields: undefined,
customHeading: 'Info'
dynamicFields: undefined
},
{
message: 'requestedVersionNotFound',
variant: 'info',
dynamicFields: ['4.0', '0.0'],
customHeading: undefined
dynamicFields: { requestedVersion: '4.0', returnedVersion: '0.0' }
}
],
summaryFields: [
Expand Down

0 comments on commit 731997a

Please sign in to comment.