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

220 - Fix: Filters disappear when the filters results is 1 file #226

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions src/files/domain/models/FileCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function FileCriteriaForm({
filesCountInfo
}: FileCriteriaInputsProps) {
const showFileCriteriaInputs =
filesCountInfo && filesCountInfo.total >= MINIMUM_FILES_TO_SHOW_CRITERIA_INPUTS
filesCountInfo &&
(filesCountInfo.total >= MINIMUM_FILES_TO_SHOW_CRITERIA_INPUTS || criteria.someFilterApplied)
return (
<div className={styles['criteria-section']}>
<Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/png')

cy.customMount(
<FileCriteriaForm
criteria={criteria}
onCriteriaChange={onCriteriaChange}
filesCountInfo={FilesCountInfoMother.create({ total: 1 })}
/>
)

cy.findByRole('button', { name: 'File Type: PNG Image' }).should('exist')
cy.findByRole('button', { name: 'Access: Public' }).should('exist')
cy.findByRole('button', { name: 'File Tags: Document' }).should('exist')
})
})
21 changes: 20 additions & 1 deletion tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,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',
Expand Down Expand Up @@ -457,6 +457,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')
})
})

Expand Down