From d0125c08456f6049816a22a3dfbec7e5db2a8f49 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Thu, 9 Nov 2023 13:01:10 +0100 Subject: [PATCH] fix: display filters after the filter results in one file --- src/files/domain/models/FileCriteria.ts | 9 ++++++++ .../file-criteria-form/FileCriteriaForm.tsx | 5 ++++- .../FileCriteriaForm.spec.tsx | 19 +++++++++++++++++ .../e2e/sections/dataset/Dataset.spec.tsx | 21 ++++++++++++++++++- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/files/domain/models/FileCriteria.ts b/src/files/domain/models/FileCriteria.ts index 8de6c9dab..30720deba 100644 --- a/src/files/domain/models/FileCriteria.ts +++ b/src/files/domain/models/FileCriteria.ts @@ -62,6 +62,15 @@ export class FileCriteria { searchText ) } + + get someFilterApplied(): boolean { + return ( + this.filterByType !== undefined || + this.filterByAccess !== undefined || + this.filterByTag !== undefined || + this.searchText !== undefined + ) + } } export enum FileSortByOption { diff --git a/src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.tsx b/src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.tsx index 5096d4001..abaad677e 100644 --- a/src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.tsx +++ b/src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.tsx @@ -18,7 +18,10 @@ export function FileCriteriaForm({ onCriteriaChange, filesCountInfo }: FileCriteriaInputsProps) { - if (!filesCountInfo || filesCountInfo.total < MINIMUM_FILES_TO_SHOW_CRITERIA_INPUTS) { + if ( + !filesCountInfo || + (filesCountInfo.total < MINIMUM_FILES_TO_SHOW_CRITERIA_INPUTS && !criteria.someFilterApplied) + ) { return <> } return ( diff --git a/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.spec.tsx b/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.spec.tsx index bd0fb0294..9da843687 100644 --- a/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.spec.tsx @@ -289,4 +289,23 @@ describe('FileCriteriaForm', () => { cy.findByLabelText('Search').should('have.value', 'test') }) + + it('renders the file criteria if there are less than 2 files but there is a filter applied', () => { + const criteria = new FileCriteria() + .withFilterByTag('document') + .withFilterByAccess(FileAccessOption.PUBLIC) + .withFilterByType('image') + + cy.customMount( + + ) + + cy.findByRole('button', { name: 'File Type: Image' }).should('exist') + cy.findByRole('button', { name: 'Access: Public' }).should('exist') + cy.findByRole('button', { name: 'File Tags: Document' }).should('exist') + }) }) diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index ef743d439..b872564fa 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -300,7 +300,7 @@ describe('Dataset', () => { }) }) - it('applies filters to the Files Table in the correct order', () => { + it.only('applies filters to the Files Table in the correct order', () => { const files = [ FileHelper.create('csv', { description: 'Some description', @@ -403,6 +403,25 @@ describe('Dataset', () => { 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') + + cy.findByLabelText('Search').clear().type('blob-5{enter}', { force: true }) + + cy.findByText('1 to 1 of 1 Files').should('exist') + 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('not.exist') + cy.findByText('blob-5').should('exist') + + cy.findByLabelText('Search').clear().type('{enter}', { force: true }) + cy.findByText('1 to 3 of 3 Files').should('exist') + cy.findByText('blob').should('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') }) })