From 89bf3e3d8d654d48a129254afe0d2e3c8680eeed Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Tue, 3 Sep 2024 16:37:03 -0400 Subject: [PATCH] updates based on review suggestions --- .../DatasetJSDataverseRepository.ts | 10 +- .../input-levels-table/InputLevelsTable.tsx | 2 +- .../PublishDatasetHelpText.module.scss | 1 - .../publish-dataset/PublishDatasetModal.tsx | 93 +++++++++---------- .../publish-dataset/useGetVersionLabels.tsx | 39 -------- .../PublishDatasetModal.stories.tsx | 2 - .../e2e/sections/dataset/Dataset.spec.tsx | 2 +- 7 files changed, 54 insertions(+), 95 deletions(-) delete mode 100644 src/sections/dataset/publish-dataset/useGetVersionLabels.tsx diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index afd1352e7..a5856a134 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -165,6 +165,8 @@ export class DatasetJSDataverseRepository implements DatasetRepository { datasetDetails.jsDataset.versionInfo.state === DatasetVersionState.DRAFT && datasetDetails.jsDataset.publicationDate !== undefined ) { + // If the dataset is a draft, but has a publication date, then we need the version + // numbers of the latest published version to show in the "Publish" button return this.getLatestPublishedVersionNumbers(datasetDetails) } else { return datasetDetails @@ -214,10 +216,10 @@ export class DatasetJSDataverseRepository implements DatasetRepository { canManageDatasetPermissions: true, canDeleteDatasetDraft: true, canViewUnpublishedDataset: true - }, - [], - 0, - 0 + }, // TODO Connect with JS dataset permissions for privateUrl when it is available in js-dataverse + [], // TODO Connect with JS dataset locks for privateUrl when it is available in js-dataverse + 0, // TODO Connect with JS dataset filesTotalDownloadSize for privateUrl when it is available in js-dataverse + 0 // TODO Connect with JS dataset filesTotalDownloadSize for privateUrl when it is available in js-dataverse ) ) .catch((error: ReadError) => { diff --git a/src/sections/create-collection/collection-form/metadata-fields-section/metadata-input-level-fields-block/input-levels-table/InputLevelsTable.tsx b/src/sections/create-collection/collection-form/metadata-fields-section/metadata-input-level-fields-block/input-levels-table/InputLevelsTable.tsx index 4ad257922..3f18c5cf1 100644 --- a/src/sections/create-collection/collection-form/metadata-fields-section/metadata-input-level-fields-block/input-levels-table/InputLevelsTable.tsx +++ b/src/sections/create-collection/collection-form/metadata-fields-section/metadata-input-level-fields-block/input-levels-table/InputLevelsTable.tsx @@ -26,7 +26,7 @@ export const InputLevelsTable = ({ })}>
{closeButton}
- +
{Object.entries(blockMetadataInputLevelFields.metadataFields).map(([key, field]) => ( diff --git a/src/sections/dataset/publish-dataset/PublishDatasetHelpText.module.scss b/src/sections/dataset/publish-dataset/PublishDatasetHelpText.module.scss index 5e5661ae8..d9e23efb3 100644 --- a/src/sections/dataset/publish-dataset/PublishDatasetHelpText.module.scss +++ b/src/sections/dataset/publish-dataset/PublishDatasetHelpText.module.scss @@ -1,7 +1,6 @@ @import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module"; .container { - margin: 10px; padding: 10px; background-color: $dv-info-box-color; border: 1px solid black; diff --git a/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx b/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx index 70a0df1b8..0e1762ee4 100644 --- a/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx +++ b/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx @@ -1,6 +1,6 @@ import { useState } from 'react' import { useTranslation } from 'react-i18next' -import { Button, Modal } from '@iqss/dataverse-design-system' +import { Button, Modal, Stack } from '@iqss/dataverse-design-system' import { Form } from '@iqss/dataverse-design-system' import type { DatasetRepository } from '../../../dataset/domain/repositories/DatasetRepository' import { VersionUpdateType } from '../../../dataset/domain/models/VersionUpdateType' @@ -23,9 +23,9 @@ interface PublishDatasetModalProps { repository: DatasetRepository persistentId: string releasedVersionExists: boolean - nextMajorVersion: string | undefined - nextMinorVersion: string | undefined handleClose: () => void + nextMajorVersion?: string + nextMinorVersion?: string } export function PublishDatasetModal({ @@ -33,9 +33,9 @@ export function PublishDatasetModal({ repository, persistentId, releasedVersionExists, + handleClose, nextMajorVersion, - nextMinorVersion, - handleClose + nextMinorVersion }: PublishDatasetModalProps) { const { t } = useTranslation('dataset') const { user } = useSession() @@ -64,57 +64,56 @@ export function PublishDatasetModal({ ) handleClose() } - if (releasedVersionExists && (!nextMajorVersion || !nextMinorVersion)) { - console.log('Error: nextMajorVersion or nextMinorVersion is missing') - return null - } + return ( - + Publish Dataset - - - {releasedVersionExists && ( - <> -

{t('publish.selectVersion')}

- - - - {user?.superuser && ( + + + + {releasedVersionExists && ( + <> + {t('publish.selectVersion')} + + - )} - - - )} + {user?.superuser && ( + + )} + + + )} + {submissionStatus === SubmissionStatus.Errored && `${t('publish.error')} ${publishError ? publishError : ''}`} diff --git a/src/sections/dataset/publish-dataset/useGetVersionLabels.tsx b/src/sections/dataset/publish-dataset/useGetVersionLabels.tsx deleted file mode 100644 index 55dea22bc..000000000 --- a/src/sections/dataset/publish-dataset/useGetVersionLabels.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { useEffect, useState } from 'react' -import { DatasetRepository } from '../../../dataset/domain/repositories/DatasetRepository' - -type UseGetVersionLabelsReturnType = { - minorVersion: string - majorVersion: string -} - -export function UseGetVersionLabels( - repository: DatasetRepository, - - persistentId: string -): UseGetVersionLabelsReturnType { - const [minorVersion, setMinorVersion] = useState('') - const [majorVersion, setMajorVersion] = useState('') - - useEffect(() => { - const fetchVersions = async () => { - try { - await repository.getByPersistentId(persistentId).then((dataset) => { - const majorVersionNumber = dataset?.version.number.majorNumber ?? 0 - const minorVersionNumber = dataset?.version.number.minorNumber ?? 0 - - setMajorVersion((majorVersionNumber + 1).toString() + '.0') - setMinorVersion((majorVersionNumber + minorVersionNumber + 0.1).toString()) - }) - } catch (error) { - console.error('Publish Dataset: failed to fetch version numbers:', error) - } - } - - void fetchVersions() - }, [repository, persistentId]) - - return { - minorVersion, - majorVersion - } as UseGetVersionLabelsReturnType -} diff --git a/src/stories/dataset/publish-dataset/PublishDatasetModal.stories.tsx b/src/stories/dataset/publish-dataset/PublishDatasetModal.stories.tsx index 4edc5aed2..671c629e6 100644 --- a/src/stories/dataset/publish-dataset/PublishDatasetModal.stories.tsx +++ b/src/stories/dataset/publish-dataset/PublishDatasetModal.stories.tsx @@ -23,8 +23,6 @@ export const Default: Story = { repository={new DatasetMockRepository()} persistentId={'test'} releasedVersionExists={false} - nextMinorVersion={undefined} - nextMajorVersion={undefined} handleClose={() => {}}> ) } diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index 86cb1845c..87bb8fc89 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -268,7 +268,7 @@ describe('Dataset', () => { }) }) - it.only('successfully loads the files tab with files', () => { + it('successfully loads the files tab with files', () => { cy.wrap(DatasetHelper.createWithFiles(FileHelper.createMany(3)), { timeout: 5000 }) .its('persistentId') .then((persistentId: string) => {