Skip to content
Open
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
14 changes: 7 additions & 7 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 @@ -18,7 +18,7 @@
"@dnd-kit/sortable": "8.0.0",
"@dnd-kit/utilities": "3.2.2",
"@faker-js/faker": "7.6.0",
"@iqss/dataverse-client-javascript": "2.0.0-alpha.67",
"@iqss/dataverse-client-javascript": "2.0.0-alpha.75",
"@iqss/dataverse-design-system": "*",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tanstack/react-table": "8.9.2",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/header.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"addData": "Add Data",
"newCollection": "New Collection",
"newDataset": "New Dataset",
"newReview": "New Review",
"accountInfo": "Account Information",
"apiToken": "API Token",
"myData": "My Data"
Expand Down
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 @@ -430,7 +430,8 @@ export class Dataset {
public readonly nextMajorVersion?: string,
public readonly nextMinorVersion?: string,
public readonly requiresMajorVersionUpdate?: boolean,
public readonly fileStore?: string
public readonly fileStore?: string,
public readonly datasetType?: string
) {}

public checkIsLockedFromPublishing(userPersistentId: string): boolean {
Expand Down Expand Up @@ -525,7 +526,8 @@ export class Dataset {
public readonly nextMajorVersionNumber?: string,
public readonly nextMinorVersionNumber?: string,
public readonly requiresMajorVersionUpdate?: boolean,
public readonly fileStore?: string
public readonly fileStore?: string,
public readonly datasetType?: string
) {
this.withAlerts()
}
Expand Down Expand Up @@ -597,7 +599,8 @@ export class Dataset {
this.nextMajorVersionNumber,
this.nextMinorVersionNumber,
this.requiresMajorVersionUpdate,
this.fileStore
this.fileStore,
this.datasetType
)
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/dataset/domain/models/DatasetType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface DatasetType {
id?: number
name: string
linkedMetadataBlocks?: string[]
availableLicenses?: 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 @@ -9,6 +9,7 @@ import { DatasetDeaccessionDTO } from '../useCases/DTOs/DatasetDTO'
import { DatasetDownloadCount } from '../models/DatasetDownloadCount'
import { FormattedCitation, CitationFormat } from '../models/DatasetCitation'
import { DatasetTemplate } from '../models/DatasetTemplate'
import { DatasetType } from '../models/DatasetType'

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

create: (dataset: DatasetDTO, collectionId: string) => Promise<{ persistentId: string }>
create: (
dataset: DatasetDTO,
collectionId: string,
datasetType?: string
) => Promise<{ persistentId: string }>
updateMetadata: (
datasetId: string | number,
datasetDTO: DatasetDTO,
Expand Down Expand Up @@ -55,5 +60,6 @@ export interface DatasetRepository {
version: string,
format: CitationFormat
) => Promise<FormattedCitation>
getAvailableDatasetTypes: () => Promise<DatasetType[]>
getTemplates: (collectionIdOrAlias: number | string) => Promise<DatasetTemplate[]>
}
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 @@ -99,7 +100,8 @@ export class JSDatasetMapper {
latestPublishedVersionMinorNumber
),
JSDatasetMapper.toRequiresMajorVersionUpdate(datasetVersionDiff),
fileStore
fileStore,
datasetType
).build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import {
deleteDatasetDraft,
getDatasetCitationInOtherFormats,
getDatasetAvailableCategories,
getDatasetTemplates
getDatasetTemplates,
getDatasetAvailableDatasetTypes,
DatasetType
} from '@iqss/dataverse-client-javascript'
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'
import { DatasetPaginationInfo } from '../../domain/models/DatasetPaginationInfo'
Expand Down Expand Up @@ -254,7 +256,8 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
datasetDetails.latestPublishedVersionMajorNumber,
datasetDetails.latestPublishedVersionMinorNumber,
datasetDetails.datasetVersionDiff,
datasetDetails.fileStore
datasetDetails.fileStore,
datasetDetails.jsDataset.datasetType
)
})
.catch((error: ReadError) => {
Expand Down Expand Up @@ -312,9 +315,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 @@ -397,6 +404,9 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
getAvailableCategories(datasetId: string | number): Promise<string[]> {
return getDatasetAvailableCategories.execute(datasetId)
}
getAvailableDatasetTypes(): Promise<DatasetType[]> {
return getDatasetAvailableDatasetTypes.execute()
}

getTemplates(collectionIdOrAlias: number | string): Promise<DatasetTemplate[]> {
return getDatasetTemplates.execute(collectionIdOrAlias)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ 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,
onlyDisplayedOnCreate?: boolean,
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 @@ -79,6 +79,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