Skip to content

Commit

Permalink
feat(RowSelection): remove row selection if the files criteria changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Oct 4, 2023
1 parent 35ac5c4 commit cbe26c9
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/sections/dataset/dataset-files/DatasetFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function DatasetFiles({
isLoading={isLoading}
paginationInfo={paginationInfo}
filesTotalDownloadSize={filesTotalDownloadSize}
criteria={criteria}
/>
<FilesPagination
page={paginationInfo.page}
Expand Down
13 changes: 12 additions & 1 deletion src/sections/dataset/dataset-files/files-table/FilesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ import { SpinnerSymbol } from './spinner-symbol/SpinnerSymbol'
import { FilePaginationInfo } from '../../../../files/domain/models/FilePaginationInfo'
import { useEffect, useState } from 'react'
import { FileSelection } from './row-selection/useFileSelection'
import { FileCriteria } from '../../../../files/domain/models/FileCriteria'

interface FilesTableProps {
files: File[]
isLoading: boolean
paginationInfo: FilePaginationInfo
filesTotalDownloadSize: number
criteria: FileCriteria
}

export function FilesTable({
files,
isLoading,
paginationInfo,
filesTotalDownloadSize
filesTotalDownloadSize,
criteria
}: FilesTableProps) {
const { table, fileSelection, selectAllFiles, clearFileSelection } = useFilesTable(
files,
Expand All @@ -37,6 +40,14 @@ export function FilesTable({
setVisitedPagination(paginationInfo)
}, [fileSelection])

const [previousCriteria, setPreviousCriteria] = useState<FileCriteria>(criteria)
useEffect(() => {
if (previousCriteria != criteria) {
clearFileSelection()
}
setPreviousCriteria(criteria)
})

if (isLoading) {
return <SpinnerSymbol />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class SettingJSDataverseRepository implements SettingRepository {
setTimeout(() => {
resolve({
name: SettingName.ZIP_DOWNLOAD_LIMIT,
value: new ZipDownloadLimit(500, FileSizeUnit.BYTES)
value: new ZipDownloadLimit(1, FileSizeUnit.BYTES)
} as Setting<T>)
}, 1000)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,65 @@ describe('DatasetFiles', () => {
cy.findByText('1 file is currently selected.').should('exist')
})

it('removes the selection when the filters change', () => {
cy.customMount(
<DatasetFiles
filesRepository={fileRepository}
datasetPersistentId={datasetPersistentId}
datasetVersion={datasetVersion}
/>
)
cy.findByRole('columnheader', { name: '1 to 10 of 200 Files' }).should('exist')

cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click()

cy.findByText('1 file is currently selected.').should('exist')

cy.findByRole('button', { name: 'File Type: All' }).click()
cy.findByText('Image (485)').should('exist').click()

cy.findByText('1 file is currently selected.').should('not.exist')
})

it('removes the selection when the Sort by changes', () => {
cy.customMount(
<DatasetFiles
filesRepository={fileRepository}
datasetPersistentId={datasetPersistentId}
datasetVersion={datasetVersion}
/>
)
cy.findByRole('columnheader', { name: '1 to 10 of 200 Files' }).should('exist')

cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click()

cy.findByText('1 file is currently selected.').should('exist')

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

cy.findByText('1 file is currently selected.').should('not.exist')
})

it('removes the selection when the Search bar is used', () => {
cy.customMount(
<DatasetFiles
filesRepository={fileRepository}
datasetPersistentId={datasetPersistentId}
datasetVersion={datasetVersion}
/>
)
cy.findByRole('columnheader', { name: '1 to 10 of 200 Files' }).should('exist')

cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click()

cy.findByText('1 file is currently selected.').should('exist')

cy.findByLabelText('Search').type('test{enter}')

cy.findByText('1 file is currently selected.').should('not.exist')
})

it('renders the zip download limit message when selecting rows from different pages', () => {
testFiles[1] = FileMother.create({
size: new FileSize(1, FileSizeUnit.BYTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { ZipDownloadLimit } from '../../../../../../src/settings/domain/models/Z
import { SettingsContext } from '../../../../../../src/sections/settings/SettingsContext'
import styles from '../../../../../../src/sections/dataset/dataset-files/files-table/FilesTable.module.scss'
import { FilePaginationInfo } from '../../../../../../src/files/domain/models/FilePaginationInfo'
import { FileCriteria } from '../../../../../../src/files/domain/models/FileCriteria'

const testFiles = FileMother.createMany(10)
const paginationInfo = new FilePaginationInfo(1, 10, 200)
const testFilesTotalDownloadSize = 19900
const defaultCriteria = new FileCriteria()
describe('FilesTable', () => {
it('renders the files table', () => {
cy.customMount(
Expand All @@ -21,6 +23,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)

Expand All @@ -40,6 +43,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={true}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)

Expand All @@ -53,6 +57,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)

Expand All @@ -67,6 +72,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)

Expand All @@ -86,6 +92,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)

Expand All @@ -109,6 +116,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)

Expand All @@ -128,6 +136,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)

Expand All @@ -149,6 +158,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)
cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click()
Expand All @@ -173,6 +183,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
</SettingsContext.Provider>
)
Expand All @@ -195,6 +206,7 @@ describe('FilesTable', () => {
paginationInfo={paginationInfo}
isLoading={false}
filesTotalDownloadSize={testFilesTotalDownloadSize}
criteria={defaultCriteria}
/>
)

Expand Down

0 comments on commit cbe26c9

Please sign in to comment.