Skip to content

Commit

Permalink
Merge pull request #551 from IQSS/feature/492-publish-dataset-with-co…
Browse files Browse the repository at this point in the history
…mpare-versions

Feature/492 publish dataset with compare versions
  • Loading branch information
ofahimIQSS authored Jan 6, 2025
2 parents 9170126 + cb7403e commit 9e91afa
Show file tree
Hide file tree
Showing 18 changed files with 584 additions and 56 deletions.
10 changes: 7 additions & 3 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@
}
},
"publish": {
"draftQuestion": "Are you sure you want to publish this dataset? Once you do so, it must remain public.",
"draftQuestion": "Are you sure you want to publish this dataset? Once you do so, it must remain published.",
"draftSubtext": "This version of the dataset will be published with the following terms:",
"previouslyReleasedQuestion": "Are you sure you want to republish this dataset?",
"releaseCollectionQuestion": "This dataset cannot be published until <a>{{parentCollectionName}}</a> is published. Would you like to publish both right now?",
"termsText": "To publish with custom Terms of Use, click the Cancel button and go to the Terms tab for this dataset.",
"previouslyReleasedSubtext": "Select if this is a minor or major version update.",
"releaseCollectionQuestion": "This dataset cannot be published until <a>{{parentCollectionName}}</a> is published. Would you like to publish both right now? ",
"releaseCollectionSubtext": "Once you publish this dataset it must remain published.",
"requiresMajorReleaseSubtext": "Due to the nature of the changes to the current draft this will be a major release ({{versionNumber}})",
"termsText": "To change the terms for this version, click the Cancel button and go to the Terms tab for this dataset.",
"selectVersion": "Select if this is a minor or major version update.",
"continueButton": "Continue",
"cancelButton": "Cancel",
Expand Down
9 changes: 6 additions & 3 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ export class Dataset {
public readonly requestedVersion?: string,
public readonly publicationDate?: string,
public readonly nextMajorVersion?: string,
public readonly nextMinorVersion?: string
public readonly nextMinorVersion?: string,
public readonly requiresMajorVersionUpdate?: boolean
) {}

public checkIsLockedFromPublishing(userPersistentId: string): boolean {
Expand Down Expand Up @@ -480,7 +481,8 @@ export class Dataset {

public readonly requestedVersion?: string,
public readonly nextMajorVersionNumber?: string,
public readonly nextMinorVersionNumber?: string
public readonly nextMinorVersionNumber?: string,
public readonly requiresMajorVersionUpdate?: boolean
) {
this.withAlerts()
}
Expand Down Expand Up @@ -547,7 +549,8 @@ export class Dataset {
this.requestedVersion,
undefined,
this.nextMajorVersionNumber,
this.nextMinorVersionNumber
this.nextMinorVersionNumber,
this.requiresMajorVersionUpdate
)
}
}
Expand Down
48 changes: 48 additions & 0 deletions src/dataset/domain/models/DatasetVersionDiff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export interface DatasetVersionDiff {
oldVersion: VersionSummary
newVersion: VersionSummary
metadataChanges?: MetadataBlockDiff[]
filesAdded?: FileSummary[]
filesRemoved?: FileSummary[]
fileChanges?: FileDiff[]
filesReplaced?: FileReplacement[]
termsOfAccess?: FieldDiff[]
}

export interface FileSummary {
fileName: string
MD5: string
type: string
fileId: number
filePath: string
description: string
isRestricted: boolean
tags: string[]
categories: string[]
}

export interface VersionSummary {
versionNumber: string
lastUpdatedDate: string
}
export interface MetadataBlockDiff {
blockName: string
changed: FieldDiff[]
}

export interface FileDiff {
fileName: string
md5: string
fileId: number
changed: FieldDiff[]
}

