From 5c00ae0bd291a107c57ff17107764eebf4fcf8b5 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 6 Oct 2023 14:06:27 -0400 Subject: [PATCH 01/30] feature: DatasetAlert component and first story --- .../dataset/dataset-alerts/DatasetAlerts.tsx | 26 +++++++++++++++++ .../dataset-alerts/DatasetAlert.stories.tsx | 28 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/sections/dataset/dataset-alerts/DatasetAlerts.tsx create mode 100644 src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx diff --git a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx new file mode 100644 index 000000000..b9ea3f84c --- /dev/null +++ b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx @@ -0,0 +1,26 @@ +import { Alert } from '@iqss/dataverse-design-system' +import { DatasetAlert, DatasetAlertMessageKey } 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 ( +
+ {alerts.map((alert: DatasetAlert, index) => { + const translatedHTML = t(`alerts.${alert.message}`) + return ( + + {parse(translatedHTML)} + + ) + })} +
+ ) +} diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx new file mode 100644 index 000000000..a7a56e8a4 --- /dev/null +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -0,0 +1,28 @@ +import type { Meta, StoryObj } from '@storybook/react' +import { DatasetMockData } from '../DatasetMockData' +import { 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' + +const meta: Meta = { + title: 'Sections/Dataset Page/DatasetAlerts', + component: DatasetAlerts, + decorators: [WithI18next] +} + +export default meta +type Story = StoryObj + +export const DraftVersion: Story = { + render: () => { + const dataset = DatasetMockData({ + version: new DatasetVersion(1, DatasetPublishingStatus.DRAFT, 1, 0) + }) + return ( +
+ +
+ ) + } +} From da02bc40039eabefa1d8368c6abf30e292b9db87 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 6 Oct 2023 16:50:03 -0400 Subject: [PATCH 02/30] add VersionNotFound and PrivateUrl stories --- public/locales/en/dataset.json | 4 +- src/dataset/domain/models/Dataset.ts | 9 +++-- .../dataset/dataset-alerts/DatasetAlerts.tsx | 5 ++- .../dataset-alerts/DatasetAlert.stories.tsx | 40 ++++++++++++++++++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index 09d4687b8..614c6135e 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -23,7 +23,7 @@ }, "alerts": { "draftVersion": "This draft version needs to be published. When ready for sharing, please publish 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}}" } } diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 901bf5aa5..172f95a93 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -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 ) {} } @@ -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( @@ -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', diff --git a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx index b9ea3f84c..3c16da424 100644 --- a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx +++ b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx @@ -14,7 +14,10 @@ export function DatasetAlerts({ alerts }: DatasetAlertsProps) { return (
{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 ( {parse(translatedHTML)} diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index a7a56e8a4..c0008df1c 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -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' @@ -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 ( +
+ +
+ ) + } +} +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 ( +
+ +
+ ) + } +} From e40738bc4a397ec8665c39e8f5940e4b10f9eb54 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 6 Oct 2023 16:53:28 -0400 Subject: [PATCH 03/30] remove unused code --- src/sections/dataset/dataset-alerts/DatasetAlerts.tsx | 4 ++-- src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx index 3c16da424..a050fc4fd 100644 --- a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx +++ b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx @@ -1,5 +1,5 @@ import { Alert } from '@iqss/dataverse-design-system' -import { DatasetAlert, DatasetAlertMessageKey } from '../../../dataset/domain/models/Dataset' +import { DatasetAlert } from '../../../dataset/domain/models/Dataset' import { useTranslation } from 'react-i18next' import styles from './DatasetAlerts.module.scss' import parse from 'html-react-parser' @@ -13,7 +13,7 @@ export function DatasetAlerts({ alerts }: DatasetAlertsProps) { return (
- {alerts.map((alert: DatasetAlert, index) => { + {alerts.map((alert: DatasetAlert) => { const translatedHTML = alert.dynamicFields ? t(`alerts.${alert.message}`, alert.dynamicFields) : t(`alerts.${alert.message}`) diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index c0008df1c..c9e9a6832 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -8,7 +8,6 @@ import { } 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' const meta: Meta = { title: 'Sections/Dataset Page/DatasetAlerts', From 731997a7804ee14f26c8b19383d0b95a278fddcc Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 6 Oct 2023 18:18:23 -0400 Subject: [PATCH 04/30] Add Dataset story; move alert customHeading to translation text --- public/locales/en/dataset.json | 15 ++- src/dataset/domain/models/Dataset.ts | 14 +-- src/sections/dataset/Dataset.tsx | 2 + .../dataset/dataset-alerts/DatasetAlerts.tsx | 19 +-- src/stories/dataset/Dataset.stories.tsx | 3 +- .../dataset/DatasetMockDataDraftVersion.ts | 111 ++++++++++++++++++ .../DatasetMockDraftVersionRepository.ts | 22 ++++ .../mappers/JSDatasetMapper.spec.ts | 10 +- 8 files changed, 167 insertions(+), 29 deletions(-) create mode 100644 src/stories/dataset/DatasetMockDataDraftVersion.ts create mode 100644 src/stories/dataset/DatasetMockDraftVersionRepository.ts diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index 614c6135e..2f470bd6a 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -22,8 +22,17 @@ "uploadFiles": "Upload Files" }, "alerts": { - "draftVersion": "This draft version needs to be published. When ready for sharing, please publish it so that others can see these changes", - "requestedVersionNotFound": "Version {{requestedVersion}} was not found. This is version {{returnedVersion}}.", - "unpublishedDataset": "Privately share this dataset before it is published: {{privateUrl}}" + "draftVersion": { + "heading": "This draft version needs to be published", + "alertText": "When ready for sharing, please publish it so that others can see these changes" + }, + "requestedVersionNotFound": { + "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}}" + } } } diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 172f95a93..9c3d4d99b 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -34,8 +34,7 @@ export class DatasetAlert { constructor( public readonly variant: AlertVariant, public readonly message: DatasetAlertMessageKey, - public readonly dynamicFields?: {}, - public readonly customHeading?: string + public readonly dynamicFields?: object ) {} } @@ -326,9 +325,7 @@ 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 = { @@ -347,12 +344,7 @@ export class Dataset { if (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) ) } } diff --git a/src/sections/dataset/Dataset.tsx b/src/sections/dataset/Dataset.tsx index b03d76a55..e506ea54e 100644 --- a/src/sections/dataset/Dataset.tsx +++ b/src/sections/dataset/Dataset.tsx @@ -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 @@ -38,6 +39,7 @@ export function Dataset({ datasetRepository, fileRepository, searchParams }: Dat ) : (
+

{dataset.getTitle()}

diff --git a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx index a050fc4fd..7d41990c0 100644 --- a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx +++ b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx @@ -13,14 +13,19 @@ export function DatasetAlerts({ alerts }: DatasetAlertsProps) { return (
- {alerts.map((alert: DatasetAlert) => { - const translatedHTML = alert.dynamicFields - ? t(`alerts.${alert.message}`, alert.dynamicFields) - : t(`alerts.${alert.message}`) - + {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 ( - - {parse(translatedHTML)} + + {parse(translatedMsg)} ) })} diff --git a/src/stories/dataset/Dataset.stories.tsx b/src/stories/dataset/Dataset.stories.tsx index d0da00035..e332943cb 100644 --- a/src/stories/dataset/Dataset.stories.tsx +++ b/src/stories/dataset/Dataset.stories.tsx @@ -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 = { title: 'Pages/Dataset', @@ -41,7 +42,7 @@ export const LoggedInAsOwner: Story = { decorators: [WithLayout, WithLoggedInUser, WithFilePermissionsGranted], render: () => ( diff --git a/src/stories/dataset/DatasetMockDataDraftVersion.ts b/src/stories/dataset/DatasetMockDataDraftVersion.ts new file mode 100644 index 000000000..a3f7dbbd3 --- /dev/null +++ b/src/stories/dataset/DatasetMockDataDraftVersion.ts @@ -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, + anonymized = false +): Dataset => { + const dataset = { + persistentId: 'doi:10.5072/FK2/ABC123', + citation: `${ + anonymized ? 'Author name(s) withheld' : 'Bennet, Elizabeth; Darcy, Fitzwilliam' + }, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, 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() +} diff --git a/src/stories/dataset/DatasetMockDraftVersionRepository.ts b/src/stories/dataset/DatasetMockDraftVersionRepository.ts new file mode 100644 index 000000000..bff2952d6 --- /dev/null +++ b/src/stories/dataset/DatasetMockDraftVersionRepository.ts @@ -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 { + return new Promise((resolve) => { + setTimeout(() => { + resolve(DatasetMockDataDraftVersion({ persistentId: persistentId })) + }, 1000) + }) + } + + // eslint-disable-next-line unused-imports/no-unused-vars + getByPrivateUrlToken(privateUrlToken: string): Promise { + return new Promise((resolve) => { + setTimeout(() => { + resolve(DatasetMockDataDraftVersion({}, true)) + }, 1000) + }) + } +} diff --git a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts index 5abd258f7..5a1c7a768 100644 --- a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts +++ b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts @@ -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', @@ -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: [ From 117a7459578db80c113fb3349979be1a72fa4aaa Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Sat, 7 Oct 2023 09:48:04 -0400 Subject: [PATCH 05/30] add DatasetAlerts.module.scss --- src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss diff --git a/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss b/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss new file mode 100644 index 000000000..ec77535e7 --- /dev/null +++ b/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss @@ -0,0 +1,3 @@ +.container > * { + margin-right: 0.5em; +} \ No newline at end of file From 548119f34475710415b9726bb2911b42e4eca231 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 9 Oct 2023 15:37:07 -0400 Subject: [PATCH 06/30] add DatasetAlerts unit test --- .../dataset-alerts/DatasetAlerts.spec.tsx | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx new file mode 100644 index 000000000..4bc468499 --- /dev/null +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -0,0 +1,75 @@ +import { DatasetAlerts } from '../../../../../src/sections/dataset/dataset-alerts/DatasetAlerts' +import { faker } from '@faker-js/faker' + +import { + DatasetAlert, + DatasetAlertMessageKey +} from '../../../../../src/dataset/domain/models/Dataset' + +describe('DatasetAlerts', () => { + function removeMarkup(htmlString: string): string { + // Use a regular expression to match HTML tags and replace them with an empty string + return htmlString.replace(/<\/?[^>]+(>|$)/g, '') + } + + const alerts = [ + new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION), + new DatasetAlert('warning', DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, { + requestedVersion: 4.0, + returnedVersion: 2.0 + }), + new DatasetAlert('info', DatasetAlertMessageKey.UNPUBLISHED_DATASET, { + privateUrl: faker.internet.url() + }) + ] + + it('renders the correct number of alerts', () => { + cy.mount() + cy.findByText('Unpublished Dataset Private URL').should('exist') + const alertElements = cy.findAllByRole('alert').should('have.length', alerts.length) + }) + + it('renders alerts with correct content', () => { + cy.fixture('../../../public/locales/en/dataset.json').then((dataset) => { + cy.mount() + + cy.findAllByRole('alert').should('exist') + cy.findAllByRole('alert').should( + 'contain.text', + removeMarkup(dataset.alerts.draftVersion.alertText) + ) + cy.findByText('Information').should('exist') + }) + }) + + it('renders alerts with correct headings', () => { + cy.fixture('../../../public/locales/en/dataset.json').then((dataset) => { + cy.mount() + + alerts.forEach((alert) => { + const alertHeading = removeMarkup(dataset.alerts[alert.message].heading) + console.log(JSON.stringify(alertHeading)) + cy.findAllByRole('alert').should('contain.text', alertHeading) + }) + }) + }) + it('renders dynamic text', () => { + cy.fixture('../../../public/locales/en/dataset.json').then((dataset) => { + const dynamicFields = { + requestedVersion: 4.0, + returnedVersion: 2.0 + } + const notFoundAlert = new DatasetAlert( + 'warning', + DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, + dynamicFields + ) + cy.mount() + + alerts.forEach((alert) => { + cy.findAllByRole('alert').should('contain.text', dynamicFields.requestedVersion) + cy.findAllByRole('alert').should('contain.text', dynamicFields.returnedVersion) + }) + }) + }) +}) From 5685673cd02f2170546d6e66334400907c57457c Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 9 Oct 2023 15:38:19 -0400 Subject: [PATCH 07/30] add DatasetAlerts unit test --- .../dataset-alerts/DatasetAlerts.spec.tsx | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index 4bc468499..4dc43c559 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -26,7 +26,6 @@ describe('DatasetAlerts', () => { it('renders the correct number of alerts', () => { cy.mount() cy.findByText('Unpublished Dataset Private URL').should('exist') - const alertElements = cy.findAllByRole('alert').should('have.length', alerts.length) }) it('renders alerts with correct content', () => { @@ -45,7 +44,6 @@ describe('DatasetAlerts', () => { it('renders alerts with correct headings', () => { cy.fixture('../../../public/locales/en/dataset.json').then((dataset) => { cy.mount() - alerts.forEach((alert) => { const alertHeading = removeMarkup(dataset.alerts[alert.message].heading) console.log(JSON.stringify(alertHeading)) @@ -54,22 +52,20 @@ describe('DatasetAlerts', () => { }) }) it('renders dynamic text', () => { - cy.fixture('../../../public/locales/en/dataset.json').then((dataset) => { - const dynamicFields = { - requestedVersion: 4.0, - returnedVersion: 2.0 - } - const notFoundAlert = new DatasetAlert( - 'warning', - DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, - dynamicFields - ) - cy.mount() + const dynamicFields = { + requestedVersion: 4.0, + returnedVersion: 2.0 + } + const notFoundAlert = new DatasetAlert( + 'warning', + DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, + dynamicFields + ) + cy.mount() - alerts.forEach((alert) => { - cy.findAllByRole('alert').should('contain.text', dynamicFields.requestedVersion) - cy.findAllByRole('alert').should('contain.text', dynamicFields.returnedVersion) - }) + alerts.forEach((alert) => { + cy.findAllByRole('alert').should('contain.text', dynamicFields.requestedVersion) + cy.findAllByRole('alert').should('contain.text', dynamicFields.returnedVersion) }) }) }) From df229db21232c8577a7d0ebff825b34db5c143a2 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Tue, 10 Oct 2023 18:21:12 -0400 Subject: [PATCH 08/30] fix: DatasetAlerts unit test --- .../dataset-alerts/DatasetAlerts.spec.tsx | 101 ++++++++++-------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index 4dc43c559..800c0d3e1 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -6,12 +6,29 @@ import { DatasetAlertMessageKey } from '../../../../../src/dataset/domain/models/Dataset' -describe('DatasetAlerts', () => { - function removeMarkup(htmlString: string): string { - // Use a regular expression to match HTML tags and replace them with an empty string - return htmlString.replace(/<\/?[^>]+(>|$)/g, '') +function removeMarkup(htmlString: string): string { + // Use a regular expression to match HTML tags and replace them with an empty string + return htmlString.replace(/<\/?[^>]+(>|$)/g, '') +} + +interface DatasetTranslation { + alerts: { + draftVersion: { + heading: string + alertText: string + } + requestedVersionNotFound: { + heading: string + alertText: string + } + unpublishedDataset: { + heading: string + alertText: string + } } +} +it('renders the correct number of alerts', () => { const alerts = [ new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION), new DatasetAlert('warning', DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, { @@ -22,50 +39,48 @@ describe('DatasetAlerts', () => { privateUrl: faker.internet.url() }) ] - - it('renders the correct number of alerts', () => { + cy.fixture('../../../public/locales/en/dataset.json').then((dataset: DatasetTranslation) => { cy.mount() - cy.findByText('Unpublished Dataset Private URL').should('exist') - }) - - it('renders alerts with correct content', () => { - cy.fixture('../../../public/locales/en/dataset.json').then((dataset) => { - cy.mount() - - cy.findAllByRole('alert').should('exist') - cy.findAllByRole('alert').should( - 'contain.text', - removeMarkup(dataset.alerts.draftVersion.alertText) - ) - cy.findByText('Information').should('exist') + const headingProps = [ + dataset.alerts.draftVersion.heading, + dataset.alerts.requestedVersionNotFound.heading, + dataset.alerts.unpublishedDataset.heading + ] + cy.findAllByRole('alert').should('have.length', 3) + cy.findAllByRole('alert').each(($alert, index) => { + cy.wrap($alert).findByText(headingProps[index]).should('exist') }) }) +}) - it('renders alerts with correct headings', () => { - cy.fixture('../../../public/locales/en/dataset.json').then((dataset) => { - cy.mount() - alerts.forEach((alert) => { - const alertHeading = removeMarkup(dataset.alerts[alert.message].heading) - console.log(JSON.stringify(alertHeading)) - cy.findAllByRole('alert').should('contain.text', alertHeading) - }) - }) - }) - it('renders dynamic text', () => { - const dynamicFields = { - requestedVersion: 4.0, - returnedVersion: 2.0 - } - const notFoundAlert = new DatasetAlert( - 'warning', - DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, - dynamicFields - ) - cy.mount() +it('renders alerts with correct text', () => { + const draftAlert = new DatasetAlert('info', DatasetAlertMessageKey.DRAFT_VERSION) + const alerts = [draftAlert] - alerts.forEach((alert) => { - cy.findAllByRole('alert').should('contain.text', dynamicFields.requestedVersion) - cy.findAllByRole('alert').should('contain.text', dynamicFields.returnedVersion) + cy.fixture('../../../public/locales/en/dataset.json').then((dataset: DatasetTranslation) => { + cy.mount() + + const alertHeading = dataset.alerts[draftAlert.message].heading + const alertText = removeMarkup(dataset.alerts[draftAlert.message].alertText) + cy.findByText(alertHeading).should('exist') + cy.findByRole('alert').should(($element) => { + // text() removes markup, so we can compare to the expected text + const text = $element.text() + expect(text).to.include(alertText) }) }) }) +it('renders dynamic text', () => { + const dynamicFields = { + requestedVersion: '4.0', + returnedVersion: '2.0' + } + const notFoundAlert = new DatasetAlert( + 'warning', + DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, + dynamicFields + ) + cy.mount() + cy.findByRole('alert').should('contain.text', dynamicFields.requestedVersion) + cy.findByRole('alert').should('contain.text', dynamicFields.returnedVersion) +}) From f4f21cc3fa73f5aecf09095346558eb3af8766ec Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 11 Oct 2023 11:35:46 -0400 Subject: [PATCH 09/30] fix: add spacing around DatasetAlerts component --- src/sections/dataset/Dataset.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sections/dataset/Dataset.tsx b/src/sections/dataset/Dataset.tsx index e506ea54e..2929358dd 100644 --- a/src/sections/dataset/Dataset.tsx +++ b/src/sections/dataset/Dataset.tsx @@ -39,7 +39,14 @@ export function Dataset({ datasetRepository, fileRepository, searchParams }: Dat ) : (
- +
+ + + + + +
+

{dataset.getTitle()}

From 98bbe41e19db6e5c95bb2ca8d9b4d18ca76bcdeb Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 18 Oct 2023 11:48:41 -0400 Subject: [PATCH 10/30] fix: remove unneeded heading text --- .../dataset/dataset-alerts/DatasetAlert.stories.tsx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index c9e9a6832..5733afcd1 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -45,15 +45,10 @@ export const VersionNotFound: Story = { 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' - ) + new DatasetAlert('info', DatasetAlertMessageKey.UNPUBLISHED_DATASET, { + privateUrl: + 'http://localhost:8080/privateurl.xhtml?token=f6815782-1227-4d80-a46d-91621c2d9386' + }) ] return ( From 8033dccea2e98d4a8423432f25ad02a35d4efe8c Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 19 Oct 2023 07:59:30 -0400 Subject: [PATCH 11/30] fix: Dataset object in stories --- src/stories/dataset/Dataset.stories.tsx | 10 ++---- .../dataset-alerts/DatasetAlert.stories.tsx | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/stories/dataset/Dataset.stories.tsx b/src/stories/dataset/Dataset.stories.tsx index f553dfdb8..255e5a768 100644 --- a/src/stories/dataset/Dataset.stories.tsx +++ b/src/stories/dataset/Dataset.stories.tsx @@ -13,7 +13,6 @@ import { WithDataset } from './WithDataset' import { WithDatasetDraftAsOwner } from './WithDatasetDraftAsOwner' import { WithDatasetNotFound } from './WithDatasetNotFound' import { WithDatasetLoading } from './WithDatasetLoading' -import { DatasetMockDraftVersionRepository } from './DatasetMockDraftVersionRepository' import { WithLoggedInUser } from '../WithLoggedInUser' const meta: Meta = { @@ -36,16 +35,11 @@ export const Default: Story = { export const DraftWithAllDatasetPermissions: Story = { decorators: [WithLayout, WithDatasetDraftAsOwner, WithLoggedInUser, WithFilePermissionsGranted], - render: () => + render: () => } export const LoggedInAsOwner: Story = { decorators: [WithDataset, WithLayout, WithLoggedInUser, WithFilePermissionsGranted], - render: () => ( - - ) + render: () => } export const Loading: Story = { diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 5733afcd1..098d0ad74 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react' -import { DatasetMockData } from '../DatasetMockData' + import { DatasetAlert, DatasetAlertMessageKey, @@ -9,6 +9,10 @@ import { import { DatasetAlerts } from '../../../sections/dataset/dataset-alerts/DatasetAlerts' import { WithI18next } from '../../WithI18next' +import { WithDatasetDraftAsOwner } from '../WithDatasetDraftAsOwner' +import { useDataset } from '../../../sections/dataset/DatasetContext' +import { DatasetMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' + const meta: Meta = { title: 'Sections/Dataset Page/DatasetAlerts', component: DatasetAlerts, @@ -19,9 +23,16 @@ export default meta type Story = StoryObj export const DraftVersion: Story = { + decorators: [WithDatasetDraftAsOwner], render: () => { - const dataset = DatasetMockData({ - version: new DatasetVersion(1, DatasetPublishingStatus.DRAFT, 1, 0) + const dataset = DatasetMother.createRealistic({ + version: new DatasetVersion( + 1, + DatasetPublishingStatus.DRAFT, + true, + false, + DatasetPublishingStatus.DRAFT + ) }) return (
@@ -30,11 +41,22 @@ export const DraftVersion: Story = { ) } } + export const VersionNotFound: Story = { render: () => { - const dataset = DatasetMockData({ - version: new DatasetVersion(1, DatasetPublishingStatus.RELEASED, 1, 0, '3.0') + const dataset = DatasetMother.createRealistic({ + version: new DatasetVersion( + 1, + DatasetPublishingStatus.RELEASED, + true, + false, + DatasetPublishingStatus.RELEASED, + 1, + 0, + '3.0' + ) }) + return (
From 87cefb7d76294bd04b7bf7c31bfca6b19c8fca14 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 19 Oct 2023 08:49:28 -0400 Subject: [PATCH 12/30] fix: lint error --- src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 098d0ad74..d73a7a856 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -10,7 +10,6 @@ import { DatasetAlerts } from '../../../sections/dataset/dataset-alerts/DatasetA import { WithI18next } from '../../WithI18next' import { WithDatasetDraftAsOwner } from '../WithDatasetDraftAsOwner' -import { useDataset } from '../../../sections/dataset/DatasetContext' import { DatasetMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' const meta: Meta = { From 2062a4efd75ad276acc82494c78c9a79244e8bf9 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 19 Oct 2023 16:49:24 -0400 Subject: [PATCH 13/30] fix: Add privateUrl Alert, fix logic for Draft Alert --- public/locales/en/dataset.json | 6 +++++- src/dataset/domain/models/Dataset.ts | 23 +++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index 559396afc..736884a79 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -66,9 +66,13 @@ "heading": "Information", "alertText": "Version {{requestedVersion}} was not found. This is version {{returnedVersion}}." }, - "unpublishedDataset": { + "shareUnpublishedDataset": { "heading": "Unpublished Dataset Private URL", "alertText": "Privately share this dataset before it is published: {{privateUrl}}" + }, + "unpublishedDataset": { + "heading": "Unpublished Dataset Private URL", + "alertText": "This unpublished dataset is being privately shared." } } } diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index f2d982fde..e456627b0 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -27,6 +27,7 @@ export class DatasetLabel { export enum DatasetAlertMessageKey { DRAFT_VERSION = 'draftVersion', REQUESTED_VERSION_NOT_FOUND = 'requestedVersionNotFound', + SHARE_UNPUBLISHED_DATASET = 'shareUnpublishedDataset', UNPUBLISHED_DATASET = 'unpublishedDataset' } @@ -384,7 +385,10 @@ export class Dataset { } private withAlerts(): void { - if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) { + if ( + this.version.publishingStatus === DatasetPublishingStatus.DRAFT && + this.permissions.canPublishDataset + ) { this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION)) } if (this.version.requestedVersion) { @@ -392,7 +396,6 @@ export class Dataset { requestedVersion: this.version.requestedVersion, returnedVersion: `${this.version.toString()}` } - this.alerts.push( new DatasetAlert( 'info', @@ -402,10 +405,18 @@ export class Dataset { ) } if (this.privateUrl) { - const dynamicFields = { privateUrl: this.privateUrl } - this.alerts.push( - new DatasetAlert('info', DatasetAlertMessageKey.UNPUBLISHED_DATASET, dynamicFields) - ) + if (this.permissions.canUpdateDataset) { + const dynamicFields = { privateUrl: this.privateUrl } + this.alerts.push( + new DatasetAlert( + 'info', + DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET, + dynamicFields + ) + ) + } else { + new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET) + } } } From 04ce3afba7c79fd3b85ff7a31cd5fffc05e5c266 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 19 Oct 2023 16:49:58 -0400 Subject: [PATCH 14/30] fix: Add privateUrlToken to JSDatasetMapper --- .../repositories/DatasetJSDataverseRepository.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index a1409b317..1464847ea 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -44,7 +44,13 @@ export class DatasetJSDataverseRepository implements DatasetRepository { getPrivateUrlDatasetCitation.execute(privateUrlToken) ]) .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => - JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames) + JSDatasetMapper.toDataset( + jsDataset, + citation, + summaryFieldsNames, + undefined, + privateUrlToken + ) ) .catch((error: WriteError) => { throw new Error(error.message) From 02f6c1b3b36ba787609d1316d74202cfff1ef9d2 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 20 Oct 2023 11:51:18 -0400 Subject: [PATCH 15/30] refactor: rename privateUrl -> privateUrlToken --- src/dataset/domain/models/Dataset.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index e456627b0..9fdb67ceb 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -333,7 +333,7 @@ export class Dataset { public readonly hasValidTermsOfAccess: boolean, public readonly isValid: boolean, public readonly isReleased: boolean, - public readonly privateUrl?: string + public readonly privateUrlToken?: string ) { this.withLabels() this.withAlerts() @@ -404,9 +404,10 @@ export class Dataset { ) ) } - if (this.privateUrl) { + if (this.privateUrlToken) { if (this.permissions.canUpdateDataset) { - const dynamicFields = { privateUrl: this.privateUrl } + // TODO: set the whole Url, not just the token + const dynamicFields = { privateUrl: this.privateUrlToken } this.alerts.push( new DatasetAlert( 'info', From a4f3694bb1312409aa20e3284ea94e13bc5e07ef Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 20 Oct 2023 11:54:21 -0400 Subject: [PATCH 16/30] fix: add privateUrlToken to DatasetMother. --- tests/component/dataset/domain/models/DatasetMother.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 428711053..87fa1cb8e 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -190,7 +190,11 @@ export class DatasetMother { return undefined } - static create(props?: Partial): Dataset { + static createWithPrivateUrlToken(privateUrlToken: string, props?: Partial) { + return this.create(props, privateUrlToken) + } + + static create(props?: Partial, privateUrlToken?: string): Dataset { const dataset = { persistentId: faker.datatype.uuid(), title: faker.lorem.sentence(), @@ -301,7 +305,8 @@ export class DatasetMother { dataset.locks, dataset.hasValidTermsOfAccess, dataset.isValid, - dataset.isReleased + dataset.isReleased, + privateUrlToken ).build() } From fe40b96c821298d776a5a872066af0bc4378b974 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 20 Oct 2023 11:55:29 -0400 Subject: [PATCH 17/30] fix: use new mock data in DatasetAlert.stories.tsx --- .../dataset-alerts/DatasetAlert.stories.tsx | 59 +++++++++++++++---- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index d73a7a856..f288c737e 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -9,8 +9,10 @@ import { import { DatasetAlerts } from '../../../sections/dataset/dataset-alerts/DatasetAlerts' import { WithI18next } from '../../WithI18next' -import { WithDatasetDraftAsOwner } from '../WithDatasetDraftAsOwner' -import { DatasetMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' +import { + DatasetMother, + DatasetPermissionsMother +} from '../../../../tests/component/dataset/domain/models/DatasetMother' const meta: Meta = { title: 'Sections/Dataset Page/DatasetAlerts', @@ -22,7 +24,6 @@ export default meta type Story = StoryObj export const DraftVersion: Story = { - decorators: [WithDatasetDraftAsOwner], render: () => { const dataset = DatasetMother.createRealistic({ version: new DatasetVersion( @@ -31,7 +32,8 @@ export const DraftVersion: Story = { true, false, DatasetPublishingStatus.DRAFT - ) + ), + permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed() }) return (
@@ -63,18 +65,51 @@ export const VersionNotFound: Story = { ) } } -export const PrivateUrl: Story = { +export const SharePrivateUrl: Story = { + render: () => { + const dataset = DatasetMother.createWithPrivateUrlToken( + 'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb', + { + version: new DatasetVersion( + 1, + DatasetPublishingStatus.RELEASED, + true, + false, + DatasetPublishingStatus.DRAFT, + 1, + 0 + ), + permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed() + } + ) + + return ( +
+ +
+ ) + } +} +export const UsePrivateUrl: Story = { render: () => { - const alerts = [ - new DatasetAlert('info', DatasetAlertMessageKey.UNPUBLISHED_DATASET, { - privateUrl: - 'http://localhost:8080/privateurl.xhtml?token=f6815782-1227-4d80-a46d-91621c2d9386' - }) - ] + const dataset = DatasetMother.createWithPrivateUrlToken( + 'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb', + { + version: new DatasetVersion( + 1, + DatasetPublishingStatus.RELEASED, + true, + false, + DatasetPublishingStatus.DRAFT, + 1, + 0 + ) + } + ) return (
- +
) } From 9fb19915321c44c57c1ba2f5075990d9c331711d Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 20 Oct 2023 13:48:03 -0400 Subject: [PATCH 18/30] fix: add tests to DatasetAlerts.spec.tsx --- .../dataset-alerts/DatasetAlerts.spec.tsx | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 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 800c0d3e1..e91ccadfc 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -5,6 +5,11 @@ import { DatasetAlert, DatasetAlertMessageKey } from '../../../../../src/dataset/domain/models/Dataset' +import { + DatasetMother, + DatasetPermissionsMother, + DatasetVersionMother +} from '../../../dataset/domain/models/DatasetMother' function removeMarkup(htmlString: string): string { // Use a regular expression to match HTML tags and replace them with an empty string @@ -25,6 +30,10 @@ interface DatasetTranslation { heading: string alertText: string } + shareUnpublishedDataset: { + heading: string + alertText: string + } } } @@ -35,7 +44,7 @@ it('renders the correct number of alerts', () => { requestedVersion: 4.0, returnedVersion: 2.0 }), - new DatasetAlert('info', DatasetAlertMessageKey.UNPUBLISHED_DATASET, { + new DatasetAlert('info', DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET, { privateUrl: faker.internet.url() }) ] @@ -84,3 +93,43 @@ it('renders dynamic text', () => { cy.findByRole('alert').should('contain.text', dynamicFields.requestedVersion) cy.findByRole('alert').should('contain.text', dynamicFields.returnedVersion) }) +it('shows draft alert if version is DRAFT', () => { + const dataset = DatasetMother.create({ + version: DatasetVersionMother.createDraftAsLatestVersion(), + permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed() + }) + + cy.customMount() + + cy.findByRole('alert').should('contain.text', 'draft') +}) +it('does not show draft alert if version is RELEASED', () => { + const dataset = DatasetMother.create({ + version: DatasetVersionMother.createReleased(), + permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed() + }) + + cy.customMount() + cy.findByRole('alert').should('not.exist') +}) + +it('shows draft & share private url message if privateUrlToken exists', () => { + cy.fixture('../../../public/locales/en/dataset.json').then((datasetText: DatasetTranslation) => { + const privateUrlToken = '12345' + const dataset = DatasetMother.createWithPrivateUrlToken(privateUrlToken, { + version: DatasetVersionMother.createDraftAsLatestVersion(), + permissions: DatasetPermissionsMother.createWithAllAllowed() + }) + cy.customMount() + const expectedMessageKeys = [ + DatasetAlertMessageKey.DRAFT_VERSION, + DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET + ] + cy.findAllByRole('alert').should('have.length', 2) + cy.findAllByRole('alert').each(($alert, index) => { + const messageKey = expectedMessageKeys[index] + const itemText = datasetText.alerts[messageKey] + cy.wrap($alert).findByText(itemText.heading).should('exist') + }) + }) +}) From 671704d2053d457892cca959f323fd7a267b9b36 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 20 Oct 2023 14:58:09 -0400 Subject: [PATCH 19/30] fix: alerts.push() Unpublished Dataset --- src/dataset/domain/models/Dataset.ts | 2 +- .../dataset-alerts/DatasetAlert.stories.tsx | 7 +------ .../dataset-alerts/DatasetAlerts.spec.tsx | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 9fdb67ceb..7e7385b91 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -416,7 +416,7 @@ export class Dataset { ) ) } else { - new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET) + this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET)) } } } diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index f288c737e..ddc9a77b5 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -1,11 +1,6 @@ import type { Meta, StoryObj } from '@storybook/react' -import { - DatasetAlert, - DatasetAlertMessageKey, - DatasetPublishingStatus, - DatasetVersion -} from '../../../dataset/domain/models/Dataset' +import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset' import { DatasetAlerts } from '../../../sections/dataset/dataset-alerts/DatasetAlerts' import { WithI18next } from '../../WithI18next' diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index e91ccadfc..103fb63b0 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -133,3 +133,22 @@ it('shows draft & share private url message if privateUrlToken exists', () => { }) }) }) +it('shows private url message only if privateUrlToken exists and user cannot edit', () => { + cy.fixture('../../../public/locales/en/dataset.json').then((datasetText: DatasetTranslation) => { + const privateUrlToken = '12345' + const dataset = DatasetMother.createWithPrivateUrlToken(privateUrlToken, { + version: DatasetVersionMother.createDraftAsLatestVersion(), + permissions: DatasetPermissionsMother.createWithNoneAllowed() + }) + cy.customMount() + const expectedMessageKeys = [DatasetAlertMessageKey.UNPUBLISHED_DATASET] + + cy.findAllByRole('alert').should('have.length', 1) + cy.findAllByRole('alert').each(($alert, index) => { + const messageKey = expectedMessageKeys[index] + const itemText = datasetText.alerts[messageKey] + cy.wrap($alert).findByText(itemText.heading).should('exist') + expect($alert.text()).to.include(itemText.alertText) + }) + }) +}) From b8bf04dd1f476ee1edb1c521e0d0705406791bf7 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 20 Oct 2023 15:06:27 -0400 Subject: [PATCH 20/30] fix: remove unneeded loop --- .../sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index 103fb63b0..54236941d 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -141,12 +141,11 @@ it('shows private url message only if privateUrlToken exists and user cannot e permissions: DatasetPermissionsMother.createWithNoneAllowed() }) cy.customMount() - const expectedMessageKeys = [DatasetAlertMessageKey.UNPUBLISHED_DATASET] + const expectedMessageKey = DatasetAlertMessageKey.UNPUBLISHED_DATASET cy.findAllByRole('alert').should('have.length', 1) - cy.findAllByRole('alert').each(($alert, index) => { - const messageKey = expectedMessageKeys[index] - const itemText = datasetText.alerts[messageKey] + cy.findByRole('alert').then(($alert) => { + const itemText = datasetText.alerts[expectedMessageKey] cy.wrap($alert).findByText(itemText.heading).should('exist') expect($alert.text()).to.include(itemText.alertText) }) From 844c6de6718ef3fb4a2a6ec5719e2f2880326dc9 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 20 Oct 2023 15:28:43 -0400 Subject: [PATCH 21/30] fix: add DatasetAlert for VersionNotFoundShowDraft --- public/locales/en/dataset.json | 6 +++- src/dataset/domain/models/Dataset.ts | 34 +++++++++++++------ .../dataset-alerts/DatasetAlert.stories.tsx | 25 +++++++++++++- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index 736884a79..916ab30b4 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -63,9 +63,13 @@ "alertText": "When ready for sharing, please publish it so that others can see these changes" }, "requestedVersionNotFound": { - "heading": "Information", + "heading": "Info", "alertText": "Version {{requestedVersion}} was not found. This is version {{returnedVersion}}." }, + "requestedVersionNotFoundShowDraft": { + "heading": "Info", + "alertText": "Version {{requestedVersion}} was not found. This is the DRAFT version." + }, "shareUnpublishedDataset": { "heading": "Unpublished Dataset Private URL", "alertText": "Privately share this dataset before it is published: {{privateUrl}}" diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 7e7385b91..cb93a313b 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -27,6 +27,7 @@ export class DatasetLabel { export enum DatasetAlertMessageKey { DRAFT_VERSION = 'draftVersion', REQUESTED_VERSION_NOT_FOUND = 'requestedVersionNotFound', + REQUESTED_VERSION_NOT_FOUND_SHOW_DRAFT = 'requestedVersionNotFoundShowDraft', SHARE_UNPUBLISHED_DATASET = 'shareUnpublishedDataset', UNPUBLISHED_DATASET = 'unpublishedDataset' } @@ -392,17 +393,30 @@ export class Dataset { this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION)) } if (this.version.requestedVersion) { - const dynamicFields = { - requestedVersion: this.version.requestedVersion, - returnedVersion: `${this.version.toString()}` - } - this.alerts.push( - new DatasetAlert( - 'info', - DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, - dynamicFields + if (this.version.latestVersionStatus == DatasetPublishingStatus.RELEASED) { + const dynamicFields = { + requestedVersion: this.version.requestedVersion, + returnedVersion: `${this.version.toString()}` + } + this.alerts.push( + new DatasetAlert( + 'warning', + DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, + dynamicFields + ) ) - ) + } else { + const dynamicFields = { + requestedVersion: this.version.requestedVersion + } + this.alerts.push( + new DatasetAlert( + 'warning', + DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND_SHOW_DRAFT, + dynamicFields + ) + ) + } } if (this.privateUrlToken) { if (this.permissions.canUpdateDataset) { diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index ddc9a77b5..5d27cce60 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -60,6 +60,28 @@ export const VersionNotFound: Story = { ) } } +export const VersionNotFoundShowDraft: Story = { + render: () => { + const dataset = DatasetMother.createRealistic({ + version: new DatasetVersion( + 1, + DatasetPublishingStatus.DRAFT, + true, + false, + DatasetPublishingStatus.DRAFT, + 1, + 0, + '3.0' + ) + }) + + return ( +
+ +
+ ) + } +} export const SharePrivateUrl: Story = { render: () => { const dataset = DatasetMother.createWithPrivateUrlToken( @@ -98,7 +120,8 @@ export const UsePrivateUrl: Story = { DatasetPublishingStatus.DRAFT, 1, 0 - ) + ), + permissions: DatasetPermissionsMother.createWithNoneAllowed() } ) From e340b0657626db01c6d0bd27e914548d257351a3 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Sat, 21 Oct 2023 08:27:19 -0400 Subject: [PATCH 22/30] fix: add PrivateUrl alert to DatasetAnonymizedView story --- src/stories/dataset/Dataset.stories.tsx | 3 ++- src/stories/dataset/WithDatasetPrivateUrl.tsx | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/stories/dataset/WithDatasetPrivateUrl.tsx diff --git a/src/stories/dataset/Dataset.stories.tsx b/src/stories/dataset/Dataset.stories.tsx index 255e5a768..ab3c7e26e 100644 --- a/src/stories/dataset/Dataset.stories.tsx +++ b/src/stories/dataset/Dataset.stories.tsx @@ -3,6 +3,7 @@ import { WithI18next } from '../WithI18next' import { WithLayout } from '../WithLayout' import { Dataset } from '../../sections/dataset/Dataset' import { WithAnonymizedView } from './WithAnonymizedView' +import { WithDatasetPrivateUrl } from './WithDatasetPrivateUrl' import { FileMockRepository } from '../files/FileMockRepository' import { WithCitationMetadataBlockInfo } from './WithCitationMetadataBlockInfo' import { FileMockNoDataRepository } from '../files/FileMockNoDataRepository' @@ -53,7 +54,7 @@ export const DatasetNotFound: Story = { } export const DatasetAnonymizedView: Story = { - decorators: [WithLayout, WithAnonymizedView, WithDataset, WithFilePermissionsGranted], + decorators: [WithLayout, WithAnonymizedView, WithDatasetPrivateUrl, WithFilePermissionsGranted], render: () => } diff --git a/src/stories/dataset/WithDatasetPrivateUrl.tsx b/src/stories/dataset/WithDatasetPrivateUrl.tsx new file mode 100644 index 000000000..5aa2e6dec --- /dev/null +++ b/src/stories/dataset/WithDatasetPrivateUrl.tsx @@ -0,0 +1,26 @@ +import { StoryFn } from '@storybook/react' +import { DatasetProvider } from '../../sections/dataset/DatasetProvider' +import { DatasetRepository } from '../../dataset/domain/repositories/DatasetRepository' +import { Dataset } from '../../dataset/domain/models/Dataset' +import { DatasetMother } from '../../../tests/component/dataset/domain/models/DatasetMother' + +export const WithDatasetPrivateUrl = (Story: StoryFn) => { + const datasetRepository = {} as DatasetRepository + datasetRepository.getByPrivateUrlToken = ( + // eslint-disable-next-line unused-imports/no-unused-vars + privateUrlToken: string + ): Promise => { + return new Promise((resolve) => { + setTimeout(() => { + resolve(DatasetMother.createWithPrivateUrlToken(privateUrlToken)) + }, 1000) + }) + } + return ( + + + + ) +} From 619bdf08b24e7b1b3adfef7092d4ff94a9c90062 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Sat, 21 Oct 2023 09:00:33 -0400 Subject: [PATCH 23/30] fix: type safety errors, JSDatasetMapper.spec.ts --- .../mappers/JSDatasetMapper.spec.ts | 6 ++--- .../dataset-alerts/DatasetAlerts.spec.tsx | 26 +++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts index e4a857bc1..15df89047 100644 --- a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts +++ b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts @@ -148,9 +148,9 @@ const expectedDatasetAlternateVersion = { dynamicFields: undefined }, { - message: 'requestedVersionNotFound', - variant: 'info', - dynamicFields: { requestedVersion: '4.0', returnedVersion: '0.0' } + message: 'requestedVersionNotFoundShowDraft', + variant: 'warning', + dynamicFields: { requestedVersion: '4.0' } } ], summaryFields: [ diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index 54236941d..698b94b1c 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -16,24 +16,18 @@ function removeMarkup(htmlString: string): string { return htmlString.replace(/<\/?[^>]+(>|$)/g, '') } +interface AlertTranslation { + heading: string + alertText: string +} + interface DatasetTranslation { alerts: { - draftVersion: { - heading: string - alertText: string - } - requestedVersionNotFound: { - heading: string - alertText: string - } - unpublishedDataset: { - heading: string - alertText: string - } - shareUnpublishedDataset: { - heading: string - alertText: string - } + [DatasetAlertMessageKey.DRAFT_VERSION]: AlertTranslation + [DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND]: AlertTranslation + [DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND_SHOW_DRAFT]: AlertTranslation + [DatasetAlertMessageKey.UNPUBLISHED_DATASET]: AlertTranslation + [DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET]: AlertTranslation } } From 8b0d7fef109c635f26872587c376a87b4d2b19db Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Sat, 21 Oct 2023 11:25:35 -0400 Subject: [PATCH 24/30] fix: top margin for DatasetAlerts.module.scss --- src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss b/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss index ec77535e7..7413b02e8 100644 --- a/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss +++ b/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss @@ -1,3 +1,4 @@ .container > * { margin-right: 0.5em; + margin-top: 1em; } \ No newline at end of file From 0e9deeb9f3cd5c56b8ce8fbe5b14655494e22142 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Sat, 21 Oct 2023 11:30:36 -0400 Subject: [PATCH 25/30] fix: lint error DatasetAlerts.module.scss --- src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss b/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss index 7413b02e8..3a63a82e6 100644 --- a/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss +++ b/src/sections/dataset/dataset-alerts/DatasetAlerts.module.scss @@ -1,4 +1,4 @@ .container > * { - margin-right: 0.5em; margin-top: 1em; + margin-right: 0.5em; } \ No newline at end of file From 20f0ecf33a8332736f53dfaaba7872d6dfb32389 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 23 Oct 2023 13:47:18 -0400 Subject: [PATCH 26/30] fix: make alert box wider --- src/sections/dataset/Dataset.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sections/dataset/Dataset.tsx b/src/sections/dataset/Dataset.tsx index 686aeabf5..ac02c8e04 100644 --- a/src/sections/dataset/Dataset.tsx +++ b/src/sections/dataset/Dataset.tsx @@ -40,7 +40,7 @@ export function Dataset({ fileRepository }: DatasetProps) {
- + From 57b57a3fe5636ff1ce44a008b912b9ab4129b0f0 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 23 Oct 2023 16:47:54 -0400 Subject: [PATCH 27/30] fix: add 'privateUrl' to Dataset domain model --- src/dataset/domain/models/Dataset.ts | 28 ++++++++--------- .../dataset-alerts/DatasetAlert.stories.tsx | 31 +++++++++---------- .../dataset/domain/models/DatasetMother.ts | 1 + .../mappers/JSDatasetMapper.spec.ts | 4 ++- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index cb93a313b..cf1e7f8dc 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -289,7 +289,8 @@ export class Dataset { public readonly locks: DatasetLock[], public readonly hasValidTermsOfAccess: boolean, public readonly isValid: boolean, - public readonly isReleased: boolean + public readonly isReleased: boolean, + public readonly privateUrl?: string ) {} public getTitle(): string { @@ -334,6 +335,7 @@ export class Dataset { public readonly hasValidTermsOfAccess: boolean, public readonly isValid: boolean, public readonly isReleased: boolean, + public readonly privateUrl?: string, public readonly privateUrlToken?: string ) { this.withLabels() @@ -386,6 +388,9 @@ export class Dataset { } private withAlerts(): void { + console.log( + 'withAlerts, privateUrl ' + this.privateUrl + ' privateUrlToken: ' + this.privateUrlToken + ) if ( this.version.publishingStatus === DatasetPublishingStatus.DRAFT && this.permissions.canPublishDataset @@ -418,20 +423,15 @@ export class Dataset { ) } } + if (this.privateUrl && !this.privateUrlToken) { + const dynamicFields = { privateUrl: this.privateUrl } + this.alerts.push( + new DatasetAlert('info', DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET, dynamicFields) + ) + } + if (this.privateUrlToken) { - if (this.permissions.canUpdateDataset) { - // TODO: set the whole Url, not just the token - const dynamicFields = { privateUrl: this.privateUrlToken } - this.alerts.push( - new DatasetAlert( - 'info', - DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET, - dynamicFields - ) - ) - } else { - this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET)) - } + this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET)) } } diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 5d27cce60..56aacf802 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -84,21 +84,20 @@ export const VersionNotFoundShowDraft: Story = { } export const SharePrivateUrl: Story = { render: () => { - const dataset = DatasetMother.createWithPrivateUrlToken( - 'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb', - { - version: new DatasetVersion( - 1, - DatasetPublishingStatus.RELEASED, - true, - false, - DatasetPublishingStatus.DRAFT, - 1, - 0 - ), - permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed() - } - ) + const dataset = DatasetMother.createRealistic({ + version: new DatasetVersion( + 1, + DatasetPublishingStatus.RELEASED, + true, + false, + DatasetPublishingStatus.DRAFT, + 1, + 0 + ), + permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(), + privateUrl: + 'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb' + }) return (
@@ -110,7 +109,7 @@ export const SharePrivateUrl: Story = { export const UsePrivateUrl: Story = { render: () => { const dataset = DatasetMother.createWithPrivateUrlToken( - 'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb', + 'cd943c75-1cc7-4c1d-9717-98141d65d5cb', { version: new DatasetVersion( 1, diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 87fa1cb8e..9a1fc483a 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -306,6 +306,7 @@ export class DatasetMother { dataset.hasValidTermsOfAccess, dataset.isValid, dataset.isReleased, + dataset.privateUrl, privateUrlToken ).build() } diff --git a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts index 15df89047..b5ffb6aa6 100644 --- a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts +++ b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts @@ -118,7 +118,8 @@ const expectedDataset = { locks: [], hasValidTermsOfAccess: true, isValid: true, - isReleased: false + isReleased: false, + privateUrl: undefined } const expectedDatasetAlternateVersion = { persistentId: 'doi:10.5072/FK2/B4B2MJ', @@ -137,6 +138,7 @@ const expectedDatasetAlternateVersion = { hasValidTermsOfAccess: true, isReleased: false, isValid: true, + privateUrl: undefined, labels: [ { semanticMeaning: 'dataset', value: 'Draft' }, { semanticMeaning: 'warning', value: 'Unpublished' } From fccce0e684f303d73d3bf6bcc2ea49901c3b6196 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 23 Oct 2023 16:52:49 -0400 Subject: [PATCH 28/30] fix: remove console.log() --- src/dataset/domain/models/Dataset.ts | 3 --- .../dataset/infrastructure/mappers/JSDatasetMapper.spec.ts | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index cf1e7f8dc..a8c5384ec 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -388,9 +388,6 @@ export class Dataset { } private withAlerts(): void { - console.log( - 'withAlerts, privateUrl ' + this.privateUrl + ' privateUrlToken: ' + this.privateUrlToken - ) if ( this.version.publishingStatus === DatasetPublishingStatus.DRAFT && this.permissions.canPublishDataset diff --git a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts index b5ffb6aa6..cf04a2edc 100644 --- a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts +++ b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts @@ -215,8 +215,6 @@ describe('JS Dataset Mapper', () => { datasetSummaryFields, '4.0' ) - console.log('mapped: ' + JSON.stringify(mappedWithAlternate)) - console.log('expected: ' + JSON.stringify(expectedDatasetAlternateVersion)) expect(expectedDatasetAlternateVersion).to.deep.equal(mappedWithAlternate) }) From a441c832aa7dbed4d650030b91c5229d9b91bf92 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 26 Oct 2023 09:14:19 -0400 Subject: [PATCH 29/30] fix: use PrivateUrl object in Dataset domain object --- src/dataset/domain/models/Dataset.ts | 32 ++++++++++------ .../infrastructure/mappers/JSDatasetMapper.ts | 29 ++------------- .../DatasetJSDataverseRepository.ts | 8 +--- src/stories/dataset/WithDatasetPrivateUrl.tsx | 9 ++++- .../dataset-alerts/DatasetAlert.stories.tsx | 37 ++++++++++--------- .../dataset/domain/models/DatasetMother.ts | 9 +---- .../dataset-alerts/DatasetAlerts.spec.tsx | 22 +++++++---- 7 files changed, 68 insertions(+), 78 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index a8c5384ec..a0d96e6c7 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -275,6 +275,11 @@ export enum DatasetLockReason { FILE_VALIDATION_FAILED = 'fileValidationFailed' } +export interface PrivateUrl { + token: string + urlSnippet: string +} + export class Dataset { constructor( public readonly persistentId: string, @@ -290,7 +295,7 @@ export class Dataset { public readonly hasValidTermsOfAccess: boolean, public readonly isValid: boolean, public readonly isReleased: boolean, - public readonly privateUrl?: string + public readonly privateUrl?: PrivateUrl ) {} public getTitle(): string { @@ -335,8 +340,7 @@ export class Dataset { public readonly hasValidTermsOfAccess: boolean, public readonly isValid: boolean, public readonly isReleased: boolean, - public readonly privateUrl?: string, - public readonly privateUrlToken?: string + public readonly privateUrl?: PrivateUrl ) { this.withLabels() this.withAlerts() @@ -420,15 +424,19 @@ export class Dataset { ) } } - if (this.privateUrl && !this.privateUrlToken) { - const dynamicFields = { privateUrl: this.privateUrl } - this.alerts.push( - new DatasetAlert('info', DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET, dynamicFields) - ) - } - - if (this.privateUrlToken) { - this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET)) + if (this.privateUrl) { + if (this.permissions.canPublishDataset) { + const dynamicFields = { privateUrl: this.privateUrl.urlSnippet + this.privateUrl.token } + this.alerts.push( + new DatasetAlert( + 'info', + DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET, + dynamicFields + ) + ) + } else { + this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET)) + } } } diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index 7b7bc47f8..fdf543694 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -13,40 +13,17 @@ import { DatasetMetadataBlocks, DatasetMetadataFields, DatasetVersion, - MetadataBlockName + MetadataBlockName, + PrivateUrl } from '../../domain/models/Dataset' -/* - - static Builder = class { - public readonly labels: DatasetLabel[] = [] - public readonly alerts: DatasetAlert[] = [] - - constructor( - public readonly persistentId: string, - public readonly version: DatasetVersion, - public readonly citation: string, - public readonly summaryFields: DatasetMetadataBlock[], - public readonly license: DatasetLicense = defaultLicense, - public readonly metadataBlocks: DatasetMetadataBlocks, - public readonly permissions: DatasetPermissions, - public readonly locks: DatasetLock[], - public readonly hasValidTermsOfAccess: boolean, - public readonly isValid: boolean, - public readonly isReleased: boolean, - public readonly privateUrl?: string - ) { - this.withLabels() - this.withAlerts() - } - */ export class JSDatasetMapper { static toDataset( jsDataset: JSDataset, citation: string, summaryFieldsNames: string[], requestedVersion?: string, - privateUrl?: string + privateUrl?: PrivateUrl ): Dataset { return new Dataset.Builder( jsDataset.persistentId, diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index 1464847ea..317254b9b 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -44,13 +44,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository { getPrivateUrlDatasetCitation.execute(privateUrlToken) ]) .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => - JSDatasetMapper.toDataset( - jsDataset, - citation, - summaryFieldsNames, - undefined, - privateUrlToken - ) + JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, undefined) ) .catch((error: WriteError) => { throw new Error(error.message) diff --git a/src/stories/dataset/WithDatasetPrivateUrl.tsx b/src/stories/dataset/WithDatasetPrivateUrl.tsx index 5aa2e6dec..1cc892f75 100644 --- a/src/stories/dataset/WithDatasetPrivateUrl.tsx +++ b/src/stories/dataset/WithDatasetPrivateUrl.tsx @@ -12,7 +12,14 @@ export const WithDatasetPrivateUrl = (Story: StoryFn) => { ): Promise => { return new Promise((resolve) => { setTimeout(() => { - resolve(DatasetMother.createWithPrivateUrlToken(privateUrlToken)) + resolve( + DatasetMother.createRealistic({ + privateUrl: { + urlSnippet: 'http://localhost:8080/privateurl.xhtml?token=', + token: 'cd943c75-1cc7-4c1d-9717-98141d65d5cb' + } + }) + ) }, 1000) }) } diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 56aacf802..072994ad5 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -94,9 +94,11 @@ export const SharePrivateUrl: Story = { 1, 0 ), - permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(), - privateUrl: - 'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb' + permissions: DatasetPermissionsMother.createWithAllAllowed(), + privateUrl: { + urlSnippet: 'http://localhost:8080/privateurl.xhtml?token=', + token: 'cd943c75-1cc7-4c1d-9717-98141d65d5cb' + } }) return ( @@ -108,21 +110,22 @@ export const SharePrivateUrl: Story = { } export const UsePrivateUrl: Story = { render: () => { - const dataset = DatasetMother.createWithPrivateUrlToken( - 'cd943c75-1cc7-4c1d-9717-98141d65d5cb', - { - version: new DatasetVersion( - 1, - DatasetPublishingStatus.RELEASED, - true, - false, - DatasetPublishingStatus.DRAFT, - 1, - 0 - ), - permissions: DatasetPermissionsMother.createWithNoneAllowed() + const dataset = DatasetMother.createRealistic({ + version: new DatasetVersion( + 1, + DatasetPublishingStatus.RELEASED, + true, + false, + DatasetPublishingStatus.DRAFT, + 1, + 0 + ), + permissions: DatasetPermissionsMother.createWithNoneAllowed(), + privateUrl: { + urlSnippet: 'http://localhost:8080/privateurl.xhtml?token=', + token: 'cd943c75-1cc7-4c1d-9717-98141d65d5cb' } - ) + }) return (
diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 9a1fc483a..c96e0a5f8 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -190,11 +190,7 @@ export class DatasetMother { return undefined } - static createWithPrivateUrlToken(privateUrlToken: string, props?: Partial) { - return this.create(props, privateUrlToken) - } - - static create(props?: Partial, privateUrlToken?: string): Dataset { + static create(props?: Partial): Dataset { const dataset = { persistentId: faker.datatype.uuid(), title: faker.lorem.sentence(), @@ -306,8 +302,7 @@ export class DatasetMother { dataset.hasValidTermsOfAccess, dataset.isValid, dataset.isReleased, - dataset.privateUrl, - privateUrlToken + dataset.privateUrl ).build() } diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index 698b94b1c..d70fd4977 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -107,12 +107,15 @@ it('does not show draft alert if version is RELEASED', () => { cy.findByRole('alert').should('not.exist') }) -it('shows draft & share private url message if privateUrlToken exists', () => { +it('shows draft & share private url message if privateUrl exists and user can edit', () => { cy.fixture('../../../public/locales/en/dataset.json').then((datasetText: DatasetTranslation) => { - const privateUrlToken = '12345' - const dataset = DatasetMother.createWithPrivateUrlToken(privateUrlToken, { + const dataset = DatasetMother.createRealistic({ version: DatasetVersionMother.createDraftAsLatestVersion(), - permissions: DatasetPermissionsMother.createWithAllAllowed() + permissions: DatasetPermissionsMother.createWithAllAllowed(), + privateUrl: { + urlSnippet: 'http://localhost:8080/privateurl.xhtml?token=', + token: 'cd943c75-1cc7-4c1d-9717-98141d65d5cb' + } }) cy.customMount() const expectedMessageKeys = [ @@ -127,12 +130,15 @@ it('shows draft & share private url message if privateUrlToken exists', () => { }) }) }) -it('shows private url message only if privateUrlToken exists and user cannot edit', () => { +it('shows private url message only if privateUrl exists and user cannot edit', () => { cy.fixture('../../../public/locales/en/dataset.json').then((datasetText: DatasetTranslation) => { - const privateUrlToken = '12345' - const dataset = DatasetMother.createWithPrivateUrlToken(privateUrlToken, { + const dataset = DatasetMother.createRealistic({ version: DatasetVersionMother.createDraftAsLatestVersion(), - permissions: DatasetPermissionsMother.createWithNoneAllowed() + permissions: DatasetPermissionsMother.createWithNoneAllowed(), + privateUrl: { + urlSnippet: 'http://localhost:8080/privateurl.xhtml?token=', + token: 'cd943c75-1cc7-4c1d-9717-98141d65d5cb' + } }) cy.customMount() const expectedMessageKey = DatasetAlertMessageKey.UNPUBLISHED_DATASET From ecf87c4ab19d1b6a3ac88e5a18f49b2779f4f667 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 27 Oct 2023 10:43:37 -0400 Subject: [PATCH 30/30] fix: isReleased (will be replaced with dataset isReleased when integration is completed) --- src/dataset/infrastructure/mappers/JSDatasetMapper.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index fdf543694..065f95212 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -48,7 +48,8 @@ export class JSDatasetMapper { [], // TODO Connect with dataset locks true, // TODO Connect with dataset hasValidTermsOfAccess true, // TODO Connect with dataset isValid - !!jsDataset.versionInfo.releaseTime, // TODO Connect with dataset isReleased, + jsDataset.versionInfo.releaseTime !== undefined && + !isNaN(jsDataset.versionInfo.releaseTime.getTime()), // TODO Connect with dataset isReleased, privateUrl ).build() }