From cbe26c900534f3c81f830e35c639dc5e3fd73583 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Wed, 4 Oct 2023 13:33:47 +0200 Subject: [PATCH] feat(RowSelection): remove row selection if the files criteria changes --- .../dataset/dataset-files/DatasetFiles.tsx | 1 + .../dataset-files/files-table/FilesTable.tsx | 13 +++- .../SettingJSDataverseRepository.ts | 2 +- .../dataset-files/DatasetFiles.spec.tsx | 59 +++++++++++++++++++ .../files-table/FilesTable.spec.tsx | 12 ++++ 5 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/sections/dataset/dataset-files/DatasetFiles.tsx b/src/sections/dataset/dataset-files/DatasetFiles.tsx index 5b009d762..cccd061a5 100644 --- a/src/sections/dataset/dataset-files/DatasetFiles.tsx +++ b/src/sections/dataset/dataset-files/DatasetFiles.tsx @@ -42,6 +42,7 @@ export function DatasetFiles({ isLoading={isLoading} paginationInfo={paginationInfo} filesTotalDownloadSize={filesTotalDownloadSize} + criteria={criteria} /> (criteria) + useEffect(() => { + if (previousCriteria != criteria) { + clearFileSelection() + } + setPreviousCriteria(criteria) + }) + if (isLoading) { return } diff --git a/src/settings/infrastructure/SettingJSDataverseRepository.ts b/src/settings/infrastructure/SettingJSDataverseRepository.ts index 03deebe37..eb5801de7 100644 --- a/src/settings/infrastructure/SettingJSDataverseRepository.ts +++ b/src/settings/infrastructure/SettingJSDataverseRepository.ts @@ -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) }, 1000) }) diff --git a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx index 4844f6b91..1e394acc6 100644 --- a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx @@ -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( + + ) + 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( + + ) + 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( + + ) + 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) diff --git a/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx index 441dcaafe..b56ea78d6 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx @@ -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( @@ -21,6 +23,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={false} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> ) @@ -40,6 +43,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={true} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> ) @@ -53,6 +57,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={false} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> ) @@ -67,6 +72,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={false} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> ) @@ -86,6 +92,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={false} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> ) @@ -109,6 +116,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={false} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> ) @@ -128,6 +136,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={false} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> ) @@ -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() @@ -173,6 +183,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={false} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> ) @@ -195,6 +206,7 @@ describe('FilesTable', () => { paginationInfo={paginationInfo} isLoading={false} filesTotalDownloadSize={testFilesTotalDownloadSize} + criteria={defaultCriteria} /> )