From b3e1626bf582a8bea07b94aec4b96a856999894e Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 25 Mar 2024 20:40:34 -0400 Subject: [PATCH 1/3] feat: add Validation Alert and locationState for Success Alert --- public/locales/en/createDataset.json | 4 ++++ src/sections/create-dataset/CreateDatasetForm.tsx | 6 +++++- src/sections/create-dataset/useCreateDatasetForm.tsx | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/public/locales/en/createDataset.json b/public/locales/en/createDataset.json index b2a2f369c..97686068a 100644 --- a/public/locales/en/createDataset.json +++ b/public/locales/en/createDataset.json @@ -5,6 +5,10 @@ "content": "After adding the dataset, click the Edit Dataset button to add more metadata." }, "requiredFields": "Asterisks indicate required fields", + "validationAlert": { + "title": "Validation Error", + "content": "Required fields were missed or there was a validation error. Please scroll down to see details." + }, "datasetForm": { "fields": { "title": { diff --git a/src/sections/create-dataset/CreateDatasetForm.tsx b/src/sections/create-dataset/CreateDatasetForm.tsx index 3a9800754..77bac6176 100644 --- a/src/sections/create-dataset/CreateDatasetForm.tsx +++ b/src/sections/create-dataset/CreateDatasetForm.tsx @@ -61,7 +61,11 @@ export function CreateDatasetForm({ repository }: CreateDatasetFormProps) { {submissionStatus === SubmissionStatus.SubmitComplete && (

{t('datasetForm.status.success')}

)} - {submissionStatus === SubmissionStatus.Errored &&

{t('datasetForm.status.failed')}

} + {submissionStatus === SubmissionStatus.Errored && ( + + {t('validationAlert.content')} + + )}
) => { handleSubmit(event) diff --git a/src/sections/create-dataset/useCreateDatasetForm.tsx b/src/sections/create-dataset/useCreateDatasetForm.tsx index 86ad034a2..a1274fd94 100644 --- a/src/sections/create-dataset/useCreateDatasetForm.tsx +++ b/src/sections/create-dataset/useCreateDatasetForm.tsx @@ -35,7 +35,9 @@ export function useCreateDatasetForm( createDataset(repository, formData) .then(({ persistentId }) => { setSubmissionStatus(SubmissionStatus.SubmitComplete) - navigate(`${Route.DATASETS}?persistentId=${persistentId}`) + navigate(`${Route.DATASETS}?persistentId=${persistentId}`, { + state: { createSuccess: true } + }) return }) .catch(() => { From 230eb37c699f1210f9f9e8da2383ceb616bf4eef Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 27 Mar 2024 14:27:10 -0400 Subject: [PATCH 2/3] feat: add Create Dataset Success Alert, update stories and tests --- public/locales/en/dataset.json | 4 ++++ src/alert/domain/models/Alert.ts | 1 + .../create-dataset/useCreateDatasetForm.tsx | 2 +- src/sections/dataset/Dataset.tsx | 11 +++++++++-- src/sections/dataset/DatasetFactory.tsx | 6 +++++- src/stories/dataset/Dataset.stories.tsx | 4 ++++ .../create-dataset/CreateDatasetForm.spec.tsx | 14 +++++++------- .../create-dataset/CreateDatasetForm.spec.tsx | 3 +++ 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index 54dad4532..ff7201668 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -82,6 +82,10 @@ "heading": "Success!", "alertText": "This dataset draft has been deleted." }, + "datasetCreated": { + "heading": "Success!", + "alertText": "This dataset has been created." + }, "metadataUpdated": { "heading": "Success!", "alertText": "The metadata for this dataset has been updated." diff --git a/src/alert/domain/models/Alert.ts b/src/alert/domain/models/Alert.ts index d48051847..88d0dbfe9 100644 --- a/src/alert/domain/models/Alert.ts +++ b/src/alert/domain/models/Alert.ts @@ -11,6 +11,7 @@ export enum AlertMessageKey { TERMS_UPDATED = 'termsUpdated', THUMBNAIL_UPDATED = 'thumbnailUpdated', DATASET_DELETED = 'datasetDeleted', + DATASET_CREATED = 'datasetCreated', PUBLISH_IN_PROGRESS = 'publishInProgress' } diff --git a/src/sections/create-dataset/useCreateDatasetForm.tsx b/src/sections/create-dataset/useCreateDatasetForm.tsx index a1274fd94..e86678e8f 100644 --- a/src/sections/create-dataset/useCreateDatasetForm.tsx +++ b/src/sections/create-dataset/useCreateDatasetForm.tsx @@ -36,7 +36,7 @@ export function useCreateDatasetForm( .then(({ persistentId }) => { setSubmissionStatus(SubmissionStatus.SubmitComplete) navigate(`${Route.DATASETS}?persistentId=${persistentId}`, { - state: { createSuccess: true } + state: { created: true } }) return }) diff --git a/src/sections/dataset/Dataset.tsx b/src/sections/dataset/Dataset.tsx index a515ad751..8acd6dd59 100644 --- a/src/sections/dataset/Dataset.tsx +++ b/src/sections/dataset/Dataset.tsx @@ -1,4 +1,4 @@ -import { Tabs, Col, Row } from '@iqss/dataverse-design-system' +import { Col, Row, Tabs } from '@iqss/dataverse-design-system' import styles from './Dataset.module.scss' import { DatasetLabels } from './dataset-labels/DatasetLabels' import { useLoading } from '../loading/LoadingContext' @@ -18,17 +18,24 @@ import { useNotImplementedModal } from '../not-implemented/NotImplementedModalCo import { NotImplementedModal } from '../not-implemented/NotImplementedModal' import { SeparationLine } from '../shared/layout/SeparationLine/SeparationLine' import { BreadcrumbsGenerator } from '../shared/hierarchy/BreadcrumbsGenerator' +import { useAlertContext } from '../alerts/AlertContext' +import { AlertMessageKey } from '../../alert/domain/models/Alert' interface DatasetProps { fileRepository: FileRepository + created?: boolean } -export function Dataset({ fileRepository }: DatasetProps) { +export function Dataset({ fileRepository, created }: DatasetProps) { const { setIsLoading } = useLoading() const { dataset, isLoading } = useDataset() const { t } = useTranslation('dataset') const { hideModal, isModalOpen } = useNotImplementedModal() + const { addDatasetAlert } = useAlertContext() + if (created) { + addDatasetAlert({ messageKey: AlertMessageKey.DATASET_CREATED, variant: 'success' }) + } useEffect(() => { setIsLoading(isLoading) }, [isLoading]) diff --git a/src/sections/dataset/DatasetFactory.tsx b/src/sections/dataset/DatasetFactory.tsx index 793620489..c80597b45 100644 --- a/src/sections/dataset/DatasetFactory.tsx +++ b/src/sections/dataset/DatasetFactory.tsx @@ -1,5 +1,6 @@ import { ReactElement, useEffect } from 'react' import { useSearchParams } from 'react-router-dom' +import { useLocation } from 'react-router-dom' import { Dataset } from './Dataset' import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { useAnonymized } from './anonymized/AnonymizedContext' @@ -47,6 +48,9 @@ function DatasetWithSearchParams() { const privateUrlToken = searchParams.get('privateUrlToken') const searchParamVersion = searchParams.get('version') ?? undefined const version = searchParamVersionToDomainVersion(searchParamVersion) + const location = useLocation() + const state = location.state as { created: boolean } | undefined + const created = state?.created ?? false useEffect(() => { if (privateUrlToken) setAnonymizedView(true) @@ -66,7 +70,7 @@ function DatasetWithSearchParams() { - + ) } diff --git a/src/stories/dataset/Dataset.stories.tsx b/src/stories/dataset/Dataset.stories.tsx index f4f1426d9..82790f25a 100644 --- a/src/stories/dataset/Dataset.stories.tsx +++ b/src/stories/dataset/Dataset.stories.tsx @@ -35,6 +35,10 @@ export const Default: Story = { render: () => } +export const Created: Story = { + decorators: [WithLayout, WithDatasetDraftAsOwner, WithLoggedInUser, WithNotImplementedModal], + render: () => +} export const DraftWithAllDatasetPermissions: Story = { decorators: [WithLayout, WithDatasetDraftAsOwner, WithLoggedInUser, WithNotImplementedModal], render: () => diff --git a/tests/component/create-dataset/CreateDatasetForm.spec.tsx b/tests/component/create-dataset/CreateDatasetForm.spec.tsx index b585dae60..42b84a020 100644 --- a/tests/component/create-dataset/CreateDatasetForm.spec.tsx +++ b/tests/component/create-dataset/CreateDatasetForm.spec.tsx @@ -53,7 +53,7 @@ describe('Create Dataset', () => { cy.findByText('Title is required.').should('exist') - cy.findByText('Error: Submission failed.').should('exist') + cy.findByText('Validation Error').should('exist') }) it('shows an error message when the author name is not provided', () => { @@ -63,7 +63,7 @@ describe('Create Dataset', () => { cy.findByText('Author name is required.').should('exist') - cy.findByText('Error: Submission failed.').should('exist') + cy.findByText('Validation Error').should('exist') }) it('shows an error message when the point of contact email is not provided', () => { @@ -73,7 +73,7 @@ describe('Create Dataset', () => { cy.findByText('Point of Contact E-mail is required.').should('exist') - cy.findByText('Error: Submission failed.').should('exist') + cy.findByText('Validation Error').should('exist') }) it('shows an error message when the point of contact email is not a valid email', () => { @@ -87,7 +87,7 @@ describe('Create Dataset', () => { cy.findByText('Point of Contact E-mail is required.').should('exist') - cy.findByText('Error: Submission failed.').should('exist') + cy.findByText('Validation Error').should('exist') }) it('shows an error message when the description text is not provided', () => { @@ -97,7 +97,7 @@ describe('Create Dataset', () => { cy.findByText('Description Text is required.').should('exist') - cy.findByText('Error: Submission failed.').should('exist') + cy.findByText('Validation Error').should('exist') }) it('shows an error message when the subject is not provided', () => { @@ -107,7 +107,7 @@ describe('Create Dataset', () => { cy.findByText('Subject is required.').should('exist') - cy.findByText('Error: Submission failed.').should('exist') + cy.findByText('Validation Error').should('exist') }) it('can submit a valid form', () => { @@ -146,6 +146,6 @@ describe('Create Dataset', () => { cy.findByLabelText(/Arts and Humanities/i).check() cy.findByText(/Save Dataset/i).click() - cy.findByText('Error: Submission failed.').should('exist') + cy.contains('Validation Error').should('exist') }) }) diff --git a/tests/e2e-integration/e2e/sections/create-dataset/CreateDatasetForm.spec.tsx b/tests/e2e-integration/e2e/sections/create-dataset/CreateDatasetForm.spec.tsx index f200d8986..eb70df11c 100644 --- a/tests/e2e-integration/e2e/sections/create-dataset/CreateDatasetForm.spec.tsx +++ b/tests/e2e-integration/e2e/sections/create-dataset/CreateDatasetForm.spec.tsx @@ -1,5 +1,6 @@ import { TestsUtils } from '../../../shared/TestsUtils' import { DatasetLabelValue } from '../../../../../src/dataset/domain/models/Dataset' +import { AlertMessageKey } from '../../../../../src/alert/domain/models/Alert' describe('Create Dataset', () => { before(() => { @@ -28,6 +29,8 @@ describe('Create Dataset', () => { cy.findByText(/Save Dataset/i).click() cy.findByRole('heading', { name: 'Test Dataset Title' }).should('exist') + cy.findByText('Success!').should('exist') + cy.contains('This dataset has been created.').should('exist') cy.findByText(DatasetLabelValue.DRAFT).should('exist') cy.findByText(DatasetLabelValue.UNPUBLISHED).should('exist') }) From 2021384589d29caee98f9f46a43fb7f4fa2409fe Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 27 Mar 2024 14:32:23 -0400 Subject: [PATCH 3/3] fix: lint errors --- .../sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx | 1 + .../e2e/sections/create-dataset/CreateDatasetForm.spec.tsx | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index 0ccf2c504..083c34e4c 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -32,6 +32,7 @@ interface DatasetTranslation { [AlertMessageKey.TERMS_UPDATED]: AlertTranslation [AlertMessageKey.DATASET_DELETED]: AlertTranslation [AlertMessageKey.THUMBNAIL_UPDATED]: AlertTranslation + [AlertMessageKey.DATASET_CREATED]: AlertTranslation } } diff --git a/tests/e2e-integration/e2e/sections/create-dataset/CreateDatasetForm.spec.tsx b/tests/e2e-integration/e2e/sections/create-dataset/CreateDatasetForm.spec.tsx index eb70df11c..c019cac6f 100644 --- a/tests/e2e-integration/e2e/sections/create-dataset/CreateDatasetForm.spec.tsx +++ b/tests/e2e-integration/e2e/sections/create-dataset/CreateDatasetForm.spec.tsx @@ -1,6 +1,5 @@ import { TestsUtils } from '../../../shared/TestsUtils' import { DatasetLabelValue } from '../../../../../src/dataset/domain/models/Dataset' -import { AlertMessageKey } from '../../../../../src/alert/domain/models/Alert' describe('Create Dataset', () => { before(() => {