Skip to content

Commit

Permalink
Added: type property to different collection item previews
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed Sep 17, 2024
1 parent 0f66fb4 commit 746affb
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/collections/domain/models/CollectionItemType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum CollectionItemType {
FILE = 'file',
DATASET = 'dataset',
COLLECTION = 'collection'
}
2 changes: 2 additions & 0 deletions src/collections/domain/models/CollectionPreview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { PublicationStatus } from '../../../core/domain/models/PublicationStatus'
import { CollectionItemType } from './CollectionItemType'

export interface CollectionPreview {
type: CollectionItemType.COLLECTION
name: string
parentName: string
alias: string
Expand Down
8 changes: 2 additions & 6 deletions src/collections/domain/models/CollectionSearchCriteria.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CollectionItemType } from './CollectionItemType'

export class CollectionSearchCriteria {
constructor(
public readonly searchText?: string,
Expand All @@ -12,9 +14,3 @@ export class CollectionSearchCriteria {
return new CollectionSearchCriteria(this.searchText, itemTypes)
}
}

export enum CollectionItemType {
FILE = 'file',
DATASET = 'dataset',
COLLECTION = 'dataverse'
}
6 changes: 2 additions & 4 deletions src/collections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@ export { CollectionFacet } from './domain/models/CollectionFacet'
export { CollectionUserPermissions } from './domain/models/CollectionUserPermissions'
export { CollectionDTO, CollectionInputLevelDTO } from './domain/dtos/CollectionDTO'
export { CollectionPreview } from './domain/models/CollectionPreview'
export {
CollectionSearchCriteria,
CollectionItemType
} from './domain/models/CollectionSearchCriteria'
export { CollectionItemType } from './domain/models/CollectionItemType'
export { CollectionSearchCriteria } from './domain/models/CollectionSearchCriteria'
13 changes: 8 additions & 5 deletions src/collections/infra/repositories/CollectionsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import { CollectionFacet } from '../../domain/models/CollectionFacet'
import { CollectionUserPermissions } from '../../domain/models/CollectionUserPermissions'
import { transformCollectionUserPermissionsResponseToCollectionUserPermissions } from './transformers/collectionUserPermissionsTransformers'
import { CollectionItemSubset } from '../../domain/models/CollectionItemSubset'
import {
CollectionItemType,
CollectionSearchCriteria
} from '../../domain/models/CollectionSearchCriteria'
import { CollectionSearchCriteria } from '../../domain/models/CollectionSearchCriteria'
import { CollectionItemType } from '../../domain/models/CollectionItemType'

export interface NewCollectionRequestPayload {
alias: string
Expand Down Expand Up @@ -170,8 +168,13 @@ export class CollectionsRepository extends ApiRepository implements ICollections

if (collectionSearchCriteria?.itemTypes) {
const itemTypesQueryString = collectionSearchCriteria.itemTypes
.map((itemType: CollectionItemType) => `type=${itemType.toString()}`)
.map((itemType: CollectionItemType) => {
const mappedItemType =
itemType === CollectionItemType.COLLECTION ? 'dataverse' : itemType.toString()
return `type=${mappedItemType}`
})
.join('&')

url += `&${itemTypesQueryString}`
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PublicationStatus } from '../../../../core/domain/models/PublicationStatus'
import { CollectionItemType } from '../../../../collections/domain/models/CollectionItemType'
import { CollectionPreview } from '../../../domain/models/CollectionPreview'
import { CollectionPreviewPayload } from './CollectionPreviewPayload'

Expand All @@ -10,6 +11,7 @@ export const transformCollectionPreviewPayloadToCollectionPreview = (
publicationStatuses.push(element as unknown as PublicationStatus)
})
return {
type: CollectionItemType.COLLECTION,
name: collectionPreviewPayload.name,
parentName: collectionPreviewPayload.parentDataverseName,
alias: collectionPreviewPayload.identifier,
Expand Down
2 changes: 2 additions & 0 deletions src/datasets/domain/models/DatasetPreview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { CollectionItemType } from '../../../collections'
import { PublicationStatus } from '../../../core/domain/models/PublicationStatus'
import { DatasetVersionInfo } from './Dataset'

export interface DatasetPreview {
type: CollectionItemType.DATASET
persistentId: string
title: string
versionId: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DatasetVersionState } from '../../../domain/models/Dataset'
import { DatasetPreviewSubset } from '../../../domain/models/DatasetPreviewSubset'
import { DatasetPreviewPayload } from './DatasetPreviewPayload'
import { PublicationStatus } from '../../../../core/domain/models/PublicationStatus'
import { CollectionItemType } from '../../../../collections/domain/models/CollectionItemType'

export const transformDatasetPreviewsResponseToDatasetPreviewSubset = (
response: AxiosResponse
Expand All @@ -28,6 +29,7 @@ export const transformDatasetPreviewPayloadToDatasetPreview = (
publicationStatuses.push(element as unknown as PublicationStatus)
})
return {
type: CollectionItemType.DATASET,
persistentId: datasetPreviewPayload.global_id,
title: datasetPreviewPayload.name,
versionId: datasetPreviewPayload.versionId,
Expand Down
2 changes: 2 additions & 0 deletions src/files/domain/models/FilePreview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CollectionItemType } from '../../../collections'
import { PublicationStatus } from '../../../core/domain/models/PublicationStatus'

export interface FilePreview {
type: CollectionItemType.FILE
name: string
url: string
imageUrl?: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CollectionItemType } from '../../../../collections/domain/models/CollectionItemType'
import { PublicationStatus } from '../../../../core/domain/models/PublicationStatus'
import { FilePreview } from '../../../domain/models/FilePreview'
import { FilePreviewPayload } from './FilePreviewPayload'
Expand All @@ -10,6 +11,7 @@ export const transformFilePreviewPayloadToFilePreview = (
publicationStatuses.push(element as unknown as PublicationStatus)
})
return {
type: CollectionItemType.FILE,
name: filePreviewPayload.name,
url: filePreviewPayload.url,
...(filePreviewPayload.image_url && { imageUrl: filePreviewPayload.image_url }),
Expand Down
3 changes: 2 additions & 1 deletion test/testHelpers/collections/collectionPreviewHelper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CollectionPreview } from '../../../src'
import { CollectionItemType, CollectionPreview } from '../../../src'
import { CollectionPreviewPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPreviewPayload'
import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus'

export const createCollectionPreviewModel = (): CollectionPreview => {
const collectionPreviewModel: CollectionPreview = {
type: CollectionItemType.COLLECTION,
name: 'test collection',
parentName: 'parent collection',
alias: 'testcollection',
Expand Down
2 changes: 2 additions & 0 deletions test/testHelpers/datasets/datasetPreviewHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DatasetPreview } from '../../../src/datasets/domain/models/DatasetPrevi
import { DatasetVersionState } from '../../../src/datasets/domain/models/Dataset'
import { DatasetPreviewPayload } from '../../../src/datasets/infra/repositories/transformers/DatasetPreviewPayload'
import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus'
import { CollectionItemType } from '../../../src'

const DATASET_CREATE_TIME_STR = '2023-05-15T08:21:01Z'
const DATASET_UPDATE_TIME_STR = '2023-05-15T08:21:03Z'
Expand All @@ -12,6 +13,7 @@ const DATASET_CITATION =

export const createDatasetPreviewModel = (): DatasetPreview => {
const datasetPreviewModel: DatasetPreview = {
type: CollectionItemType.DATASET,
persistentId: 'doi:10.5072/FK2/HC6KTB',
title: 'Test Dataset 1',
versionId: 19,
Expand Down
3 changes: 2 additions & 1 deletion test/testHelpers/files/filePreviewHelper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FilePreview } from '../../../src'
import { CollectionItemType, FilePreview } from '../../../src'
import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus'
import { FilePreviewPayload } from '../../../src/files/infra/repositories/transformers/FilePreviewPayload'

export const createFilePreviewModel = (): FilePreview => {
const filePreviewModel: FilePreview = {
type: CollectionItemType.FILE,
name: 'test file',
url: 'http://dataverse.com',
imageUrl: 'http://dataverseimage.com',
Expand Down

0 comments on commit 746affb

Please sign in to comment.