Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

167 - Files table UI [1/2] - Integration filters and search #171

Merged
merged 16 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 4 additions & 4 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-pr80.3e0c21e",
"@iqss/dataverse-client-javascript": "2.0.0-pr82.33671e5",
"@iqss/dataverse-design-system": "*",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tanstack/react-table": "8.9.2",
Expand Down
34 changes: 17 additions & 17 deletions src/files/infrastructure/FileJSDataverseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,39 @@ export class FileJSDataverseRepository implements FileRepository {
datasetPersistentId: string,
datasetVersion: DatasetVersion,
paginationInfo: FilePaginationInfo = new FilePaginationInfo(),
criteria?: FileCriteria
criteria: FileCriteria = new FileCriteria()
): Promise<File[]> {
const jsPagination = DomainFileMapper.toJSPagination(paginationInfo)
const jsFileOrderCriteria = DomainFileMapper.toJSFileOrderCriteria(criteria)

return getDatasetFiles
.execute(
datasetPersistentId,
datasetVersion.toString(),
jsPagination.limit,
jsPagination.offset,
jsFileOrderCriteria
DomainFileMapper.toJSFileCriteria(criteria)
)
.then((jsFiles) => jsFiles.map((jsFile) => JSFileMapper.toFile(jsFile, datasetVersion)))
.then((files) =>
Promise.all(
files.map((file) =>
FileJSDataverseRepository.getFileDownloadCount(
file.id,
file.version.publishingStatus
).then((downloadCount) => {
file.downloadCount = downloadCount
return file
})
)
)
)
.then((files) => FileJSDataverseRepository.getAllWithDownloadCount(files))
.catch((error: WriteError) => {
throw new Error(error.message)
})
}

