diff --git a/package-lock.json b/package-lock.json index 20d5fa78d..a848250ae 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.8", + "@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-alpha.8", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-alpha.8/bb548a68f074bec8b7a87f5d98f0fd03b87d07fb", - "integrity": "sha512-g1I1BfdoGUfohwQYPDwM2DHVYPBK+B4oHLO7twmPQDhZiWNTkMz34rbOxzA8ZUst22oxJj8rhuF5CqIO1YOBrw==", + "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", @@ -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/package.json b/package.json index e74d7ac8e..bf283f587 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.8", + "@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", 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/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/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index 2b204a17f..6ed22920b 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -161,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) diff --git a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts index b7453ffdc..5d4557824 100644 --- a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts +++ b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts @@ -34,7 +34,7 @@ export class JSFileMetadataMapper { this.toFileLabels(jsFile.categories, jsFile.tabularTags), this.toFileIsDeleted(jsFile.deleted), this.toFileOriginalFileDownloadUrl(jsFile.id), - jsFile.creationDate ?? new Date(), + jsFile.creationDate, jsFile.publicationDate, this.toFileThumbnail(thumbnail), this.toFileDirectory(jsFile.directoryLabel), @@ -55,8 +55,8 @@ export class JSFileMetadataMapper { } static toFileDate( - jsFileCreationDate?: Date, - jsFilePublicationDate?: Date, + jsFileCreationDate?: string, + jsFilePublicationDate?: string, jsFileEmbargo?: JSFileEmbargo ): FileDate { if (jsFilePublicationDate) { @@ -65,6 +65,7 @@ export class JSFileMetadataMapper { } return { type: FileDateType.PUBLISHED, date: jsFilePublicationDate } } + if (jsFileCreationDate) { return { type: FileDateType.DEPOSITED, date: jsFileCreationDate } } 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..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/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) } /> diff --git a/src/shared/helpers/DateHelper.ts b/src/shared/helpers/DateHelper.ts index 690b83c91..1f179563a 100644 --- a/src/shared/helpers/DateHelper.ts +++ b/src/shared/helpers/DateHelper.ts @@ -1,5 +1,5 @@ export class DateHelper { - static toDisplayFormat(date: Date | undefined): string { + 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..b943a2160 100644 --- a/tests/component/files/domain/models/FileMetadataMother.ts +++ b/tests/component/files/domain/models/FileMetadataMother.ts @@ -143,7 +143,7 @@ export class FileMetadataMother { size: FileSizeMother.create(), date: { type: FakerHelper.fileDateType(), - date: FakerHelper.recentDate() + date: '2024-02-01' }, downloadCount: FakerHelper.smallNumber(40), labels: faker.datatype.boolean() ? FileLabelMother.createMany(3) : [], @@ -155,8 +155,8 @@ 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: '2020-01-01', + publicationDate: faker.datatype.boolean() ? '2020-01-01' : undefined, persistentId: faker.datatype.uuid(), ...props } @@ -315,7 +315,7 @@ export class FileMetadataMother { static createWithPublicationDate(props?: Partial): FileMetadata { return this.createDefault({ - publicationDate: FakerHelper.pastDate(), + publicationDate: '2020-01-01', ...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 8bc1a95c8..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.toDisplayFormat(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 ) })