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

Fix/454 dataset page actions for draft #462

Merged
merged 9 commits into from
Sep 3, 2024
4 changes: 0 additions & 4 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ export enum DatasetNonNumericVersion {
export enum DatasetNonNumericVersionSearchParam {
DRAFT = 'DRAFT'
}
// TODO: Maybe add this to some routing related folder or file
export enum QueryParamsKeys {
VERSION = 'version'
}

export class DatasetVersionNumber {
constructor(public readonly majorNumber?: number, public readonly minorNumber?: number) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,11 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
.execute(persistentId, version, includeDeaccessioned)
.then((jsDataset) => this.fetchDatasetDetails(jsDataset, version))
.then((datasetDetails) => {
if (datasetDetails.jsDatasetPermissions.canEditDataset) {
return this.fetchDownloadSizes(persistentId, version).then((downloadSizes) => {
datasetDetails.jsDatasetFilesTotalOriginalDownloadSize = downloadSizes[0]
datasetDetails.jsDatasetFilesTotalArchivalDownloadSize = downloadSizes[1]
return datasetDetails
})
} else {
return this.fetchDownloadSizes(persistentId, version).then((downloadSizes) => {
datasetDetails.jsDatasetFilesTotalOriginalDownloadSize = downloadSizes[0]
datasetDetails.jsDatasetFilesTotalArchivalDownloadSize = downloadSizes[1]
return datasetDetails
}
})
})
.then((datasetDetails) => {
return JSDatasetMapper.toDataset(
Expand Down
5 changes: 5 additions & 0 deletions src/sections/Route.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ export const RouteWithParams = {
CREATE_COLLECTION: (ownerCollectionId?: string) =>
`/collections/${ownerCollectionId ?? 'root'}/create`
}

export enum QueryParamKey {
VERSION = 'version',
PERSISTENT_ID = 'persistentId'
}
2 changes: 1 addition & 1 deletion src/sections/collection/datasets-list/DatasetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function DatasetsList({ datasetRepository, page, collectionId }: Datasets
<PaginationResultsInfo paginationInfo={paginationInfo} />
</div>
{datasets.map((dataset) => (
<DatasetCard dataset={dataset} key={dataset.persistentId} />
<DatasetCard dataset={dataset} key={`${dataset.persistentId}-${dataset.version.id}`} />
))}
<PaginationControls
onPaginationInfoChange={setPaginationInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function DatasetsListWithInfiniteScroll({
<PaginationResultsInfo paginationInfo={paginationInfo} accumulated={accumulatedCount} />
</div>
{accumulatedDatasets.map((dataset) => (
<DatasetCard dataset={dataset} key={dataset.persistentId} />
<DatasetCard dataset={dataset} key={`${dataset.persistentId}-${dataset.version.id}`} />
))}
</>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/sections/dataset/Dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { DatasetAlerts } from './dataset-alerts/DatasetAlerts'
import { DatasetFilesScrollable } from './dataset-files/DatasetFilesScrollable'
import useCheckPublishCompleted from './useCheckPublishCompleted'
import useUpdateDatasetAlerts from './useUpdateDatasetAlerts'
import { Route } from '../Route.enum'
import { QueryParamKey, Route } from '../Route.enum'
import { MetadataBlockInfoRepository } from '../../metadata-block-info/domain/repositories/MetadataBlockInfoRepository'

interface DatasetProps {
Expand Down Expand Up @@ -60,7 +60,7 @@ export function Dataset({

useEffect(() => {
if (publishInProgress && publishCompleted && dataset) {
navigate(`${Route.DATASETS}?persistentId=${dataset.persistentId}`, {
navigate(`${Route.DATASETS}?${QueryParamKey.PERSISTENT_ID}=${dataset.persistentId}`, {
state: {},
replace: true
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export function AccessDatasetMenu({
}: AccessDatasetMenuProps) {
const { t } = useTranslation('dataset')

const flesToDownloadSizeIsZero =
fileDownloadSizes.map(({ value }) => value).reduce((acc, curr) => acc + curr, 0) === 0

if (
flesToDownloadSizeIsZero ||
!permissions.canDownloadFiles ||
(version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED &&
!permissions.canUpdateDataset)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import { Dataset } from '../../../../dataset/domain/models/Dataset'
import {
Dataset,
DatasetNonNumericVersionSearchParam,
DatasetPublishingStatus
} from '../../../../dataset/domain/models/Dataset'
import { DropdownButton, DropdownButtonItem } from '@iqss/dataverse-design-system'
import { EditDatasetPermissionsMenu } from './EditDatasetPermissionsMenu'
import { DeleteDatasetButton } from './DeleteDatasetButton'
import { DeaccessionDatasetButton } from './DeaccessionDatasetButton'
import { useNotImplementedModal } from '../../../not-implemented/NotImplementedModalContext'
import { useSession } from '../../../session/SessionContext'
import { Route } from '../../../Route.enum'
import { QueryParamKey, Route } from '../../../Route.enum'

interface EditDatasetMenuProps {
dataset: Dataset
Expand All @@ -29,12 +33,19 @@ export function EditDatasetMenu({ dataset }: EditDatasetMenuProps) {
const navigate = useNavigate()

const handleOnSelect = (eventKey: EditDatasetMenuItems | string | null) => {
const searchParams = new URLSearchParams()
searchParams.set(QueryParamKey.PERSISTENT_ID, dataset.persistentId)

if (dataset.version.publishingStatus === DatasetPublishingStatus.DRAFT) {
searchParams.set(QueryParamKey.VERSION, DatasetNonNumericVersionSearchParam.DRAFT)
}

if (eventKey === EditDatasetMenuItems.FILES_UPLOAD) {
navigate(`${Route.UPLOAD_DATASET_FILES}?persistentId=${dataset.persistentId}`)
navigate(`${Route.UPLOAD_DATASET_FILES}?${searchParams.toString()}`)
return
}
if (eventKey === EditDatasetMenuItems.METADATA) {
navigate(`${Route.EDIT_DATASET_METADATA}?persistentId=${dataset.persistentId}`)
navigate(`${Route.EDIT_DATASET_METADATA}?${searchParams.toString()}`)
return
}
showModal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { PlusLg } from 'react-bootstrap-icons'
import { Button } from '@iqss/dataverse-design-system'
import { useSession } from '../../../session/SessionContext'
import { useDataset } from '../../DatasetContext'
import { Route } from '../../../Route.enum'
import { QueryParamKey, Route } from '../../../Route.enum'
import {
DatasetNonNumericVersionSearchParam,
DatasetPublishingStatus
} from '../../../../dataset/domain/models/Dataset'
import styles from './DatasetUploadFilesButton.module.scss'

export function DatasetUploadFilesButton() {
Expand All @@ -18,7 +22,14 @@ export function DatasetUploadFilesButton() {
}

const handleClick = () => {
navigate(`${Route.UPLOAD_DATASET_FILES}?persistentId=${dataset.persistentId}`)
const searchParams = new URLSearchParams()
searchParams.set(QueryParamKey.PERSISTENT_ID, dataset.persistentId)

if (dataset.version.publishingStatus === DatasetPublishingStatus.DRAFT) {
searchParams.set(QueryParamKey.VERSION, DatasetNonNumericVersionSearchParam.DRAFT)
}

navigate(`${Route.UPLOAD_DATASET_FILES}?${searchParams.toString()}`)
}
g-saracca marked this conversation as resolved.
Show resolved Hide resolved

return (
Expand Down
7 changes: 3 additions & 4 deletions src/sections/dataset/publish-dataset/PublishDatasetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import { useSession } from '../../session/SessionContext'
import { License } from '../dataset-summary/License'
import {
DatasetNonNumericVersionSearchParam,
defaultLicense,
QueryParamsKeys
defaultLicense
} from '../../../dataset/domain/models/Dataset'
import { SubmissionStatus } from '../../shared/form/DatasetMetadataForm/useSubmitDataset'
import { usePublishDataset } from './usePublishDataset'
import { PublishDatasetHelpText } from './PublishDatasetHelpText'
import styles from './PublishDatasetModal.module.scss'
import { useNavigate } from 'react-router-dom'
import { Route } from '../../Route.enum'
import { QueryParamKey, Route } from '../../Route.enum'

interface PublishDatasetModalProps {
show: boolean
Expand Down Expand Up @@ -52,7 +51,7 @@ export function PublishDatasetModal({

function onPublishSucceed() {
navigate(
`${Route.DATASETS}?persistentId=${persistentId}&${QueryParamsKeys.VERSION}=${DatasetNonNumericVersionSearchParam.DRAFT}`,
`${Route.DATASETS}?${QueryParamKey.PERSISTENT_ID}=${persistentId}&${QueryParamKey.VERSION}=${DatasetNonNumericVersionSearchParam.DRAFT}`,
{
state: { publishInProgress: true },
replace: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EditDatasetMetadata } from './EditDatasetMetadata'
import { DatasetProvider } from '../dataset/DatasetProvider'
import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository'
import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository'
import { searchParamVersionToDomainVersion } from '../../Router'

const datasetRepository = new DatasetJSDataverseRepository()
const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository()
Expand All @@ -17,9 +18,13 @@ export class EditDatasetMetadataFactory {
function EditDatasetMetadataWithParams() {
const [searchParams] = useSearchParams()
const persistentId = searchParams.get('persistentId') ?? undefined
const searchParamVersion = searchParams.get('version') ?? undefined
const version = searchParamVersionToDomainVersion(searchParamVersion)

return (
<DatasetProvider repository={datasetRepository} searchParams={{ persistentId: persistentId }}>
<DatasetProvider
repository={datasetRepository}
searchParams={{ persistentId: persistentId, version: version }}>
<EditDatasetMetadata
datasetRepository={datasetRepository}
metadataBlockInfoRepository={metadataBlockInfoRepository}
Expand Down
11 changes: 4 additions & 7 deletions src/sections/shared/form/DatasetMetadataForm/useSubmitDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import { updateDatasetMetadata } from '../../../../dataset/domain/useCases/updat
import { MetadataFieldsHelper, type DatasetMetadataFormValues } from './MetadataFieldsHelper'
import { getValidationFailedFieldError } from '../../../../metadata-block-info/domain/models/fieldValidations'
import { type DatasetMetadataFormMode } from '.'
import { Route } from '../../../Route.enum'
import {
DatasetNonNumericVersionSearchParam,
QueryParamsKeys
} from '../../../../dataset/domain/models/Dataset'
import { QueryParamKey, Route } from '../../../Route.enum'
import { DatasetNonNumericVersionSearchParam } from '../../../../dataset/domain/models/Dataset'

export enum SubmissionStatus {
NotSubmitted = 'NotSubmitted',
Expand Down Expand Up @@ -65,7 +62,7 @@ export function useSubmitDataset(
setSubmitError(null)
setSubmissionStatus(SubmissionStatus.SubmitComplete)
navigate(
`${Route.DATASETS}?persistentId=${persistentId}&${QueryParamsKeys.VERSION}=${DatasetNonNumericVersionSearchParam.DRAFT}`,
`${Route.DATASETS}?${QueryParamKey.PERSISTENT_ID}=${persistentId}&${QueryParamKey.VERSION}=${DatasetNonNumericVersionSearchParam.DRAFT}`,
{
state: { created: true }
}
Expand Down Expand Up @@ -95,7 +92,7 @@ export function useSubmitDataset(
setSubmitError(null)
setSubmissionStatus(SubmissionStatus.SubmitComplete)
navigate(
`${Route.DATASETS}?persistentId=${currentEditedDatasetPersistentID}&${QueryParamsKeys.VERSION}=${DatasetNonNumericVersionSearchParam.DRAFT}`,
`${Route.DATASETS}?${QueryParamKey.PERSISTENT_ID}=${currentEditedDatasetPersistentID}&${QueryParamKey.VERSION}=${DatasetNonNumericVersionSearchParam.DRAFT}`,
{
state: { metadataUpdated: true }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repos
import { FileJSDataverseRepository } from '../../files/infrastructure/FileJSDataverseRepository'
import { DatasetProvider } from '../dataset/DatasetProvider'
import { UploadDatasetFiles } from './UploadDatasetFiles'
import { searchParamVersionToDomainVersion } from '../../Router'

const datasetRepository = new DatasetJSDataverseRepository()
const fileRepository = new FileJSDataverseRepository()
Expand All @@ -17,9 +18,13 @@ export class UploadDatasetFilesFactory {
function UploadDatasetFilesWithSearchParams() {
const [searchParams] = useSearchParams()
const persistentId = searchParams.get('persistentId') ?? undefined
const searchParamVersion = searchParams.get('version') ?? undefined
const version = searchParamVersionToDomainVersion(searchParamVersion)

return (
<DatasetProvider repository={datasetRepository} searchParams={{ persistentId: persistentId }}>
<DatasetProvider
repository={datasetRepository}
searchParams={{ persistentId: persistentId, version: version }}>
<UploadDatasetFiles fileRepository={fileRepository} />
</DatasetProvider>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { DatasetRepository } from '../../../../src/dataset/domain/repositories/D
import { MetadataBlockInfoRepository } from '../../../../src/metadata-block-info/domain/repositories/MetadataBlockInfoRepository'
import { MetadataBlockInfoMother } from '../../metadata-block-info/domain/models/MetadataBlockInfoMother'
import { NotImplementedModalProvider } from '../../../../src/sections/not-implemented/NotImplementedModalProvider'
import { FileRepository } from '../../../../src/files/domain/repositories/FileRepository'

const datasetRepository: DatasetRepository = {} as DatasetRepository
const metadataBlockInfoRepository: MetadataBlockInfoRepository = {} as MetadataBlockInfoRepository
const fileRepository: FileRepository = {} as FileRepository

const collectionMetadataBlocksInfo =
MetadataBlockInfoMother.getByCollectionIdDisplayedOnCreateTrue()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { DatasetRepository } from '../../../../../src/dataset/domain/repositories/DatasetRepository'
import { FileSizeUnit } from '../../../../../src/files/domain/models/FileMetadata'
import { DatasetActionButtons } from '../../../../../src/sections/dataset/dataset-action-buttons/DatasetActionButtons'
import {
DatasetFileDownloadSizeMother,
DatasetMother,
DatasetPermissionsMother,
DatasetVersionMother
} from '../../../dataset/domain/models/DatasetMother'

const datasetRepository: DatasetRepository = {} as DatasetRepository

describe('DatasetActionButtons', () => {
it('renders the DatasetActionButtons with the Publish button', () => {
const dataset = DatasetMother.create({
version: DatasetVersionMother.createDraftAsLatestVersionWithSomeVersionHasBeenReleased(),
permissions: DatasetPermissionsMother.createWithAllAllowed()
permissions: DatasetPermissionsMother.createWithAllAllowed(),
fileDownloadSizes: [
DatasetFileDownloadSizeMother.createOriginal({ value: 2000, unit: FileSizeUnit.BYTES })
]
})

cy.mountAuthenticated(<DatasetActionButtons dataset={dataset} />)
cy.mountAuthenticated(
<DatasetActionButtons dataset={dataset} datasetRepository={datasetRepository} />
)

cy.findByRole('group', { name: 'Dataset Action Buttons' }).should('exist')
cy.findByRole('button', { name: 'Access Dataset' }).should('exist')
Expand All @@ -28,10 +38,15 @@ describe('DatasetActionButtons', () => {
canDownloadFiles: true,
canUpdateDataset: true,
canPublishDataset: false
})
}),
fileDownloadSizes: [
DatasetFileDownloadSizeMother.createOriginal({ value: 2000, unit: FileSizeUnit.BYTES })
]
})

cy.mountAuthenticated(<DatasetActionButtons dataset={dataset} />)
cy.mountAuthenticated(
<DatasetActionButtons dataset={dataset} datasetRepository={datasetRepository} />
)

cy.findByRole('group', { name: 'Dataset Action Buttons' }).should('exist')
cy.findByRole('button', { name: 'Access Dataset' }).should('exist')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,26 @@ describe('AccessDatasetMenu', () => {
.should('exist')
.should('have.attr', 'href', downloadUrls.archival)
})

it('does not render the AccessDatasetMenu if the file download sizes are zero', () => {
const version = DatasetVersionMother.createReleased()
const permissions = DatasetPermissionsMother.createWithFilesDownloadAllowed()
const fileDownloadSizes = [
DatasetFileDownloadSizeMother.createOriginal({ value: 0, unit: FileSizeUnit.BYTES }),
DatasetFileDownloadSizeMother.createArchival({
value: 0,
unit: FileSizeUnit.BYTES
})
]
cy.customMount(
<AccessDatasetMenu
fileDownloadSizes={fileDownloadSizes}
hasOneTabularFileAtLeast={true}
version={version}
permissions={permissions}
downloadUrls={downloadUrls}
/>
)
cy.findByRole('button', { name: 'Access Dataset' }).should('not.exist')
})
})
Loading