export interface FileReplacement {
oldFile: FileSummary
newFile: FileSummary
}
export interface FieldDiff {
fieldName: string
oldValue: string
newValue: string
}
7 changes: 7 additions & 0 deletions src/dataset/domain/repositories/DatasetRepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Dataset, DatasetLock } from '../models/Dataset'
import { DatasetVersionDiff } from '../models/DatasetVersionDiff'
import { DatasetPaginationInfo } from '../models/DatasetPaginationInfo'
import { DatasetDTO } from '../useCases/DTOs/DatasetDTO'
import { DatasetsWithCount } from '../models/DatasetsWithCount'
Expand All @@ -8,6 +9,12 @@ export interface DatasetRepository {
getByPersistentId: (persistentId: string, version?: string) => Promise<Dataset | undefined>
getLocks(persistentId: string): Promise<DatasetLock[]>
getByPrivateUrlToken: (privateUrlToken: string) => Promise<Dataset | undefined>
getVersionDiff: (
persistentId: string,
oldVersion: string,
newVersion: string
) => Promise<DatasetVersionDiff>

create: (dataset: DatasetDTO, collectionId: string) => Promise<{ persistentId: string }>
updateMetadata: (datasetId: string | number, datasetDTO: DatasetDTO) => Promise<void>
getAllWithCount: (
Expand Down
15 changes: 15 additions & 0 deletions src/dataset/domain/useCases/getDatasetVersionDiff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DatasetRepository } from '../repositories/DatasetRepository'
import { DatasetVersionDiff } from '../models/DatasetVersionDiff'

export async function getDatasetVersionDiff(
datasetRepository: DatasetRepository,
persistentId: string,
oldVersion: string,
newVersion: string
): Promise<DatasetVersionDiff | undefined> {
return datasetRepository
.getVersionDiff(persistentId, oldVersion, newVersion)
.catch((error: Error) => {
throw new Error(error.message)
})
}
33 changes: 31 additions & 2 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
DatasetMetadataBlocks as JSDatasetMetadataBlocks,
DatasetMetadataFields as JSDatasetMetadataFields,
DatasetUserPermissions as JSDatasetPermissions,
DatasetVersionDiff as JSDatasetVersionDiff,
DvObjectOwnerNode as JSUpwardHierarchyNode
} from '@iqss/dataverse-client-javascript'
import { DatasetVersionDiff } from '../../domain/models/DatasetVersionDiff'
import {
Dataset,
DatasetDownloadUrls,
Expand Down Expand Up @@ -44,7 +46,8 @@ export class JSDatasetMapper {
requestedVersion?: string,
privateUrl?: PrivateUrl,
latestPublishedVersionMajorNumber?: number,
latestPublishedVersionMinorNumber?: number
latestPublishedVersionMinorNumber?: number,
datasetVersionDiff?: JSDatasetVersionDiff
): Dataset {
const version = JSDatasetVersionMapper.toVersion(
jsDataset.versionId,
Expand Down Expand Up @@ -87,7 +90,8 @@ export class JSDatasetMapper {
JSDatasetMapper.toNextMinorVersion(
latestPublishedVersionMajorNumber,
latestPublishedVersionMinorNumber
)
),
JSDatasetMapper.toRequiresMajorVersionUpdate(datasetVersionDiff)
).build()
}

Expand Down Expand Up @@ -116,6 +120,31 @@ export class JSDatasetMapper {
return nextMinorVersion
}

static toRequiresMajorVersionUpdate(
datasetVersionDiff: JSDatasetVersionDiff | undefined
): boolean {
if (datasetVersionDiff === undefined) {
return false
}
const required =
((datasetVersionDiff.filesAdded && datasetVersionDiff.filesAdded.length > 0) ||
(datasetVersionDiff.filesRemoved && datasetVersionDiff.filesRemoved.length > 0) ||
(datasetVersionDiff.filesReplaced && datasetVersionDiff.filesReplaced.length > 0)) ??
false
return required
}
static toDatasetVersionDiff(jsDatasetVersionDiff: JSDatasetVersionDiff): DatasetVersionDiff {
return {
oldVersion: jsDatasetVersionDiff.oldVersion,
newVersion: jsDatasetVersionDiff.newVersion,
metadataChanges: jsDatasetVersionDiff.metadataChanges,
filesAdded: jsDatasetVersionDiff.filesAdded,
filesRemoved: jsDatasetVersionDiff.filesRemoved,
fileChanges: jsDatasetVersionDiff.fileChanges,
filesReplaced: jsDatasetVersionDiff.filesReplaced,
termsOfAccess: jsDatasetVersionDiff.termsOfAccess
}
}
static toDatasetTitle(jsDatasetMetadataBlocks: JSDatasetMetadataBlocks): string {
return jsDatasetMetadataBlocks[0].fields.title
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DatasetRepository } from '../../domain/repositories/DatasetRepository'
import { Dataset, DatasetLock, DatasetNonNumericVersion } from '../../domain/models/Dataset'
import { DatasetVersionDiff } from '../../domain/models/DatasetVersionDiff'
import {
createDataset,
CreatedDatasetIdentifiers as JSDatasetIdentifiers,
Expand All @@ -10,6 +11,7 @@ import {
DatasetUserPermissions as JSDatasetPermissions,
DatasetVersionState,
FileDownloadSizeMode,
DatasetVersionDiff as JSDatasetVersionDiff,
getAllDatasetPreviews,
getDataset,
getDatasetCitation,
Expand All @@ -23,7 +25,8 @@ import {
ReadError,
updateDataset,
VersionUpdateType as JSVersionUpdateType,
WriteError
WriteError,
getDatasetVersionDiff
} from '@iqss/dataverse-client-javascript'
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'
import { DatasetPaginationInfo } from '../../domain/models/DatasetPaginationInfo'
Expand All @@ -46,6 +49,7 @@ interface IDatasetDetails {
jsDatasetFilesTotalArchivalDownloadSize: number
latestPublishedVersionMajorNumber?: number
latestPublishedVersionMinorNumber?: number
datasetVersionDiff?: JSDatasetVersionDiff
}

export class DatasetJSDataverseRepository implements DatasetRepository {
Expand All @@ -66,6 +70,18 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
}
})
}
getVersionDiff(
persistentId: string,
oldVersion: string,
newVersion: string
): Promise<DatasetVersionDiff> {
return getDatasetVersionDiff
.execute(persistentId, oldVersion, newVersion)
.then((jsDatasetVersionDiff) => {
return JSDatasetMapper.toDatasetVersionDiff(jsDatasetVersionDiff)
})
}

