From 35e5c957dfb00d0f2d95ce6dc6c2bc798a2226f4 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Fri, 6 Dec 2024 17:44:21 -0500 Subject: [PATCH 1/9] fix: change the data format to file creationDate and publishDate from Date to string --- .../mappers/JSFileMetadataMapper.ts | 20 ++++++----- src/shared/helpers/DateHelper.ts | 34 +++++++++++++++---- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts index b7453ffdc..10419ab4b 100644 --- a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts +++ b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts @@ -29,13 +29,13 @@ export class JSFileMetadataMapper { return new FileMetadata( this.toFileType(jsFile.contentType, jsFile.originalFormatLabel), this.toFileSize(jsFile.sizeBytes), - this.toFileDate(jsFile.creationDate, jsFile.publicationDate, jsFile.embargo), + this.toFileDate(jsFile.creationDate ?? '', jsFile.publicationDate, jsFile.embargo), this.toFileDownloads(downloadsCount), this.toFileLabels(jsFile.categories, jsFile.tabularTags), this.toFileIsDeleted(jsFile.deleted), this.toFileOriginalFileDownloadUrl(jsFile.id), - jsFile.creationDate ?? new Date(), - jsFile.publicationDate, + jsFile.creationDate ? new Date(jsFile.creationDate) : new Date(), + jsFile.publicationDate ? new Date(jsFile.publicationDate) : new Date(), this.toFileThumbnail(thumbnail), this.toFileDirectory(jsFile.directoryLabel), this.toFileEmbargo(jsFile.embargo), @@ -55,18 +55,22 @@ export class JSFileMetadataMapper { } static toFileDate( - jsFileCreationDate?: Date, - jsFilePublicationDate?: Date, + jsFileCreationDate: string, + jsFilePublicationDate?: string, jsFileEmbargo?: JSFileEmbargo ): FileDate { + console.log('jsFileCreationDate', jsFileCreationDate) if (jsFilePublicationDate) { if (jsFileEmbargo) { - return { type: FileDateType.METADATA_RELEASED, date: jsFilePublicationDate } + return { + type: FileDateType.METADATA_RELEASED, + date: new Date(jsFilePublicationDate) + } } - return { type: FileDateType.PUBLISHED, date: jsFilePublicationDate } + return { type: FileDateType.PUBLISHED, date: new Date(jsFilePublicationDate) } } if (jsFileCreationDate) { - return { type: FileDateType.DEPOSITED, date: jsFileCreationDate } + return { type: FileDateType.DEPOSITED, date: new Date(jsFileCreationDate) } } throw new Error('File date not found') } diff --git a/src/shared/helpers/DateHelper.ts b/src/shared/helpers/DateHelper.ts index 690b83c91..6fee580f9 100644 --- a/src/shared/helpers/DateHelper.ts +++ b/src/shared/helpers/DateHelper.ts @@ -1,13 +1,35 @@ export class DateHelper { - static toDisplayFormat(date: Date | undefined): string { + static toDisplayFormat(date: Date | undefined | string): string { if (!date) { return '' } - return date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { - year: 'numeric', - month: 'short', - day: 'numeric' - }) + + if (typeof date === 'string') { + const monthNames = [ + 'Jan', + 'Feb', + 'Mar', + 'Apr', + 'May', + 'Jun', + 'Jul', + 'Aug', + 'Sep', + 'Oct', + 'Nov', + 'Dec' + ] + const [year, month, day] = date.split('-') + const monthIndex = monthNames[parseInt(month) - 1] + const formattedDate = `${monthIndex} ${day}, ${year}` + return formattedDate + } else { + return date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { + year: 'numeric', + month: 'short', + day: 'numeric' + }) + } } static toDisplayFormatYYYYMMDD(date: Date | undefined): string { From c16476749e156c0015ff1c2068d4ffe24d953544 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Fri, 6 Dec 2024 18:46:56 -0500 Subject: [PATCH 2/9] fix: change the data format to file creationDate and publishDate from Date to string --- .../mappers/JSFileMetadataMapper.ts | 1 - .../file-info-data/FileDate.tsx | 2 +- src/shared/helpers/DateHelper.ts | 42 +++++++------------ .../file-info-data/FileDate.spec.tsx | 2 +- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts index 10419ab4b..9e97ad774 100644 --- a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts +++ b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts @@ -59,7 +59,6 @@ export class JSFileMetadataMapper { jsFilePublicationDate?: string, jsFileEmbargo?: JSFileEmbargo ): FileDate { - console.log('jsFileCreationDate', jsFileCreationDate) if (jsFilePublicationDate) { if (jsFileEmbargo) { return { diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx index 299887b4f..68256a4ac 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx @@ -10,7 +10,7 @@ export function FileDate({ date }: { date: FileDateModel }) { {t(`table.date.${date.type}`)}{' '} diff --git a/src/shared/helpers/DateHelper.ts b/src/shared/helpers/DateHelper.ts index 6fee580f9..35c053c2c 100644 --- a/src/shared/helpers/DateHelper.ts +++ b/src/shared/helpers/DateHelper.ts @@ -1,35 +1,25 @@ export class DateHelper { - static toDisplayFormat(date: Date | undefined | string): string { + static toDisplayFileFormat(date: Date): string { if (!date) { return '' } + return date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { + year: 'numeric', + month: 'short', + day: 'numeric', + timeZone: 'UTC' + }) + } - if (typeof date === 'string') { - const monthNames = [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'May', - 'Jun', - 'Jul', - 'Aug', - 'Sep', - 'Oct', - 'Nov', - 'Dec' - ] - const [year, month, day] = date.split('-') - const monthIndex = monthNames[parseInt(month) - 1] - const formattedDate = `${monthIndex} ${day}, ${year}` - return formattedDate - } else { - return date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { - year: 'numeric', - month: 'short', - day: 'numeric' - }) + static toDisplayFormat(date: Date): string { + if (!date) { + return '' } + return date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { + year: 'numeric', + month: 'short', + day: 'numeric' + }) } static toDisplayFormatYYYYMMDD(date: Date | undefined): string { diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx index 8bc1a95c8..02c1f6712 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx @@ -7,7 +7,7 @@ describe('FileDate', () => { const fileDate = new Date('2023-09-18') const date = { type: FileDateType.PUBLISHED, date: fileDate } cy.customMount() - const dateString = DateHelper.toDisplayFormat(fileDate) + const dateString = DateHelper.toDisplayFileFormat(fileDate) cy.findByText(`Published`).should('exist') cy.get('time').should('have.text', dateString) }) From cfd3fc8e710708936b697f25983be9dd716da7dd Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Thu, 12 Dec 2024 14:42:00 -0500 Subject: [PATCH 3/9] feat: update package --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42ddaf1e7..5f3632d9f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-alpha.4", + "@iqss/dataverse-client-javascript": "2.0.0-pr226.756569c", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -3674,9 +3674,9 @@ }, "node_modules/@iqss/dataverse-client-javascript": { "name": "@IQSS/dataverse-client-javascript", - "version": "2.0.0-alpha.4", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-alpha.4/10ab7e0ed2a31a09b1b32d27521b96f84ef50f4f", - "integrity": "sha512-SJdkBIks+yjJxEVw8G7sf4YY2Bujl+8vOD+fZqt2qhIGmyPSlj9ld0APnYyoVX6lI8lGsREHZzYYjzeAmYfxhw==", + "version": "2.0.0-pr226.756569c", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr226.756569c/d7701b41bbfadbe446d14c30bfade96292b7e7bd", + "integrity": "sha512-au7YCtaigfDx4IqCV1CSLh+9bqu413TF6v/rX6f79+CtaIBtB+KETGqaJix1oqWwrU/dh9i2HQB1VZd9QE9pEA==", "license": "MIT", "dependencies": { "@types/node": "^18.15.11", diff --git a/package.json b/package.json index db411a652..c306ec820 100644 --- a/package.json +++ b/package.json @@ -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-pr226.756569c", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", From 6279d01d4f767f67cee30aff1ee5b0a7b7228516 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Thu, 12 Dec 2024 15:24:05 -0500 Subject: [PATCH 4/9] fix: fix one type error for publicationDate --- .../infrastructure/FileJSDataverseRepository.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/files/infrastructure/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index 2b204a17f..d88e2bb2e 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -146,9 +146,12 @@ export class FileJSDataverseRepository implements FileRepository { private static getAllDownloadCount(jsFiles: JSFile[]): Promise { return Promise.all( - jsFiles.map((jsFile) => - FileJSDataverseRepository.getDownloadCountById(jsFile.id, jsFile.publicationDate) - ) + jsFiles.map((jsFile) => { + return FileJSDataverseRepository.getDownloadCountById( + jsFile.id, + jsFile.publicationDate ? new Date(jsFile.publicationDate) : new Date() + ) + }) ) } private static getAllWithPermissions(files: JSFile[]): Promise { @@ -234,7 +237,10 @@ export class FileJSDataverseRepository implements FileRepository { jsDataset, getDatasetCitation.execute(jsDataset.id, datasetVersionNumber, includeDeaccessioned), FileJSDataverseRepository.getCitationById(jsFile.id), - FileJSDataverseRepository.getDownloadCountById(jsFile.id, jsFile.publicationDate), + FileJSDataverseRepository.getDownloadCountById( + jsFile.id, + jsFile.publicationDate ? new Date(jsFile.publicationDate) : new Date() + ), FileJSDataverseRepository.getPermissionsById(jsFile.id), FileJSDataverseRepository.getThumbnailById(jsFile.id), FileJSDataverseRepository.getTabularDataById(jsFile.id, jsFile.tabularData) From 2f65c6e61e2a73483ac620da8c9b3279d95fed43 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Fri, 13 Dec 2024 17:16:17 -0500 Subject: [PATCH 5/9] fix: show strings for creationDate and publicationDate --- src/files/domain/models/FileMetadata.ts | 6 +++--- .../mappers/JSFileMetadataMapper.ts | 15 ++++++++------- .../file-info-cell/file-info-data/FileDate.tsx | 6 +----- .../file/file-metadata/FileMetadata.tsx | 13 +++---------- src/shared/helpers/DateHelper.ts | 12 ------------ .../files/domain/models/FileMetadataMother.ts | 11 +++++++---- .../file-info-data/FileDate.spec.tsx | 6 ++---- .../file/file-metadata/FileMetadata.spec.tsx | 17 ++++++----------- .../files/FileJSDataverseRepository.spec.ts | 10 +++++----- 9 files changed, 35 insertions(+), 61 deletions(-) diff --git a/src/files/domain/models/FileMetadata.ts b/src/files/domain/models/FileMetadata.ts index dadf7856d..1d4629e6d 100644 --- a/src/files/domain/models/FileMetadata.ts +++ b/src/files/domain/models/FileMetadata.ts @@ -87,7 +87,7 @@ export enum FileDateType { export interface FileDate { type: FileDateType - date: Date + date: string } export class FileEmbargo { @@ -150,8 +150,8 @@ export class FileMetadata { readonly labels: FileLabel[], public readonly isDeleted: boolean, public readonly downloadUrls: FileDownloadUrls, - readonly depositDate: Date, - readonly publicationDate?: Date, + readonly depositDate?: string, + readonly publicationDate?: string, public thumbnail?: string, readonly directory?: string, readonly embargo?: FileEmbargo, diff --git a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts index 9e97ad774..c43b6e8f6 100644 --- a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts +++ b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts @@ -29,13 +29,13 @@ export class JSFileMetadataMapper { return new FileMetadata( this.toFileType(jsFile.contentType, jsFile.originalFormatLabel), this.toFileSize(jsFile.sizeBytes), - this.toFileDate(jsFile.creationDate ?? '', jsFile.publicationDate, jsFile.embargo), + this.toFileDate(jsFile.creationDate, jsFile.publicationDate, jsFile.embargo), this.toFileDownloads(downloadsCount), this.toFileLabels(jsFile.categories, jsFile.tabularTags), this.toFileIsDeleted(jsFile.deleted), this.toFileOriginalFileDownloadUrl(jsFile.id), - jsFile.creationDate ? new Date(jsFile.creationDate) : new Date(), - jsFile.publicationDate ? new Date(jsFile.publicationDate) : new Date(), + jsFile.creationDate, + jsFile.publicationDate, this.toFileThumbnail(thumbnail), this.toFileDirectory(jsFile.directoryLabel), this.toFileEmbargo(jsFile.embargo), @@ -55,7 +55,7 @@ export class JSFileMetadataMapper { } static toFileDate( - jsFileCreationDate: string, + jsFileCreationDate?: string, jsFilePublicationDate?: string, jsFileEmbargo?: JSFileEmbargo ): FileDate { @@ -63,13 +63,14 @@ export class JSFileMetadataMapper { if (jsFileEmbargo) { return { type: FileDateType.METADATA_RELEASED, - date: new Date(jsFilePublicationDate) + date: jsFilePublicationDate } } - return { type: FileDateType.PUBLISHED, date: new Date(jsFilePublicationDate) } + return { type: FileDateType.PUBLISHED, date: jsFilePublicationDate } } + if (jsFileCreationDate) { - return { type: FileDateType.DEPOSITED, date: new Date(jsFileCreationDate) } + return { type: FileDateType.DEPOSITED, date: jsFileCreationDate } } throw new Error('File date not found') } diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx index 68256a4ac..4e9ca1ded 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx @@ -1,6 +1,5 @@ import { useTranslation } from 'react-i18next' import { FileDate as FileDateModel } from '../../../../../../../files/domain/models/FileMetadata' -import { DateHelper } from '../../../../../../../shared/helpers/DateHelper' export function FileDate({ date }: { date: FileDateModel }) { const { t } = useTranslation('files') @@ -8,10 +7,7 @@ export function FileDate({ date }: { date: FileDateModel }) { return (
- {t(`table.date.${date.type}`)}{' '} - + {t(`table.date.${date.type}`)}
) diff --git a/src/sections/file/file-metadata/FileMetadata.tsx b/src/sections/file/file-metadata/FileMetadata.tsx index ab49dbe8a..1c95782f8 100644 --- a/src/sections/file/file-metadata/FileMetadata.tsx +++ b/src/sections/file/file-metadata/FileMetadata.tsx @@ -2,7 +2,6 @@ import { Trans, useTranslation } from 'react-i18next' import { Accordion, Col, Row } from '@iqss/dataverse-design-system' import { FilePreview } from '../file-preview/FilePreview' import { FileLabels } from '../file-labels/FileLabels' -import { DateHelper } from '../../../shared/helpers/DateHelper' import { FileEmbargoDate } from '../file-embargo/FileEmbargoDate' import { BASE_URL } from '../../../config' import { FileMetadata as FileMetadataModel } from '../../../files/domain/models/FileMetadata' @@ -99,9 +98,7 @@ export function FileMetadata({ {t('metadata.fields.depositDate')} - + {metadata.publicationDate && ( @@ -110,9 +107,7 @@ export function FileMetadata({ {t('metadata.fields.metadataReleaseDate')} - + )} @@ -130,9 +125,7 @@ export function FileMetadata({ /> ) : ( metadata.publicationDate && ( - + ) )} diff --git a/src/shared/helpers/DateHelper.ts b/src/shared/helpers/DateHelper.ts index 35c053c2c..1f179563a 100644 --- a/src/shared/helpers/DateHelper.ts +++ b/src/shared/helpers/DateHelper.ts @@ -1,16 +1,4 @@ export class DateHelper { - static toDisplayFileFormat(date: Date): string { - if (!date) { - return '' - } - return date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { - year: 'numeric', - month: 'short', - day: 'numeric', - timeZone: 'UTC' - }) - } - static toDisplayFormat(date: Date): string { if (!date) { return '' diff --git a/tests/component/files/domain/models/FileMetadataMother.ts b/tests/component/files/domain/models/FileMetadataMother.ts index 96752b016..82db049d3 100644 --- a/tests/component/files/domain/models/FileMetadataMother.ts +++ b/tests/component/files/domain/models/FileMetadataMother.ts @@ -12,6 +12,7 @@ import { } from '../../../../../src/files/domain/models/FileMetadata' import FileTypeToFriendlyTypeMap from '../../../../../src/files/domain/models/FileTypeToFriendlyTypeMap' import { FakerHelper } from '../../../shared/FakerHelper' +import { DateHelper } from '@/shared/helpers/DateHelper' const valueOrUndefined: (value: T) => T | undefined = (value) => { const shouldShowValue = faker.datatype.boolean() @@ -143,7 +144,7 @@ export class FileMetadataMother { size: FileSizeMother.create(), date: { type: FakerHelper.fileDateType(), - date: FakerHelper.recentDate() + date: DateHelper.toISO8601Format(FakerHelper.recentDate()) }, downloadCount: FakerHelper.smallNumber(40), labels: faker.datatype.boolean() ? FileLabelMother.createMany(3) : [], @@ -155,8 +156,10 @@ export class FileMetadataMother { description: valueOrUndefined(faker.lorem.paragraph()), isDeleted: faker.datatype.boolean(), downloadUrls: FileDownloadUrlsMother.create(), - depositDate: FakerHelper.pastDate(), - publicationDate: faker.datatype.boolean() ? FakerHelper.pastDate() : undefined, + depositDate: DateHelper.toISO8601Format(FakerHelper.pastDate()), + publicationDate: faker.datatype.boolean() + ? DateHelper.toISO8601Format(FakerHelper.pastDate()) + : undefined, persistentId: faker.datatype.uuid(), ...props } @@ -315,7 +318,7 @@ export class FileMetadataMother { static createWithPublicationDate(props?: Partial): FileMetadata { return this.createDefault({ - publicationDate: FakerHelper.pastDate(), + publicationDate: DateHelper.toISO8601Format(FakerHelper.pastDate()), ...props }) } diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx index 02c1f6712..f08080c52 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx @@ -1,14 +1,12 @@ import { FileDate } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate' import { FileDateType } from '../../../../../../../../../src/files/domain/models/FileMetadata' -import { DateHelper } from '../../../../../../../../../src/shared/helpers/DateHelper' describe('FileDate', () => { it('renders the date', () => { - const fileDate = new Date('2023-09-18') + const fileDate = '2023-09-18' const date = { type: FileDateType.PUBLISHED, date: fileDate } cy.customMount() - const dateString = DateHelper.toDisplayFileFormat(fileDate) cy.findByText(`Published`).should('exist') - cy.get('time').should('have.text', dateString) + cy.get('time').should('have.text', fileDate) }) }) diff --git a/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx b/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx index 23b4dbe9a..d845be11e 100644 --- a/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx +++ b/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx @@ -11,7 +11,6 @@ import { } from '../../../files/domain/models/FileMetadataMother' import { DatasetPublishingStatus } from '../../../../../src/dataset/domain/models/Dataset' import { FilePermissionsMother } from '../../../files/domain/models/FilePermissionsMother' -import { DateHelper } from '../../../../../src/shared/helpers/DateHelper' const file = FileMother.create() describe('FileMetadata', () => { @@ -215,7 +214,9 @@ describe('FileMetadata', () => { /> ) cy.findByText('Deposit Date').should('exist') - cy.get('time').contains(DateHelper.toISO8601Format(file.metadata.depositDate)).should('exist') + if (file.metadata.depositDate) { + cy.get('time').contains(file.metadata.depositDate).should('exist') + } }) it('renders the file Metadata Release Date', () => { @@ -231,9 +232,7 @@ describe('FileMetadata', () => { cy.findByText('Metadata Release Date').should('exist') if (metadataWithPublicationDate.publicationDate) { - cy.findAllByText( - DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate) - ).should('exist') + cy.findAllByText(metadataWithPublicationDate.publicationDate).should('exist') } }) @@ -264,9 +263,7 @@ describe('FileMetadata', () => { cy.findByText('Publication Date').should('exist') if (metadataWithPublicationDate.publicationDate) { - cy.findAllByText( - DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate) - ).should('exist') + cy.findAllByText(metadataWithPublicationDate.publicationDate).should('exist') } }) @@ -284,9 +281,7 @@ describe('FileMetadata', () => { cy.findByText('Publication Date').should('exist') if (metadataWithPublicationDateEmbargoed.publicationDate) { - cy.findAllByText( - DateHelper.toISO8601Format(metadataWithPublicationDateEmbargoed.publicationDate) - ).should('exist') + cy.findAllByText(metadataWithPublicationDateEmbargoed.publicationDate).should('exist') } }) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 8a2fb0641..000e3603a 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -31,6 +31,8 @@ import { } from '../../../../src/dataset/domain/models/Dataset' import { File } from '../../../../src/files/domain/models/File' import { FileIngest, FileIngestStatus } from '../../../../src/files/domain/models/FileIngest' +import { DateHelper } from '@/shared/helpers/DateHelper' + const DRAFT_PARAM = DatasetNonNumericVersion.DRAFT chai.use(chaiAsPromised) @@ -38,8 +40,7 @@ const expect = chai.expect const fileRepository = new FileJSDataverseRepository() const datasetRepository = new DatasetJSDataverseRepository() -const dateNow = new Date() -dateNow.setHours(2, 0, 0, 0) +const dateNow = DateHelper.toISO8601Format(new Date()) const filePreviewExpectedData = (id: number): FilePreview => { return { id: id, @@ -161,7 +162,7 @@ describe('File JSDataverse Repository', () => { const compareMetadata = (fileMetadata: FileMetadata, expectedFileMetadata: FileMetadata) => { expect(fileMetadata.type).to.deep.equal(expectedFileMetadata.type) - cy.compareDate(fileMetadata.date.date, expectedFileMetadata.date.date) + expect(fileMetadata.date.date).to.deep.equal(expectedFileMetadata.date.date) expect(fileMetadata.downloadCount).to.deep.equal(expectedFileMetadata.downloadCount) expect(fileMetadata.labels).to.deep.equal(expectedFileMetadata.labels) expect(fileMetadata.checksum?.algorithm).to.deep.equal(expectedFileMetadata.checksum?.algorithm) @@ -249,8 +250,7 @@ describe('File JSDataverse Repository', () => { expect(file.datasetPublishingStatus).to.deep.equal( expectedPublishedFile.datasetPublishingStatus ) - cy.compareDate( - file.metadata.date.date, + expect(file.metadata.date.date).to.deep.equal( filePreviewExpectedData(file.id).metadata.date.date ) }) From c33fa3fd4224d9dd96ea23b346991983ffe01870 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Fri, 13 Dec 2024 17:26:33 -0500 Subject: [PATCH 6/9] fix: fix one type error for publicationDate --- .../infrastructure/FileJSDataverseRepository.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/files/infrastructure/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index d88e2bb2e..caf238d5b 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -147,10 +147,7 @@ export class FileJSDataverseRepository implements FileRepository { private static getAllDownloadCount(jsFiles: JSFile[]): Promise { return Promise.all( jsFiles.map((jsFile) => { - return FileJSDataverseRepository.getDownloadCountById( - jsFile.id, - jsFile.publicationDate ? new Date(jsFile.publicationDate) : new Date() - ) + return FileJSDataverseRepository.getDownloadCountById(jsFile.id, jsFile.publicationDate) }) ) } @@ -164,7 +161,7 @@ export class FileJSDataverseRepository implements FileRepository { .then((jsFilePermissions) => JSFilePermissionsMapper.toFilePermissions(jsFilePermissions)) } - private static getDownloadCountById(id: number, publicationDate?: Date): Promise { + private static getDownloadCountById(id: number, publicationDate?: string): Promise { return publicationDate !== undefined ? getFileDownloadCount.execute(id).then((downloadCount) => Number(downloadCount)) : Promise.resolve(0) @@ -237,10 +234,7 @@ export class FileJSDataverseRepository implements FileRepository { jsDataset, getDatasetCitation.execute(jsDataset.id, datasetVersionNumber, includeDeaccessioned), FileJSDataverseRepository.getCitationById(jsFile.id), - FileJSDataverseRepository.getDownloadCountById( - jsFile.id, - jsFile.publicationDate ? new Date(jsFile.publicationDate) : new Date() - ), + FileJSDataverseRepository.getDownloadCountById(jsFile.id, jsFile.publicationDate), FileJSDataverseRepository.getPermissionsById(jsFile.id), FileJSDataverseRepository.getThumbnailById(jsFile.id), FileJSDataverseRepository.getTabularDataById(jsFile.id, jsFile.tabularData) From 36e6311fbbe570af5938b5ff15377b08fa9cff1c Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Mon, 16 Dec 2024 10:20:19 -0500 Subject: [PATCH 7/9] fix: changes on test, remove some dateHelpers on test, and delete extra return keyword --- src/files/infrastructure/FileJSDataverseRepository.ts | 6 +++--- .../infrastructure/mappers/JSFileMetadataMapper.ts | 5 +---- .../files/domain/models/FileMetadataMother.ts | 11 ++++------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/files/infrastructure/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index caf238d5b..6ed22920b 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -146,9 +146,9 @@ export class FileJSDataverseRepository implements FileRepository { private static getAllDownloadCount(jsFiles: JSFile[]): Promise { return Promise.all( - jsFiles.map((jsFile) => { - return FileJSDataverseRepository.getDownloadCountById(jsFile.id, jsFile.publicationDate) - }) + jsFiles.map((jsFile) => + FileJSDataverseRepository.getDownloadCountById(jsFile.id, jsFile.publicationDate) + ) ) } private static getAllWithPermissions(files: JSFile[]): Promise { diff --git a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts index c43b6e8f6..5d4557824 100644 --- a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts +++ b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts @@ -61,10 +61,7 @@ export class JSFileMetadataMapper { ): FileDate { if (jsFilePublicationDate) { if (jsFileEmbargo) { - return { - type: FileDateType.METADATA_RELEASED, - date: jsFilePublicationDate - } + return { type: FileDateType.METADATA_RELEASED, date: jsFilePublicationDate } } return { type: FileDateType.PUBLISHED, date: jsFilePublicationDate } } diff --git a/tests/component/files/domain/models/FileMetadataMother.ts b/tests/component/files/domain/models/FileMetadataMother.ts index 82db049d3..b943a2160 100644 --- a/tests/component/files/domain/models/FileMetadataMother.ts +++ b/tests/component/files/domain/models/FileMetadataMother.ts @@ -12,7 +12,6 @@ import { } from '../../../../../src/files/domain/models/FileMetadata' import FileTypeToFriendlyTypeMap from '../../../../../src/files/domain/models/FileTypeToFriendlyTypeMap' import { FakerHelper } from '../../../shared/FakerHelper' -import { DateHelper } from '@/shared/helpers/DateHelper' const valueOrUndefined: (value: T) => T | undefined = (value) => { const shouldShowValue = faker.datatype.boolean() @@ -144,7 +143,7 @@ export class FileMetadataMother { size: FileSizeMother.create(), date: { type: FakerHelper.fileDateType(), - date: DateHelper.toISO8601Format(FakerHelper.recentDate()) + date: '2024-02-01' }, downloadCount: FakerHelper.smallNumber(40), labels: faker.datatype.boolean() ? FileLabelMother.createMany(3) : [], @@ -156,10 +155,8 @@ export class FileMetadataMother { description: valueOrUndefined(faker.lorem.paragraph()), isDeleted: faker.datatype.boolean(), downloadUrls: FileDownloadUrlsMother.create(), - depositDate: DateHelper.toISO8601Format(FakerHelper.pastDate()), - publicationDate: faker.datatype.boolean() - ? DateHelper.toISO8601Format(FakerHelper.pastDate()) - : undefined, + depositDate: '2020-01-01', + publicationDate: faker.datatype.boolean() ? '2020-01-01' : undefined, persistentId: faker.datatype.uuid(), ...props } @@ -318,7 +315,7 @@ export class FileMetadataMother { static createWithPublicationDate(props?: Partial): FileMetadata { return this.createDefault({ - publicationDate: DateHelper.toISO8601Format(FakerHelper.pastDate()), + publicationDate: '2020-01-01', ...props }) } From 157d84abd03b7d7845be55c835f2a6e9804b3759 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Thu, 19 Dec 2024 10:17:29 -0500 Subject: [PATCH 8/9] fix: change the js-dataverse in package.json to 2.0.0-alpha.10 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5f3632d9f..e04344ef5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-pr226.756569c", + "@iqss/dataverse-client-javascript": "2.0.0-alpha.10", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -3674,9 +3674,9 @@ }, "node_modules/@iqss/dataverse-client-javascript": { "name": "@IQSS/dataverse-client-javascript", - "version": "2.0.0-pr226.756569c", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr226.756569c/d7701b41bbfadbe446d14c30bfade96292b7e7bd", - "integrity": "sha512-au7YCtaigfDx4IqCV1CSLh+9bqu413TF6v/rX6f79+CtaIBtB+KETGqaJix1oqWwrU/dh9i2HQB1VZd9QE9pEA==", + "version": "2.0.0-alpha.10", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-alpha.10/41edaabb0072793dd0a3438871d27ee60388bb58", + "integrity": "sha512-rBC3aaAgR26NRmXoGTQAFnxRlmKWca5xq8VuqC58DpBogvwXxLKM/5tvxFnjgKAuSeyDxJpfxSZeorCaTsSvwA==", "license": "MIT", "dependencies": { "@types/node": "^18.15.11", diff --git a/package.json b/package.json index c306ec820..d94960a77 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-pr226.756569c", + "@iqss/dataverse-client-javascript": "2.0.0-alpha.10", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", From f76d68ee25b1138e2d4aea93ff8bef817154c77b Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Thu, 19 Dec 2024 14:51:54 -0500 Subject: [PATCH 9/9] solve conflicts --- package-lock.json | 2 +- packages/design-system/package.json | 2 +- .../models/CollectionSearchCriteria.tsx | 63 ++++++++++++++++++- .../add-tags-modal/AddTagsModal.tsx | 4 +- .../file-form/FileForm.tsx | 10 +-- 5 files changed, 69 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0681d081..a848250ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44426,7 +44426,7 @@ "react-bootstrap": "2.7.2", "react-bootstrap-icons": "1.11.4", "sass": "1.58.1", - "typescript": "4.9.5", + "typescript": "5.7.2", "vite-plugin-istanbul": "4.0.1" }, "devDependencies": { diff --git a/packages/design-system/package.json b/packages/design-system/package.json index 88966e1d2..0f55bb6b1 100644 --- a/packages/design-system/package.json +++ b/packages/design-system/package.json @@ -52,7 +52,7 @@ "react-bootstrap": "2.7.2", "react-bootstrap-icons": "1.11.4", "sass": "1.58.1", - "typescript": "4.9.5", + "typescript": "5.7.2", "vite-plugin-istanbul": "4.0.1" }, "devDependencies": { diff --git a/src/collection/domain/models/CollectionSearchCriteria.tsx b/src/collection/domain/models/CollectionSearchCriteria.tsx index 247439c7d..f6f7b84c7 100644 --- a/src/collection/domain/models/CollectionSearchCriteria.tsx +++ b/src/collection/domain/models/CollectionSearchCriteria.tsx @@ -1,17 +1,74 @@ import { type CollectionItemType } from './CollectionItemType' +export enum SortType { + NAME = 'name', + DATE = 'date' +} + +export enum OrderType { + ASC = 'asc', + DESC = 'desc' +} + +export type FilterQuery = `${string}:${string}` + export class CollectionSearchCriteria { constructor( public readonly searchText?: string, - public readonly itemTypes?: CollectionItemType[] + public readonly itemTypes?: CollectionItemType[], + public readonly sort?: SortType, + public readonly order?: OrderType, + public readonly filterQueries?: FilterQuery[] ) {} withSearchText(searchText: string | undefined): CollectionSearchCriteria { - return new CollectionSearchCriteria(searchText, this.itemTypes) + return new CollectionSearchCriteria( + searchText, + this.itemTypes, + this.sort, + this.order, + this.filterQueries + ) } withItemTypes(itemTypes: CollectionItemType[] | undefined): CollectionSearchCriteria { - return new CollectionSearchCriteria(this.searchText, itemTypes) + return new CollectionSearchCriteria( + this.searchText, + itemTypes, + this.sort, + this.order, + this.filterQueries + ) + } + + withSort(sort: SortType | undefined): CollectionSearchCriteria { + return new CollectionSearchCriteria( + this.searchText, + this.itemTypes, + sort, + this.order, + this.filterQueries + ) + } + + withOrder(order: OrderType | undefined): CollectionSearchCriteria { + return new CollectionSearchCriteria( + this.searchText, + this.itemTypes, + this.sort, + order, + this.filterQueries + ) + } + + withFilterQueries(filterQueries: FilterQuery[] | undefined): CollectionSearchCriteria { + return new CollectionSearchCriteria( + this.searchText, + this.itemTypes, + this.sort, + this.order, + filterQueries + ) } hasSearchText(): boolean { diff --git a/src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx b/src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx index 03df1aca7..7c512eb15 100644 --- a/src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx +++ b/src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx @@ -1,6 +1,6 @@ import { Button, Col, Form, Modal, Badge } from '@iqss/dataverse-design-system' import styles from './AddTagsModal.module.scss' -import { FormEvent, useState, KeyboardEvent, useId } from 'react' +import { useState, KeyboardEvent, useId, ChangeEvent } from 'react' import { useTranslation } from 'react-i18next' import { Plus, X } from 'react-bootstrap-icons' @@ -78,7 +78,7 @@ export function AddTagsModal({ show, availableTags, setTagOptions, update }: Add placeholder={t('tags.addNewTag')} value={newCustomTag} title={t('addTags.customTag')} - onChange={(event: FormEvent) => + onChange={(event: ChangeEvent) => setNewCustomTag(event.currentTarget.value) } /> diff --git a/src/sections/upload-dataset-files/uploaded-files-list/file-form/FileForm.tsx b/src/sections/upload-dataset-files/uploaded-files-list/file-form/FileForm.tsx index 783743443..e18913541 100644 --- a/src/sections/upload-dataset-files/uploaded-files-list/file-form/FileForm.tsx +++ b/src/sections/upload-dataset-files/uploaded-files-list/file-form/FileForm.tsx @@ -1,7 +1,7 @@ import { Badge, Button, Col, Form } from '@iqss/dataverse-design-system' import { FileUploadState } from '../../../../files/domain/models/FileUploadState' import styles from './FileForm.module.scss' -import { FormEvent, useState, KeyboardEvent, useId } from 'react' +import { ChangeEvent, useState, KeyboardEvent, useId } from 'react' import { useTranslation } from 'react-i18next' import { Plus, X } from 'react-bootstrap-icons' @@ -63,7 +63,7 @@ export function FileForm({ file, availableTags, updateFiles, setTagOptions }: Fi type="text" placeholder={t('fileForm.fileName')} defaultValue={file.fileName} - onChange={(event: FormEvent) => + onChange={(event: ChangeEvent) => updateFileName(file, event.currentTarget.value) } /> @@ -78,7 +78,7 @@ export function FileForm({ file, availableTags, updateFiles, setTagOptions }: Fi type="text" placeholder={t('fileForm.filePath')} defaultValue={file.fileDir} - onChange={(event: FormEvent) => + onChange={(event: ChangeEvent) => updateFileDir(file, event.currentTarget.value) } /> @@ -91,7 +91,7 @@ export function FileForm({ file, availableTags, updateFiles, setTagOptions }: Fi ) => + onChange={(event: ChangeEvent) => updateFileDescription(file, event.currentTarget.value) } /> @@ -119,7 +119,7 @@ export function FileForm({ file, availableTags, updateFiles, setTagOptions }: Fi placeholder={t('tags.addCustomTag')} title={t('tags.creatingNewTag')} value={tag} - onChange={(event: FormEvent) => + onChange={(event: ChangeEvent) => setTag(event.currentTarget.value) } />