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

Feature/127 add alert messages to dataset view #194

Merged
merged 31 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5c00ae0
feature: DatasetAlert component and first story
ekraffmiller Oct 6, 2023
da02bc4
add VersionNotFound and PrivateUrl stories
ekraffmiller Oct 6, 2023
e40738b
remove unused code
ekraffmiller Oct 6, 2023
731997a
Add Dataset story; move alert customHeading to translation text
ekraffmiller Oct 6, 2023
117a745
add DatasetAlerts.module.scss
ekraffmiller Oct 7, 2023
548119f
add DatasetAlerts unit test
ekraffmiller Oct 9, 2023
5685673
add DatasetAlerts unit test
ekraffmiller Oct 9, 2023
df229db
fix: DatasetAlerts unit test
ekraffmiller Oct 10, 2023
f4f21cc
fix: add spacing around DatasetAlerts component
ekraffmiller Oct 11, 2023
98bbe41
fix: remove unneeded heading text
ekraffmiller Oct 18, 2023
8a73214
merge commit
ekraffmiller Oct 18, 2023
8033dcc
fix: Dataset object in stories
ekraffmiller Oct 19, 2023
87cefb7
fix: lint error
ekraffmiller Oct 19, 2023
2062a4e
fix: Add privateUrl Alert, fix logic for Draft Alert
ekraffmiller Oct 19, 2023
04ce3af
fix: Add privateUrlToken to JSDatasetMapper
ekraffmiller Oct 19, 2023
02f6c1b
refactor: rename privateUrl -> privateUrlToken
ekraffmiller Oct 20, 2023
a4f3694
fix: add privateUrlToken to DatasetMother.
ekraffmiller Oct 20, 2023
fe40b96
fix: use new mock data in DatasetAlert.stories.tsx
ekraffmiller Oct 20, 2023
9fb1991
fix: add tests to DatasetAlerts.spec.tsx
ekraffmiller Oct 20, 2023
671704d
fix: alerts.push() Unpublished Dataset
ekraffmiller Oct 20, 2023
b8bf04d
fix: remove unneeded loop
ekraffmiller Oct 20, 2023
844c6de
fix: add DatasetAlert for VersionNotFoundShowDraft
ekraffmiller Oct 20, 2023
e340b06
fix: add PrivateUrl alert to DatasetAnonymizedView story
ekraffmiller Oct 21, 2023
619bdf0
fix: type safety errors, JSDatasetMapper.spec.ts
ekraffmiller Oct 21, 2023
8b0d7fe
fix: top margin for DatasetAlerts.module.scss
ekraffmiller Oct 21, 2023
0e9deeb
fix: lint error DatasetAlerts.module.scss
ekraffmiller Oct 21, 2023
20f0ecf
fix: make alert box wider
ekraffmiller Oct 23, 2023
57b57a3
fix: add 'privateUrl' to Dataset domain model
ekraffmiller Oct 23, 2023
fccce0e
fix: remove console.log()
ekraffmiller Oct 23, 2023
a441c83
fix: use PrivateUrl object in Dataset domain object
ekraffmiller Oct 26, 2023
ecf87c4
fix: isReleased (will be replaced with dataset isReleased when integ…
ekraffmiller Oct 27, 2023
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
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": "Info – Version {0} was not found. This is version {1}",
"unpublishedDataset": "Privately share this dataset before it is published: {0}"
"draftVersion": {
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
"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": {
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
"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}}"
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
21 changes: 8 additions & 13 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?: string[],
public readonly customHeading?: string
public readonly dynamicFields?: object
) {}
}

Expand Down Expand Up @@ -326,12 +325,13 @@ 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 = [this.version.requestedVersion, `${this.version.toString()}`]
const dynamicFields = {
requestedVersion: this.version.requestedVersion,
returnedVersion: `${this.version.toString()}`
}

this.alerts.push(
new DatasetAlert(
Expand All @@ -342,14 +342,9 @@ export class Dataset {
)
}
if (this.privateUrl) {
const dynamicFields = [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
3 changes: 3 additions & 0 deletions src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.container > * {
margin-right: 0.5em;
}
34 changes: 34 additions & 0 deletions src/sections/dataset/dataset-alerts/DatasetAlerts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Alert } from '@iqss/dataverse-design-system'
import { DatasetAlert } from '../../../dataset/domain/models/Dataset'
import { useTranslation } from 'react-i18next'
import styles from './DatasetAlerts.module.scss'
import parse from 'html-react-parser'

interface DatasetAlertsProps {
alerts: DatasetAlert[]
}

export function DatasetAlerts({ alerts }: DatasetAlertsProps) {
const { t } = useTranslation('dataset')

return (
<div className={styles.container}>
{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
key={alertKey}
variant={alert.variant}
customHeading={translatedHeading}
dismissible={false}>
{parse(translatedMsg)}
</Alert>
)
})}
</div>
)
}
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> = {
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
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)
})
}
}
65 changes: 65 additions & 0 deletions src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type { Meta, StoryObj } from '@storybook/react'
import { DatasetMockData } from '../DatasetMockData'
import {
DatasetAlert,
DatasetAlertMessageKey,
DatasetPublishingStatus,
DatasetVersion
} from '../../../dataset/domain/models/Dataset'
import { DatasetAlerts } from '../../../sections/dataset/dataset-alerts/DatasetAlerts'
import { WithI18next } from '../../WithI18next'

const meta: Meta<typeof DatasetAlerts> = {
title: 'Sections/Dataset Page/DatasetAlerts',
component: DatasetAlerts,
decorators: [WithI18next]
}

export default meta
type Story = StoryObj<typeof DatasetAlerts>

export const DraftVersion: Story = {
render: () => {
const dataset = DatasetMockData({
version: new DatasetVersion(1, DatasetPublishingStatus.DRAFT, 1, 0)
})
return (
<div>
<DatasetAlerts alerts={dataset.alerts} />
</div>
)
}
}
export const VersionNotFound: Story = {
render: () => {
const dataset = DatasetMockData({
version: new DatasetVersion(1, DatasetPublishingStatus.RELEASED, 1, 0, '3.0')
})
return (
<div>
<DatasetAlerts alerts={dataset.alerts} />
</div>
)
}
}
export const PrivateUrl: Story = {
render: () => {
const alerts = [
new DatasetAlert(
'info',
DatasetAlertMessageKey.UNPUBLISHED_DATASET,
{
privateUrl:
'http://localhost:8080/privateurl.xhtml?token=f6815782-1227-4d80-a46d-91621c2d9386'
},
'Unpublished Dataset Private URL'
)
]

return (
<div>
<DatasetAlerts alerts={alerts} />
</div>
)
}
}
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
Loading
Loading