Skip to content

Commit

Permalink
add VersionNotFound and PrivateUrl stories
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Oct 6, 2023
1 parent 5c00ae0 commit da02bc4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
4 changes: 2 additions & 2 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"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}"
"requestedVersionNotFound": "Version {{requestedVersion}} was not found. This is version {{returnedVersion}}.",
"unpublishedDataset": "Privately share this dataset before it is published: {{privateUrl}}"
}
}
9 changes: 6 additions & 3 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DatasetAlert {
constructor(
public readonly variant: AlertVariant,
public readonly message: DatasetAlertMessageKey,
public readonly dynamicFields?: string[],
public readonly dynamicFields?: {},
public readonly customHeading?: string
) {}
}
Expand Down Expand Up @@ -331,7 +331,10 @@ export class Dataset {
)
}
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,7 +345,7 @@ export class Dataset {
)
}
if (this.privateUrl) {
const dynamicFields = [this.privateUrl]
const dynamicFields = { privateUrl: this.privateUrl }
this.alerts.push(
new DatasetAlert(
'info',
Expand Down
5 changes: 4 additions & 1 deletion src/sections/dataset/dataset-alerts/DatasetAlerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export function DatasetAlerts({ alerts }: DatasetAlertsProps) {
return (
<div className={styles.container}>
{alerts.map((alert: DatasetAlert, index) => {
const translatedHTML = t(`alerts.${alert.message}`)
const translatedHTML = alert.dynamicFields
? t(`alerts.${alert.message}`, alert.dynamicFields)
: t(`alerts.${alert.message}`)

return (
<Alert variant={alert.variant} customHeading={alert.customHeading} dismissible={false}>
{parse(translatedHTML)}
Expand Down
40 changes: 39 additions & 1 deletion src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { Meta, StoryObj } from '@storybook/react'
import { DatasetMockData } from '../DatasetMockData'
import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset'
import {
DatasetAlert,
DatasetAlertMessageKey,
DatasetPublishingStatus,
DatasetVersion
} from '../../../dataset/domain/models/Dataset'
import { DatasetAlerts } from '../../../sections/dataset/dataset-alerts/DatasetAlerts'
import { WithI18next } from '../../WithI18next'
import { AlertVariant } from '@iqss/dataverse-design-system/dist/components/alert/AlertVariant'
Expand All @@ -26,3 +31,36 @@ export const DraftVersion: Story = {
)
}
}
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>
)
}
}

0 comments on commit da02bc4

Please sign in to comment.