Skip to content

Commit

Permalink
feat: Add Stories and DatasetAlert types
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Nov 6, 2023
1 parent 41e987c commit de2fcd8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
22 changes: 21 additions & 1 deletion public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,27 @@
"uploadFiles": "Upload Files"
},
"alerts": {
"updateMetadataSuccess": {
"publishInProgress": {
"heading": "Publish in Progress",
"alertText": "The dataset is locked while the persistent identifiers are being registered or updated, and/or the physical files are being validated."
},
"filesUpdated": {
"heading": "Success!",
"alertText": "One or more files have been updated."
},
"termsUpdated": {
"heading": "Success!",
"alertText": "The terms for this dataset have been updated."
},
"thumbnailUpdated": {
"heading": "Success!",
"alertText": "Dataset thumbnail updated."
},
"datasetDeleted": {
"heading": "Success!",
"alertText": "This dataset draft has been deleted."
},
"metadataUpdated": {
"heading": "Success!",
"alertText": "The metadata for this dataset has been updated."
},
Expand Down
9 changes: 7 additions & 2 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ export enum DatasetAlertMessageKey {
REQUESTED_VERSION_NOT_FOUND_SHOW_DRAFT = 'requestedVersionNotFoundShowDraft',
SHARE_UNPUBLISHED_DATASET = 'shareUnpublishedDataset',
UNPUBLISHED_DATASET = 'unpublishedDataset',
UPDATE_METADATA_SUCCESS = 'updateMetadataSuccess'
METADATA_UPDATED = 'metadataUpdated',
FILES_UPDATED = 'filesUpdated',
TERMS_UPDATED = 'termsUpdated',
THUMBNAIL_UPDATED = 'thumbnailUpdated',
DATASET_DELETED = 'datasetDeleted',
PUBLISH_IN_PROGRESS = 'publishInProgress'
}

export class DatasetAlert {
constructor(
public readonly variant: AlertVariant,
public readonly message: DatasetAlertMessageKey,
public readonly dynamicFields?: object
public dynamicFields?: object
) {}
}

Expand Down
36 changes: 33 additions & 3 deletions src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import {
DatasetPermissionsMother
} from '../../../../tests/component/dataset/domain/models/DatasetMother'
import { DatasetAlertContext } from '../../../sections/dataset/DatasetAlertContext'
import { useEffect, useState } from 'react'

const meta: Meta<typeof DatasetAlerts> = {
title: 'Sections/Dataset Page/DatasetAlerts',
component: DatasetAlerts,
decorators: [WithI18next]
}
const editMetadataAlert = [
new DatasetAlert('success', DatasetAlertMessageKey.UPDATE_METADATA_SUCCESS)
]
const editMetadataAlert = [new DatasetAlert('success', DatasetAlertMessageKey.METADATA_UPDATED)]

export default meta
type Story = StoryObj<typeof DatasetAlerts>
Expand All @@ -44,6 +43,37 @@ export const EditMetadataSuccessful: Story = {
}
}

const publishAlert = [new DatasetAlert('warning', DatasetAlertMessageKey.PUBLISH_IN_PROGRESS)]

export const PublishInProgress: StoryObj<typeof DatasetAlerts> = {
render: () => {
const dataset = DatasetMother.createRealistic()
const [alerts, setAlerts] = useState(publishAlert)

// Set a timeout to remove the alert after 3 seconds
useEffect(() => {
const timer = setTimeout(() => {
setAlerts([]) // This will clear the alert after 3 seconds
}, 3000) // Timeout of 3 seconds

// Clear the timer if the component unmounts
return () => clearTimeout(timer)
}, [])

return (
<DatasetAlertContext.Provider
value={{
datasetAlerts: alerts,
setDatasetAlerts: setAlerts
}}>
<div>
<DatasetAlerts alerts={dataset.alerts} />
</div>
</DatasetAlertContext.Provider>
)
}
}

export const DraftVersion: Story = {
render: () => {
const dataset = DatasetMother.createRealistic({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ interface DatasetTranslation {
[DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND_SHOW_DRAFT]: AlertTranslation
[DatasetAlertMessageKey.UNPUBLISHED_DATASET]: AlertTranslation
[DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET]: AlertTranslation
[DatasetAlertMessageKey.METADATA_UPDATED]: AlertTranslation
[DatasetAlertMessageKey.FILES_UPDATED]: AlertTranslation
[DatasetAlertMessageKey.PUBLISH_IN_PROGRESS]: AlertTranslation
[DatasetAlertMessageKey.TERMS_UPDATED]: AlertTranslation
[DatasetAlertMessageKey.DATASET_DELETED]: AlertTranslation
[DatasetAlertMessageKey.THUMBNAIL_UPDATED]: AlertTranslation
}
}

Expand Down

0 comments on commit de2fcd8

Please sign in to comment.