Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

321 default dataset version #442

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ export enum DatasetPublishingStatus {

export enum DatasetNonNumericVersion {
LATEST = ':latest',
DRAFT = ':draft'
DRAFT = ':draft',
LATEST_PUBLISHED = ':latest-published'
}
export enum DatasetVersionNonNumericSearchParam {
ekraffmiller marked this conversation as resolved.
Show resolved Hide resolved
DRAFT = 'DRAFT'
}

export class DatasetVersionNumber {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DatasetRepository } from '../../domain/repositories/DatasetRepository'
import { Dataset } from '../../domain/models/Dataset'
import { Dataset, DatasetNonNumericVersion } from '../../domain/models/Dataset'
import {
getDataset,
getAllDatasetPreviews,
Expand Down Expand Up @@ -116,9 +116,10 @@ export class DatasetJSDataverseRepository implements DatasetRepository {

getByPersistentId(
persistentId: string,
version?: string,
version: string = DatasetNonNumericVersion.LATEST_PUBLISHED,
requestedVersion?: string
): Promise<Dataset | undefined> {
console.log('getByPersistentId', persistentId, version, requestedVersion)
ekraffmiller marked this conversation as resolved.
Show resolved Hide resolved
return getDataset
.execute(persistentId, version, includeDeaccessioned)
.then((jsDataset) => this.fetchDatasetDetails(jsDataset, version))
Expand Down Expand Up @@ -147,10 +148,14 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
})
.catch((error: ReadError) => {
console.error(error)
if (!version) {
if (version === DatasetNonNumericVersion.LATEST_PUBLISHED) {
throw new Error(`Failed to get dataset by persistent ID: ${error.message}`)
}
g-saracca marked this conversation as resolved.
Show resolved Hide resolved
return this.getByPersistentId(persistentId, undefined, (requestedVersion = version))
return this.getByPersistentId(
persistentId,
DatasetNonNumericVersion.LATEST_PUBLISHED,
(requestedVersion = version)
)
})
}
getByPrivateUrlToken(privateUrlToken: string): Promise<Dataset | undefined> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@ import { LinkToPage } from '../../../shared/link-to-page/LinkToPage'
import { Route } from '../../../Route.enum'
import { DatasetLabels } from '../../../dataset/dataset-labels/DatasetLabels'
import { DatasetIcon } from '../../../dataset/dataset-icon/DatasetIcon'
import { DatasetVersion } from '../../../../dataset/domain/models/Dataset'
import {
DatasetPublishingStatus,
DatasetVersion,
DatasetVersionNonNumericSearchParam
} from '../../../../dataset/domain/models/Dataset'

interface DatasetCardHeaderProps {
persistentId: string
version: DatasetVersion
}
function getSearchParams(
persistentId: string,
publishingStatus: DatasetPublishingStatus
): Record<string, string> {
const params: Record<string, string> = { persistentId: persistentId }
if (publishingStatus === DatasetPublishingStatus.DRAFT) {
params.version = DatasetVersionNonNumericSearchParam.DRAFT
}
return params
}
export function DatasetCardHeader({ persistentId, version }: DatasetCardHeaderProps) {
return (
<div className={styles.header}>
<div className={styles.title}>
<LinkToPage page={Route.DATASETS} searchParams={{ persistentId: persistentId }}>
<LinkToPage
page={Route.DATASETS}
searchParams={getSearchParams(persistentId, version.publishingStatus)}>
{version.title}
</LinkToPage>
<DatasetLabels labels={version.labels} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MetadataFieldsHelper, type DatasetMetadataFormValues } from './Metadata
import { getValidationFailedFieldError } from '../../../../metadata-block-info/domain/models/fieldValidations'
import { type DatasetMetadataFormMode } from '.'
import { Route } from '../../../Route.enum'
import { DatasetVersionNonNumericSearchParam } from '../../../../dataset/domain/models/Dataset'

export enum SubmissionStatus {
NotSubmitted = 'NotSubmitted',
Expand Down Expand Up @@ -56,11 +57,12 @@ export function useSubmitDataset(
)

if (mode === 'create') {
const DRAFT_PARAM = DatasetVersionNonNumericSearchParam.DRAFT
createDataset(datasetRepository, formattedFormValues, collectionId)
.then(({ persistentId }) => {
setSubmitError(null)
setSubmissionStatus(SubmissionStatus.SubmitComplete)
navigate(`${Route.DATASETS}?persistentId=${persistentId}`, {
navigate(`${Route.DATASETS}?persistentId=${persistentId}&version=${DRAFT_PARAM}`, {
ekraffmiller marked this conversation as resolved.
Show resolved Hide resolved
state: { created: true }
})
return
Expand Down
30 changes: 17 additions & 13 deletions tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DatasetLabelValue } from '../../../../../src/dataset/domain/models/Dataset'
import {
DatasetLabelValue,
DatasetVersionNonNumericSearchParam
} from '../../../../../src/dataset/domain/models/Dataset'
import { TestsUtils } from '../../../shared/TestsUtils'
import { DatasetHelper, DatasetResponse } from '../../../shared/datasets/DatasetHelper'
import { FileHelper } from '../../../shared/files/FileHelper'
Expand All @@ -9,6 +12,7 @@ import { FILES_TAB_INFINITE_SCROLL_ENABLED } from '../../../../../src/sections/d
type Dataset = {
datasetVersion: { metadataBlocks: { citation: { fields: { value: string }[] } } }
}
const DRAFT_PARAM = DatasetVersionNonNumericSearchParam.DRAFT

describe('Dataset', () => {
before(() => {
Expand All @@ -24,7 +28,7 @@ describe('Dataset', () => {
cy.wrap(DatasetHelper.create())
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.fixture('dataset-finch1.json').then((dataset: Dataset) => {
cy.findByRole('heading', {
Expand Down Expand Up @@ -72,7 +76,7 @@ describe('Dataset', () => {
.its('persistentId')
.then((persistentId: string) => {
cy.wrap(TestsUtils.logout())
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Page Not Found').should('exist')
})
Expand Down Expand Up @@ -181,7 +185,7 @@ describe('Dataset', () => {
)
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Root').should('exist')
cy.findByRole('link', { name: 'Scientific Research' }).should('exist').click()
Expand All @@ -196,7 +200,7 @@ describe('Dataset', () => {
cy.wrap(DatasetHelper.create())
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Files').should('exist')

Expand All @@ -208,7 +212,7 @@ describe('Dataset', () => {
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createMany(3)), { timeout: 5000 })
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Files').should('exist')

Expand All @@ -228,7 +232,7 @@ describe('Dataset', () => {
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createMany(30)), { timeout: 20000 })
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Files').should('exist')

Expand All @@ -252,7 +256,7 @@ describe('Dataset', () => {
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createMany(30)), { timeout: 20000 })
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Files').should('exist')

Expand Down Expand Up @@ -282,7 +286,7 @@ describe('Dataset', () => {
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createMany(3)))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Files').should('exist')

Expand Down Expand Up @@ -319,7 +323,7 @@ describe('Dataset', () => {
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createManyRestricted(1)))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Files').should('exist')

Expand Down Expand Up @@ -402,7 +406,7 @@ describe('Dataset', () => {
.then((persistentId: string) => {
cy.wait(1500) // Wait for the files to be embargoed

cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.wait(1500) // Wait for the files to be loaded

Expand Down Expand Up @@ -460,7 +464,7 @@ describe('Dataset', () => {
cy.wrap(DatasetHelper.createWithFiles(files))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Files').should('exist')

Expand Down Expand Up @@ -580,7 +584,7 @@ describe('Dataset', () => {
cy.wrap(FileHelper.createImage().then((file) => DatasetHelper.createWithFiles([file])))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.findByText('Files').should('exist')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DatasetLabel,
DatasetLabelSemanticMeaning,
DatasetLockReason,
DatasetNonNumericVersion,
DatasetPublishingStatus,
DatasetVersion,
MetadataBlockName
Expand All @@ -19,6 +20,7 @@ import {
import { DatasetPaginationInfo } from '../../../../src/dataset/domain/models/DatasetPaginationInfo'
import { DatasetDTO } from '../../../../src/dataset/domain/useCases/DTOs/DatasetDTO'
import { CollectionHelper } from '../../shared/collection/CollectionHelper'
const DRAFT_PARAM = DatasetNonNumericVersion.DRAFT

chai.use(chaiAsPromised)
const expect = chai.expect
Expand Down Expand Up @@ -142,23 +144,25 @@ describe('Dataset JSDataverse Repository', () => {
it('gets the dataset by persistentId', async () => {
const datasetResponse = await DatasetHelper.create(collectionId)

await datasetRepository.getByPersistentId(datasetResponse.persistentId).then((dataset) => {
if (!dataset) {
throw new Error('Dataset not found')
}
const datasetExpected = datasetData(dataset.persistentId, dataset.version.id)
await datasetRepository
.getByPersistentId(datasetResponse.persistentId, DRAFT_PARAM)
.then((dataset) => {
if (!dataset) {
throw new Error('Dataset not found')
}
const datasetExpected = datasetData(dataset.persistentId, dataset.version.id)

expect(dataset.license).to.deep.equal(datasetExpected.license)
expect(dataset.metadataBlocks).to.deep.equal(datasetExpected.metadataBlocks)
expect(dataset.summaryFields).to.deep.equal(datasetExpected.summaryFields)
expect(dataset.version).to.deep.equal(datasetExpected.version)
expect(dataset.metadataBlocks[0].fields.publicationDate).not.to.exist
expect(dataset.metadataBlocks[0].fields.citationDate).not.to.exist
expect(dataset.permissions).to.deep.equal(datasetExpected.permissions)
expect(dataset.locks).to.deep.equal(datasetExpected.locks)
expect(dataset.downloadUrls).to.deep.equal(datasetExpected.downloadUrls)
expect(dataset.fileDownloadSizes).to.deep.equal(datasetExpected.fileDownloadSizes)
})
expect(dataset.license).to.deep.equal(datasetExpected.license)
expect(dataset.metadataBlocks).to.deep.equal(datasetExpected.metadataBlocks)
expect(dataset.summaryFields).to.deep.equal(datasetExpected.summaryFields)
expect(dataset.version).to.deep.equal(datasetExpected.version)
expect(dataset.metadataBlocks[0].fields.publicationDate).not.to.exist
expect(dataset.metadataBlocks[0].fields.citationDate).not.to.exist
expect(dataset.permissions).to.deep.equal(datasetExpected.permissions)
expect(dataset.locks).to.deep.equal(datasetExpected.locks)
expect(dataset.downloadUrls).to.deep.equal(datasetExpected.downloadUrls)
expect(dataset.fileDownloadSizes).to.deep.equal(datasetExpected.fileDownloadSizes)
})
})

it('gets a published dataset by persistentId without user authentication', async () => {
Expand Down Expand Up @@ -247,7 +251,7 @@ describe('Dataset JSDataverse Repository', () => {
const datasetResponse = await DatasetHelper.create(collectionId)

await datasetRepository
.getByPersistentId(datasetResponse.persistentId, 'DRAFT')
.getByPersistentId(datasetResponse.persistentId, DRAFT_PARAM)
.then((dataset) => {
if (!dataset) {
throw new Error('Dataset not found')
Expand Down Expand Up @@ -338,20 +342,22 @@ describe('Dataset JSDataverse Repository', () => {
const datasetResponse = await DatasetHelper.create(collectionId)
await DatasetHelper.lock(datasetResponse.id, DatasetLockReason.FINALIZE_PUBLICATION)

await datasetRepository.getByPersistentId(datasetResponse.persistentId).then((dataset) => {
if (!dataset) {
throw new Error('Dataset not found')
}
const datasetExpected = datasetData(dataset.persistentId, dataset.version.id)

expect(dataset.version.title).to.deep.equal(datasetExpected.title)
expect(dataset.locks).to.deep.equal([
{
userPersistentId: 'dataverseAdmin',
reason: DatasetLockReason.FINALIZE_PUBLICATION
await datasetRepository
.getByPersistentId(datasetResponse.persistentId, DRAFT_PARAM)
.then((dataset) => {
if (!dataset) {
throw new Error('Dataset not found')
}
])
})
const datasetExpected = datasetData(dataset.persistentId, dataset.version.id)

expect(dataset.version.title).to.deep.equal(datasetExpected.title)
expect(dataset.locks).to.deep.equal([
{
userPersistentId: 'dataverseAdmin',
reason: DatasetLockReason.FINALIZE_PUBLICATION
}
])
})
})

it('creates a new dataset from DatasetDTO', async () => {
Expand Down
Loading
Loading