Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions public/locales/en/createDataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@
"label": "Dataset Template",
"description": "The dataset template which prepopulates info into the form automatically.",
"helpText": "Changing the template will clear any fields you may have entered data into."
},
"datasetType": {
"label": "Dataset Type",
"description": "The type of dataset you are creating.",
"helpText": "Changing the dataset type will clear any fields you may have entered data into.",
"placeholder": "Select a dataset type",
"toggleMenu": "Toggle dataset types options menu"
}
}
5 changes: 4 additions & 1 deletion public/locales/en/editDatasetMetadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"label": "Host Collection",
"description": "The collection which contains this data."
},
"metadata": "Metadata"
"metadata": "Metadata",
"datasetType": {
"label": "Dataset Type"
}
}
56 changes: 56 additions & 0 deletions src/dataset/domain/hooks/useGetAvailableDatasetTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useCallback, useEffect, useState } from 'react'
import { ReadError } from '@iqss/dataverse-client-javascript'
import { JSDataverseReadErrorHandler } from '@/shared/helpers/JSDataverseReadErrorHandler'
import { DatasetRepository } from '../repositories/DatasetRepository'
import { getAvailableDatasetTypes } from '../useCases/getAvailableDatasetTypes'
import { DatasetType } from '../models/DatasetType'

interface useGetAvailableDatasetTypesProps {
datasetRepository: DatasetRepository
autoFetch?: boolean
}

export const useGetAvailableDatasetTypes = ({
datasetRepository,
autoFetch = true
}: useGetAvailableDatasetTypesProps) => {
const [datasetTypes, setDatasetTypes] = useState<DatasetType[]>([])
const [isLoadingDatasetTypes, setIsLoadingDatasetTypes] = useState<boolean>(autoFetch)
const [errorGetDatasetTypes, setErrorGetDatasetTypes] = useState<string | null>(null)

const fetchDatasetTypes = useCallback(async () => {
setIsLoadingDatasetTypes(true)
setErrorGetDatasetTypes(null)

try {
const response: DatasetType[] = await getAvailableDatasetTypes(datasetRepository)

setDatasetTypes(response)
} catch (err) {
if (err instanceof ReadError) {
const error = new JSDataverseReadErrorHandler(err)
const formattedError =
error.getReasonWithoutStatusCode() ?? /* istanbul ignore next */ error.getErrorMessage()

setErrorGetDatasetTypes(formattedError)
} else {
setErrorGetDatasetTypes('Something went wrong getting the dataset types. Try again later.')
}
} finally {
setIsLoadingDatasetTypes(false)
}
}, [datasetRepository])

useEffect(() => {
if (autoFetch) {
void fetchDatasetTypes()
}
}, [autoFetch, fetchDatasetTypes])

return {
datasetTypes,
isLoadingDatasetTypes,
errorGetDatasetTypes,
fetchDatasetTypes
}
}
9 changes: 6 additions & 3 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ export class Dataset {
public readonly nextMinorVersion?: string,
public readonly requiresMajorVersionUpdate?: boolean,
public readonly fileStore?: string,
public readonly guestbookId?: number
public readonly guestbookId?: number,
public readonly datasetType?: string
) {}

public checkIsLockedFromPublishing(userPersistentId: string): boolean {
Expand Down Expand Up @@ -535,7 +536,8 @@ export class Dataset {
public readonly nextMinorVersionNumber?: string,
public readonly requiresMajorVersionUpdate?: boolean,
public readonly fileStore?: string,
public readonly guestbookId?: number
public readonly guestbookId?: number,
public readonly datasetType?: string
) {
this.withAlerts()
}
Expand Down Expand Up @@ -608,7 +610,8 @@ export class Dataset {
this.nextMinorVersionNumber,
this.requiresMajorVersionUpdate,
this.fileStore,
this.guestbookId
this.guestbookId,
this.datasetType
)
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/dataset/domain/models/DatasetType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface DatasetType {
id: number
name: string
displayName: string
linkedMetadataBlocks?: string[]
availableLicenses?: string[]
description?: string
}
8 changes: 7 additions & 1 deletion src/dataset/domain/repositories/DatasetRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DatasetLicenseUpdateRequest } from '../models/DatasetLicenseUpdateReque
import { CollectionSummary } from '@/collection/domain/models/CollectionSummary'
import { DatasetVersionPaginationInfo } from '../models/DatasetVersionPaginationInfo'
import { DatasetUploadLimits } from '../models/DatasetUploadLimits'
import { DatasetType } from '../models/DatasetType'

