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

Feature/492 publish dataset with compare versions #551

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@faker-js/faker": "7.6.0",
"@iqss/dataverse-client-javascript": "2.0.0-alpha.4",
"@iqss/dataverse-client-javascript": "2.0.0-pr220.5174e64",
"@iqss/dataverse-design-system": "*",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tanstack/react-table": "8.9.2",
Expand Down
10 changes: 7 additions & 3 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,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
21 changes: 19 additions & 2 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DatasetMetadataBlocks as JSDatasetMetadataBlocks,
DatasetMetadataFields as JSDatasetMetadataFields,
DatasetUserPermissions as JSDatasetPermissions,
DatasetVersionDiff as JSDatasetVersionDiff,
DvObjectOwnerNode as JSUpwardHierarchyNode
} from '@iqss/dataverse-client-javascript'
import {
Expand Down Expand Up @@ -44,7 +45,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 +89,8 @@ export class JSDatasetMapper {
JSDatasetMapper.toNextMinorVersion(
latestPublishedVersionMajorNumber,
latestPublishedVersionMinorNumber
)
),
JSDatasetMapper.toRequiresMajorVersionUpdate(datasetVersionDiff)
).build()
}

Expand Down Expand Up @@ -116,6 +119,20 @@ 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 toDatasetTitle(jsDatasetMetadataBlocks: JSDatasetMetadataBlocks): string {
return jsDatasetMetadataBlocks[0].fields.title
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DatasetUserPermissions as JSDatasetPermissions,
DatasetVersionState,
FileDownloadSizeMode,
DatasetVersionDiff as JSDatasetVersionDiff,
getAllDatasetPreviews,
getDataset,
getDatasetCitation,
Expand All @@ -23,7 +24,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 +48,7 @@ interface IDatasetDetails {
jsDatasetFilesTotalArchivalDownloadSize: number
latestPublishedVersionMajorNumber?: number
latestPublishedVersionMinorNumber?: number
datasetVersionDiff?: JSDatasetVersionDiff
}

export class DatasetJSDataverseRepository implements DatasetRepository {
Expand Down Expand Up @@ -82,6 +85,21 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
return datasetDetails
}

private async getVersionDiffDetails(datasetDetails: IDatasetDetails): Promise<IDatasetDetails> {
await getDatasetVersionDiff
.execute(
datasetDetails.jsDataset.persistentId,
DatasetNonNumericVersion.LATEST_PUBLISHED,
DatasetNonNumericVersion.DRAFT
ekraffmiller marked this conversation as resolved.
Show resolved Hide resolved
)
.then((datasetVersionDiff) => {
datasetDetails.datasetVersionDiff = datasetVersionDiff
return datasetDetails
})

return datasetDetails
}

private async fetchDatasetDetails(
jsDataset: JSDataset,
version?: string
Expand Down Expand Up @@ -161,8 +179,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)
)
g-saracca marked this conversation as resolved.
Show resolved Hide resolved
} else {
return datasetDetails
}
Expand All @@ -179,7 +200,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;
}
89 changes: 64 additions & 25 deletions src/sections/dataset/publish-dataset/PublishDatasetHelpText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,89 @@ import { RouteWithParams } from '@/sections/Route.enum'
import { Link } from 'react-router-dom'
import { Stack } from '@iqss/dataverse-design-system'
import styles from './PublishDatasetHelpText.module.scss'
import { TFunction } from 'i18next'

interface PublishDatasetHelpTextProps {
releasedVersionExists: boolean
parentCollectionIsReleased: boolean | undefined
nextMajorVersion: string
parentCollectionIsReleased: boolean
parentCollectionName: string
parentCollectionId: string
requiresMajorVersionUpdate: boolean
}

function getWarningTextKey(
function renderWarningText(
t: TFunction,
releasedVersionExists: boolean,
parentCollectionIsReleased: boolean | undefined
): string {
if (!releasedVersionExists) {
if (!parentCollectionIsReleased) {
return 'publish.releaseCollectionQuestion'
} else return 'publish.draftQuestion'
}
return 'publish.previouslyReleasedQuestion'
parentCollectionIsReleased: boolean,
parentCollectionName: string,
parentCollectionId: string
) {
return (
<p className={styles.warningText}>
{!releasedVersionExists && parentCollectionIsReleased && <>{t('publish.draftQuestion')}</>}
{!releasedVersionExists && !parentCollectionIsReleased && (
<Trans
t={t}
i18nKey={'publish.releaseCollectionQuestion'}
values={{ parentCollectionName }}
components={{ a: <Link to={RouteWithParams.COLLECTIONS(parentCollectionId)} /> }}
/>
)}
{releasedVersionExists && <>{t('publish.previouslyReleasedQuestion')}</>}
</p>
)
}
function renderSubText(
t: TFunction,
releasedVersionExists: boolean,
requiresMajorVersionUpdate: boolean,
nextMajorVersion: string,
parentCollectionIsReleased: boolean
) {
return (
<p className={styles.secondaryText}>
{!releasedVersionExists && !parentCollectionIsReleased && (
<>{t('publish.releaseCollectionSubtext')}</>
)}
{!releasedVersionExists && parentCollectionIsReleased && <>{t('publish.draftSubtext')}</>}
{releasedVersionExists && !requiresMajorVersionUpdate && (
<>{t('publish.previouslyReleasedSubtext')}</>
)}
{releasedVersionExists && requiresMajorVersionUpdate && (
<>{t('publish.requiresMajorReleaseSubtext', { versionNumber: nextMajorVersion })}</>
)}
</p>
)
}

export function PublishDatasetHelpText({
releasedVersionExists,
nextMajorVersion,
parentCollectionIsReleased,
parentCollectionName,
parentCollectionId
parentCollectionId,
requiresMajorVersionUpdate
}: PublishDatasetHelpTextProps) {
const { t } = useTranslation('dataset')
const warningText = getWarningTextKey(releasedVersionExists, parentCollectionIsReleased)

return (
<Stack direction="vertical">
<p className={styles.warningText}>
{!parentCollectionIsReleased ? (
<Trans
t={t}
i18nKey={warningText}
values={{ parentCollectionName }}
components={{ a: <Link to={RouteWithParams.COLLECTIONS(parentCollectionId)} /> }}
/>
) : (
<>{t(warningText)}</>
)}
</p>
<p>{t('publish.termsText')}</p>
{renderWarningText(
t,
releasedVersionExists,
parentCollectionIsReleased,
parentCollectionName,
parentCollectionId
)}

{renderSubText(
t,
releasedVersionExists,
requiresMajorVersionUpdate,
nextMajorVersion,
parentCollectionIsReleased
)}
</Stack>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
.errorText {
color: $dv-danger-color;
}

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