private async getLatestPublishedVersionNumbers(
datasetDetails: IDatasetDetails
): Promise<IDatasetDetails> {
Expand All @@ -82,6 +98,19 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
return datasetDetails
}

private async getVersionDiffDetails(datasetDetails: IDatasetDetails): Promise<IDatasetDetails> {
await this.getVersionDiff(
datasetDetails.jsDataset.persistentId,
DatasetNonNumericVersion.LATEST_PUBLISHED,
DatasetNonNumericVersion.DRAFT
).then((datasetVersionDiff) => {
datasetDetails.datasetVersionDiff = datasetVersionDiff
return datasetDetails
})

return datasetDetails
}

private async fetchDatasetDetails(
jsDataset: JSDataset,
version?: string
Expand Down Expand Up @@ -161,8 +190,11 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
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)
// numbers of the latest published version and the datasetVersionDiff,
// for the PublishDatasetModal component.
return this.getLatestPublishedVersionNumbers(datasetDetails).then((updatedDetails) =>
this.getVersionDiffDetails(updatedDetails)
)
} else {
return datasetDetails
}
Expand All @@ -179,7 +211,8 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
requestedVersion,
undefined,
datasetDetails.latestPublishedVersionMajorNumber,
datasetDetails.latestPublishedVersionMinorNumber
datasetDetails.latestPublishedVersionMinorNumber,
datasetDetails.datasetVersionDiff
)
})
.catch((error: ReadError) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function PublishDatasetMenu({
releasedVersionExists={dataset.version.someDatasetVersionHasBeenReleased}
nextMajorVersion={dataset.nextMajorVersion}
nextMinorVersion={dataset.nextMinorVersion}
requiresMajorVersionUpdate={dataset.requiresMajorVersionUpdate}
handleClose={() => setShowModal(false)}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
margin-bottom: 0;
color: $dv-warning-color;
}

.secondaryText {
color: $dv-subtext-color;
}
Loading

0 comments on commit 9e91afa

Please sign in to comment.