export interface DatasetRepository {
getByPersistentId: (
Expand All @@ -29,7 +30,11 @@ export interface DatasetRepository {
includeDeaccessioned: boolean
) => Promise<DatasetVersionDiff>

create: (dataset: DatasetDTO, collectionId: string) => Promise<{ persistentId: string }>
create: (
dataset: DatasetDTO,
collectionId: string,
datasetType?: DatasetType
) => Promise<{ persistentId: string }>
updateMetadata: (
datasetId: string | number,
datasetDTO: DatasetDTO,
Expand Down Expand Up @@ -70,4 +75,5 @@ export interface DatasetRepository {
unlink(datasetId: string | number, collectionIdOrAlias: string | number): Promise<void>
getDatasetLinkedCollections: (datasetId: string | number) => Promise<CollectionSummary[]>
getDatasetUploadLimits: (datasetId: string | number) => Promise<DatasetUploadLimits>
getAvailableDatasetTypes: () => Promise<DatasetType[]>
}
5 changes: 3 additions & 2 deletions src/dataset/domain/useCases/createDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { DatasetDTO } from './DTOs/DatasetDTO'
export function createDataset(
datasetRepository: DatasetRepository,
dataset: DatasetDTO,
collectionId: string
collectionId: string,
datasetType?: string
): Promise<{ persistentId: string }> {
return datasetRepository.create(dataset, collectionId).catch((error: Error) => {
return datasetRepository.create(dataset, collectionId, datasetType).catch((error: Error) => {
throw new Error(error.message)
})
}
8 changes: 8 additions & 0 deletions src/dataset/domain/useCases/getAvailableDatasetTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { DatasetRepository } from '../repositories/DatasetRepository'
import { DatasetType } from '@iqss/dataverse-client-javascript'

export function getAvailableDatasetTypes(
datasetRepository: DatasetRepository
): Promise<DatasetType[]> {
return datasetRepository.getAvailableDatasetTypes()
}
6 changes: 4 additions & 2 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export class JSDatasetMapper {
latestPublishedVersionMajorNumber?: number,
latestPublishedVersionMinorNumber?: number,
datasetVersionDiff?: JSDatasetVersionDiff,
fileStore?: string
fileStore?: string,
datasetType?: string
): Dataset {
const version = JSDatasetVersionMapper.toVersion(
jsDataset.versionId,
Expand Down Expand Up @@ -101,7 +102,8 @@ export class JSDatasetMapper {
),
JSDatasetMapper.toRequiresMajorVersionUpdate(datasetVersionDiff),
fileStore,
jsDataset.guestbookId as number
jsDataset.guestbookId as number,
datasetType
).build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import {
getDatasetLinkedCollections,
updateTermsOfAccess,
updateDatasetLicense,
getDatasetUploadLimits
getDatasetUploadLimits,
DatasetType,
getDatasetAvailableDatasetTypes
} from '@iqss/dataverse-client-javascript'
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'
import { DatasetPaginationInfo } from '../../domain/models/DatasetPaginationInfo'
Expand Down Expand Up @@ -269,7 +271,8 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
datasetDetails.latestPublishedVersionMajorNumber,
datasetDetails.latestPublishedVersionMinorNumber,
datasetDetails.datasetVersionDiff,
datasetDetails.fileStore
datasetDetails.fileStore,
datasetDetails.datasetType
)
})
.catch((error: ReadError) => {
Expand Down Expand Up @@ -327,9 +330,13 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
})
}

create(dataset: DatasetDTO, collectionId: string): Promise<{ persistentId: string }> {
create(
dataset: DatasetDTO,
collectionId: string,
datasetType?: string
): Promise<{ persistentId: string }> {
return createDataset
.execute(DatasetDTOMapper.toJSDatasetDTO(dataset), collectionId)
.execute(DatasetDTOMapper.toJSDatasetDTO(dataset), collectionId, datasetType)
.then((jsDatasetIdentifiers: JSDatasetIdentifiers) => ({
persistentId: jsDatasetIdentifiers.persistentId
}))
Expand Down Expand Up @@ -431,6 +438,10 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
return getDatasetLinkedCollections.execute(datasetId)
}

getAvailableDatasetTypes: () => Promise<DatasetType[]> = () => {
return getDatasetAvailableDatasetTypes.execute()
}

/*
TODO: This is a temporary solution as this use case doesn't exist in js-dataverse yet and the API should also return the file store type rather than name only.
After https://github.com/IQSS/dataverse/issues/11695 is implemented, create a js-dataverse use case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ export interface MetadataBlockInfoRepository {
getByName: (name: string) => Promise<MetadataBlockInfoDisplayFormat | undefined>
getAll: () => Promise<MetadataBlockInfo[]>
getDisplayedOnCreateByCollectionId: (
collectionId: number | string
collectionId: number | string,
datasetType?: string
) => Promise<MetadataBlockInfo[]>
getByCollectionId: (
collectionId: number | string,
datasetType?: string
) => Promise<MetadataBlockInfo[]>
getByCollectionId: (collectionId: number | string) => Promise<MetadataBlockInfo[]>
getAllFacetableMetadataFields: () => Promise<MetadataField[]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { MetadataBlockInfoRepository } from '../repositories/MetadataBlockInfoRe

export async function getDisplayedOnCreateMetadataBlockInfoByCollectionId(
metadataBlockInfoRepository: MetadataBlockInfoRepository,
collectionId: number | string
collectionId: number | string,
datasetType?: string
): Promise<MetadataBlockInfo[]> {
return metadataBlockInfoRepository
.getDisplayedOnCreateByCollectionId(collectionId)
.getDisplayedOnCreateByCollectionId(collectionId, datasetType)
.catch((error: Error) => {
throw new Error(error.message)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { MetadataBlockInfoRepository } from '../repositories/MetadataBlockInfoRe

export async function getMetadataBlockInfoByCollectionId(
metadataBlockInfoRepository: MetadataBlockInfoRepository,
collectionId: number | string
collectionId: number | string,
onlyDisplayedOnCreate?: boolean,
datasetType?: string
): Promise<MetadataBlockInfo[]> {
return metadataBlockInfoRepository.getByCollectionId(collectionId).catch((error: Error) => {
throw new Error(error.message)
})
}
return metadataBlockInfoRepository
.getByCollectionId(collectionId, onlyDisplayedOnCreate, datasetType)
.catch((error: Error) => {
throw new Error(error.message)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ export class MetadataBlockInfoJSDataverseRepository implements MetadataBlockInfo
})
}

getByCollectionId(collectionIdOrAlias: number | string): Promise<MetadataBlockInfo[]> {
getByCollectionId(
collectionIdOrAlias: number | string,
onlyDisplayedOnCreate?: boolean,
datasetType?: string
): Promise<MetadataBlockInfo[]> {
return getCollectionMetadataBlocks
.execute(collectionIdOrAlias)
.execute(collectionIdOrAlias, onlyDisplayedOnCreate, datasetType)
.then((metadataBlocks: MetadataBlockInfo[]) => {
return metadataBlocks
})
Expand All @@ -49,12 +53,23 @@ export class MetadataBlockInfoJSDataverseRepository implements MetadataBlockInfo
}

getDisplayedOnCreateByCollectionId(
collectionIdOrAlias: number | string
collectionIdOrAlias: number | string,
datasetType?: string
): Promise<MetadataBlockInfo[]> {
return getCollectionMetadataBlocks
.execute(collectionIdOrAlias, true)
.execute(collectionIdOrAlias, true, datasetType)
.then((metadataBlocks: MetadataBlockInfo[]) => {
return metadataBlocks
const metadataBlocksWithFields: MetadataBlockInfo[] = []
metadataBlocks.forEach((block) => {
const numFields = Object.keys(block.metadataFields).length
// numFields can be zero if you pass a datasetType that's linked to
// a metadata block that doesn't have any fields set to displayOnCreate.
// See https://github.com/IQSS/dataverse/blob/v6.7.1/src/test/java/edu/harvard/iq/dataverse/api/DatasetTypesIT.java#L512
if (numFields > 0) {
metadataBlocksWithFields.push(block)
}
})
return metadataBlocksWithFields
})
.catch((error: ReadError) => {
throw new Error(error.message)
Expand Down
1 change: 1 addition & 0 deletions src/sections/Route.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export enum QueryParamKey {
TAB = 'tab',
FILE_ID = 'id',
DATASET_VERSION = 'datasetVersion',
DATASET_TYPE = 'datasetType',
REFERRER = 'referrer',
AUTH_STATE = 'state',
VALID_TOKEN_BUT_NOT_LINKED_ACCOUNT = 'validTokenButNotLinkedAccount',
Expand Down
Loading
Loading