private static getFileDownloadCount(
private static getAllWithDownloadCount(files: File[]): Promise<File[]> {
return Promise.all(
files.map((file) =>
FileJSDataverseRepository.getDownloadCountById(file.id, file.version.publishingStatus).then(
(downloadCount) => {
file.downloadCount = downloadCount
return file
}
)
)
)
}

private static getDownloadCountById(
id: number,
publishingStatus: FilePublishingStatus
): Promise<number> {
Expand Down
69 changes: 57 additions & 12 deletions src/files/infrastructure/mappers/DomainFileMapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { FilePaginationInfo } from '../../domain/models/FilePaginationInfo'
import { FileCriteria, FileSortByOption } from '../../domain/models/FileCriteria'
import { FileOrderCriteria } from '@iqss/dataverse-client-javascript'
import {
FileAccessOption,
FileCriteria,
FileSortByOption,
FileTag
} from '../../domain/models/FileCriteria'
import {
FileAccessStatus as JSFileAccessStatus,
FileCriteria as JSFileCriteria,
FileOrderCriteria as JSFileOrderCriteria
} from '@iqss/dataverse-client-javascript'
import { FileType } from '../../domain/models/File'

export class DomainFileMapper {
static toJSPagination(paginationInfo: FilePaginationInfo): { limit?: number; offset?: number } {
Expand All @@ -10,22 +20,57 @@ export class DomainFileMapper {
}
}

static toJSFileOrderCriteria(criteria?: FileCriteria): FileOrderCriteria {
switch (criteria?.sortBy) {
static toJSFileCriteria(criteria: FileCriteria): JSFileCriteria {
return new JSFileCriteria(
this.toJSOrderCriteria(criteria.sortBy),
this.toJSContentType(criteria.filterByType),
this.toJSAccessStatus(criteria.filterByAccess),
this.toJSCategoryName(criteria.filterByTag),
this.toJSSearchText(criteria.searchText)
)
}

static toJSOrderCriteria(sortBy: FileSortByOption): JSFileOrderCriteria {
switch (sortBy) {
case FileSortByOption.NAME_AZ:
return FileOrderCriteria.NAME_AZ
return JSFileOrderCriteria.NAME_AZ
case FileSortByOption.NAME_ZA:
return FileOrderCriteria.NAME_ZA
return JSFileOrderCriteria.NAME_ZA
case FileSortByOption.NEWEST:
return FileOrderCriteria.NEWEST
return JSFileOrderCriteria.NEWEST
case FileSortByOption.OLDEST:
return FileOrderCriteria.OLDEST
return JSFileOrderCriteria.OLDEST
case FileSortByOption.SIZE:
return FileOrderCriteria.SIZE
return JSFileOrderCriteria.SIZE
case FileSortByOption.TYPE:
return FileOrderCriteria.TYPE
default:
return FileOrderCriteria.NAME_AZ
return JSFileOrderCriteria.TYPE
}
}

static toJSContentType(type: FileType | undefined): string | undefined {
return type === undefined ? undefined : type.value
}

static toJSAccessStatus(
accessStatus: FileAccessOption | undefined
): JSFileAccessStatus | undefined {
switch (accessStatus) {
case FileAccessOption.PUBLIC:
return JSFileAccessStatus.PUBLIC
case FileAccessOption.RESTRICTED:
return JSFileAccessStatus.RESTRICTED
case FileAccessOption.EMBARGOED:
return JSFileAccessStatus.EMBARGOED
case FileAccessOption.EMBARGOED_RESTRICTED:
return JSFileAccessStatus.EMBARGOED_RESTRICTED
}
}

static toJSCategoryName(filterByTag: FileTag | undefined): string | undefined {
return filterByTag === undefined ? undefined : filterByTag.value
}

static toJSSearchText(searchText: string | undefined): string | undefined {
return searchText
}
}
119 changes: 112 additions & 7 deletions tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DatasetLabelValue } from '../../../../../src/dataset/domain/models/Dataset'
import { TestsUtils } from '../../../shared/TestsUtils'
import { DatasetHelper } from '../../../shared/datasets/DatasetHelper'
import { FileHelper } from '../../../shared/files/FileHelper'

type Dataset = {
datasetVersion: { metadataBlocks: { citation: { fields: { value: string }[] } } }
Expand Down Expand Up @@ -144,7 +145,7 @@ describe('Dataset', () => {
})

it('successfully loads the files tab with files', () => {
cy.wrap(DatasetHelper.createWithFiles(3))
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createMany(3)))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
Expand All @@ -160,7 +161,7 @@ describe('Dataset', () => {

it.skip('navigates to the next page of files', () => {
// TODO - Connect files count implementation to the pagination
cy.wrap(DatasetHelper.createWithFiles(20), { timeout: 10000 })
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createMany(20)), { timeout: 10000 })
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
Expand All @@ -180,7 +181,7 @@ describe('Dataset', () => {
})

it('successfully loads the action buttons when the user is logged in as owner', () => {
cy.wrap(DatasetHelper.createWithFiles(3))
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createMany(3)))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
Expand All @@ -196,7 +197,7 @@ describe('Dataset', () => {

it('does not load the action buttons when the user is not logged in as owner', () => {
cy.wrap(
DatasetHelper.createWithFiles(3).then((dataset) =>
DatasetHelper.createWithFiles(FileHelper.createMany(3)).then((dataset) =>
DatasetHelper.publish(dataset.persistentId)
)
)
Expand All @@ -217,7 +218,7 @@ describe('Dataset', () => {
})

it('loads the restricted files when the user is logged in as owner', () => {
cy.wrap(DatasetHelper.createWithFilesRestricted(1))
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createManyRestricted(1)))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
Expand All @@ -237,7 +238,7 @@ describe('Dataset', () => {

it('loads the restricted files when the user is not logged in as owner', () => {
cy.wrap(
DatasetHelper.createWithFilesRestricted(1).then((dataset) =>
DatasetHelper.createWithFiles(FileHelper.createManyRestricted(1)).then((dataset) =>
DatasetHelper.publish(dataset.persistentId)
)
)
Expand All @@ -261,7 +262,7 @@ describe('Dataset', () => {

it('loads the embargoed files', () => {
cy.wrap(
DatasetHelper.createWithFiles(1).then((dataset) =>
DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) =>
DatasetHelper.embargoFiles(
dataset.persistentId,
[dataset.files ? dataset.files[0].id : 0],
Expand All @@ -271,6 +272,8 @@ describe('Dataset', () => {
)
.its('persistentId')
.then((persistentId: string) => {
cy.wait(1500) // Wait for the files to be embargoed

cy.visit(`/spa/datasets?persistentId=${persistentId}`)

cy.findByText('Files').should('exist')
Expand All @@ -282,5 +285,107 @@ describe('Dataset', () => {
cy.findByText('Embargoed').should('exist')
})
})

it.skip('applies filters to the Files Table in the correct order', () => {
// TODO - Integrate fileCountInfo
const files = [
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
restrict: 'true',
tabIngest: 'false'
}),
FileHelper.create('csv', {
description: 'Some description',
restrict: 'true',
tabIngest: 'false'
}),
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
tabIngest: 'false'
}),
FileHelper.create('txt', {
description: 'Some description',
categories: ['category'],
restrict: 'true'
}),
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
restrict: 'true',
tabIngest: 'false'
}),
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
restrict: 'true',
tabIngest: 'false'
})
]
cy.wrap(DatasetHelper.createWithFiles(files))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)

cy.findByText('Files').should('exist')

cy.findByText('blob').should('exist')
cy.findByText('blob-1').should('exist')
cy.findByText('blob-2').should('exist')
cy.findByText('blob-3').should('exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByLabelText('Search').type('blob-{enter}', { force: true })

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('exist')
cy.findByText('blob-2').should('exist')
cy.findByText('blob-3').should('exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByRole('button', { name: 'Filter Tag: All' }).click({ force: true })
cy.findByText('category').should('exist').click({ force: true })

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('exist')
cy.findByText('blob-3').should('exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByRole('button', { name: 'Access: All' }).click()
cy.findByText('Restricted').should('exist').click()

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('not.exist')
cy.findByText('blob-3').should('exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByRole('button', { name: 'Filter Type: All' }).click()
cy.findByText('text/csv').should('exist').click()

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('not.exist')
cy.findByText('blob-3').should('not.exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByRole('button', { name: /Sort/ }).click()
cy.findByText('Name (Z-A)').should('exist').click()

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('not.exist')
cy.findByText('blob-3').should('not.exist')
cy.get('table > tbody > tr').eq(0).should('contain', 'blob-5')
cy.get('table > tbody > tr').eq(1).should('contain', 'blob-4')
})
})
})
})
Loading
Loading