From de2fcd8a6e507cb7cd255be4ccb11c243d6ad476 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Sun, 5 Nov 2023 21:19:29 -0500 Subject: [PATCH] feat: Add Stories and DatasetAlert types --- public/locales/en/dataset.json | 22 +++++++++++- src/dataset/domain/models/Dataset.ts | 9 +++-- .../dataset-alerts/DatasetAlert.stories.tsx | 36 +++++++++++++++++-- .../dataset-alerts/DatasetAlerts.spec.tsx | 6 ++++ 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index cd748bdd5..fbc62fefb 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -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." }, diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 203b33b77..a12578325 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -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 ) {} } diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 356e50140..3493f2686 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -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 = { 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 @@ -44,6 +43,37 @@ export const EditMetadataSuccessful: Story = { } } +const publishAlert = [new DatasetAlert('warning', DatasetAlertMessageKey.PUBLISH_IN_PROGRESS)] + +export const PublishInProgress: StoryObj = { + 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 ( + +
+ +
+
+ ) + } +} + export const DraftVersion: Story = { render: () => { const dataset = DatasetMother.createRealistic({ diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index d70fd4977..03430b233 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -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 } }