Skip to content

Commit

Permalink
Merge pull request #563 from IQSS/560-feature-requestidea-show-a-stri…
Browse files Browse the repository at this point in the history
…ng-for-the-creation-date-and-publication-date-of-file

Change the data format of File's creationDate and publishDate from Date to string
  • Loading branch information
ofahimIQSS authored Dec 20, 2024
2 parents 07f1c9c + f76d68e commit d1b4cc3
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 64 deletions.
10 changes: 5 additions & 5 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 @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
63 changes: 60 additions & 3 deletions src/collection/domain/models/CollectionSearchCriteria.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/files/domain/models/FileMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export enum FileDateType {

export interface FileDate {
type: FileDateType
date: Date
date: string
}

export class FileEmbargo {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/files/infrastructure/FileJSDataverseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class FileJSDataverseRepository implements FileRepository {
.then((jsFilePermissions) => JSFilePermissionsMapper.toFilePermissions(jsFilePermissions))
}

private static getDownloadCountById(id: number, publicationDate?: Date): Promise<number> {
private static getDownloadCountById(id: number, publicationDate?: string): Promise<number> {
return publicationDate !== undefined
? getFileDownloadCount.execute(id).then((downloadCount) => Number(downloadCount))
: Promise.resolve(0)
Expand Down
7 changes: 4 additions & 3 deletions src/files/infrastructure/mappers/JSFileMetadataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -55,8 +55,8 @@ export class JSFileMetadataMapper {
}

static toFileDate(
jsFileCreationDate?: Date,
jsFilePublicationDate?: Date,
jsFileCreationDate?: string,
jsFilePublicationDate?: string,
jsFileEmbargo?: JSFileEmbargo
): FileDate {
if (jsFilePublicationDate) {
Expand All @@ -65,6 +65,7 @@ export class JSFileMetadataMapper {
}
return { type: FileDateType.PUBLISHED, date: jsFilePublicationDate }
}

if (jsFileCreationDate) {
return { type: FileDateType.DEPOSITED, date: jsFileCreationDate }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
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')

return (
<div>
<span>
{t(`table.date.${date.type}`)}{' '}
<time dateTime={DateHelper.toISO8601Format(date.date)}>
{DateHelper.toDisplayFormat(date.date)}
</time>
{t(`table.date.${date.type}`)} <time dateTime={date.date}>{date.date}</time>
</span>
</div>
)
Expand Down
13 changes: 3 additions & 10 deletions src/sections/file/file-metadata/FileMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -99,9 +98,7 @@ export function FileMetadata({
<strong>{t('metadata.fields.depositDate')}</strong>
</Col>
<Col>
<time dateTime={DateHelper.toISO8601Format(metadata.depositDate)}>
{DateHelper.toISO8601Format(metadata.depositDate)}
</time>
<time dateTime={metadata.depositDate}>{metadata.depositDate}</time>
</Col>
</Row>
{metadata.publicationDate && (
Expand All @@ -110,9 +107,7 @@ export function FileMetadata({
<strong>{t('metadata.fields.metadataReleaseDate')}</strong>
</Col>
<Col>
<time dateTime={DateHelper.toISO8601Format(metadata.publicationDate)}>
{DateHelper.toISO8601Format(metadata.publicationDate)}
</time>
<time dateTime={metadata.publicationDate}>{metadata.publicationDate}</time>
</Col>
</Row>
)}
Expand All @@ -130,9 +125,7 @@ export function FileMetadata({
/>
) : (
metadata.publicationDate && (
<time dateTime={DateHelper.toISO8601Format(metadata.publicationDate)}>
{DateHelper.toISO8601Format(metadata.publicationDate)}
</time>
<time dateTime={metadata.publicationDate}>{metadata.publicationDate}</time>
)
)}
</Col>
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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<HTMLInputElement>) =>
onChange={(event: ChangeEvent<HTMLInputElement>) =>
setNewCustomTag(event.currentTarget.value)
}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -63,7 +63,7 @@ export function FileForm({ file, availableTags, updateFiles, setTagOptions }: Fi
type="text"
placeholder={t('fileForm.fileName')}
defaultValue={file.fileName}
onChange={(event: FormEvent<HTMLInputElement>) =>
onChange={(event: ChangeEvent<HTMLInputElement>) =>
updateFileName(file, event.currentTarget.value)
}
/>
Expand All @@ -78,7 +78,7 @@ export function FileForm({ file, availableTags, updateFiles, setTagOptions }: Fi
type="text"
placeholder={t('fileForm.filePath')}
defaultValue={file.fileDir}
onChange={(event: FormEvent<HTMLInputElement>) =>
onChange={(event: ChangeEvent<HTMLInputElement>) =>
updateFileDir(file, event.currentTarget.value)
}
/>
Expand All @@ -91,7 +91,7 @@ export function FileForm({ file, availableTags, updateFiles, setTagOptions }: Fi
<Col sm={9}>
<Form.Group.TextArea
defaultValue={file.description}
onChange={(event: FormEvent<HTMLInputElement>) =>
onChange={(event: ChangeEvent<HTMLInputElement>) =>
updateFileDescription(file, event.currentTarget.value)
}
/>
Expand Down Expand Up @@ -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<HTMLInputElement>) =>
onChange={(event: ChangeEvent<HTMLInputElement>) =>
setTag(event.currentTarget.value)
}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/shared/helpers/DateHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class DateHelper {
static toDisplayFormat(date: Date | undefined): string {
static toDisplayFormat(date: Date): string {
if (!date) {
return ''
}
Expand Down
8 changes: 4 additions & 4 deletions tests/component/files/domain/models/FileMetadataMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) : [],
Expand All @@ -155,8 +155,8 @@ export class FileMetadataMother {
description: valueOrUndefined<string>(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
}
Expand Down Expand Up @@ -315,7 +315,7 @@ export class FileMetadataMother {

static createWithPublicationDate(props?: Partial<FileMetadata>): FileMetadata {
return this.createDefault({
publicationDate: FakerHelper.pastDate(),
publicationDate: '2020-01-01',
...props
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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(<FileDate date={date} />)
const dateString = DateHelper.toDisplayFormat(fileDate)
cy.findByText(`Published`).should('exist')
cy.get('time').should('have.text', dateString)
cy.get('time').should('have.text', fileDate)
})
})
Loading

0 comments on commit d1b4cc3

Please sign in to comment.