-
Notifications
You must be signed in to change notification settings - Fork 4
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
[DT-777] Filter by participant count #2733
Merged
Merged
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2cbedca
add filter for participant count
raejohanek 45612b9
generalize FilterItemRange
raejohanek 9b2edc9
Merge branch 'develop' into rj/dt-777-filter-participant-count
raejohanek e2d3e06
add unit test
raejohanek 37606ba
feedback: update calculation of default values
raejohanek 9f89de8
feedback: update numSelectedFilters -> anyFiltersSelected
raejohanek 0f08b2c
simplify anyFiltersSelected
raejohanek 8dd3cc4
Feedback: update filterHandler
raejohanek d03c0bf
Feedback: add validation
raejohanek e1383f1
Merge branch 'develop' into rj/dt-777-filter-participant-count
raejohanek d0556f8
try to fix test
raejohanek c033344
try to fix test
raejohanek 4cc1ac8
try to fix test
raejohanek 44e9f1c
try to fix test
raejohanek 2417d78
fix tests?
raejohanek af1a501
fails locally, but just curious if it will pass on the server
raejohanek 24ca3b1
revert last change
raejohanek c4ed6ee
reduce URLs and rename parameter
raejohanek 2d3b3ab
remove debounce just to see
raejohanek 851879e
add cy.clock and revert remove debounce
raejohanek 455abe3
add cy.clock to existing tests!!
raejohanek ff293e5
pr feedback: simplify anyFiltersSelected and rename response alias in…
raejohanek 79eaba9
pr feedback: update calls in test
raejohanek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ const datasets = [ | |
datasetId: 123456, | ||
datasetIdentifier: `DUOS-123456`, | ||
datasetName: 'Some Dataset 1', | ||
participantCount: 100, | ||
study: { | ||
studyName: 'Some Study 1', | ||
studyId: 1, | ||
dataCustodianEmail: ['Some Data Custodian Email 1'], | ||
} | ||
|
@@ -23,8 +25,9 @@ const props = { | |
|
||
describe('Dataset Search Table tests', () => { | ||
|
||
describe('Data library with three datasets', () => { | ||
describe('Data library with one dataset footer tests', () => { | ||
beforeEach(() => { | ||
cy.initApplicationConfig(); | ||
cy.stub(TerraDataRepo, 'listSnapshotsByDatasetIds').returns({}); | ||
mount(<DatasetSearchTable {...props} />); | ||
}); | ||
|
@@ -38,6 +41,31 @@ describe('Dataset Search Table tests', () => { | |
cy.get('#header-checkbox').click(); | ||
cy.contains('1 dataset selected from 1 study'); | ||
}); | ||
}); | ||
|
||
describe('Data library filter by participant count tests', () => { | ||
beforeEach(() => { | ||
cy.initApplicationConfig(); | ||
cy.stub(TerraDataRepo, 'listSnapshotsByDatasetIds').returns({}); | ||
}); | ||
|
||
it('When a participant count filter is applied the query is updated', () => { | ||
var filtered = false; | ||
function handler(request) { | ||
if (JSON.stringify(request.body).includes('{"range":{"participantCount":{"gte":null,"lte":"50"}}}')) { | ||
filtered = true; | ||
} | ||
request.reply({statusCode: 200, body:[]}); | ||
} | ||
|
||
cy.intercept( | ||
{method: 'POST', url: '**/api/dataset/search/index'}, handler).as('searchIndex'); | ||
mount(<DatasetSearchTable {...props} />); | ||
cy.get('#participantCountMax-range-input').clear().type('50'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cypress recommends not chaining calls after clear. It's a little more verbose, but safer to:
|
||
cy.wait(1000).then(() => { | ||
rjohanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(filtered).to.be.true; | ||
}); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ import useOnMount from '@mui/utils/useOnMount'; | |||||||
import * as React from 'react'; | ||||||||
import { Box, Button } from '@mui/material'; | ||||||||
import { useEffect, useRef, useState } from 'react'; | ||||||||
import { isEmpty } from 'lodash'; | ||||||||
import { isArray, isEmpty } from 'lodash'; | ||||||||
import { TerraDataRepo } from '../../libs/ajax/TerraDataRepo'; | ||||||||
import { DatasetSearchTableDisplay } from './DatasetSearchTableDisplay'; | ||||||||
import { datasetSearchTableTabs } from './DatasetSearchTableConstants'; | ||||||||
|
@@ -37,7 +37,9 @@ const defaultFilters = { | |||||||
accessManagement: [], | ||||||||
dataUse: [], | ||||||||
dataType: [], | ||||||||
dac: [] | ||||||||
dac: [], | ||||||||
participantCountMin: null, | ||||||||
participantCountMax: null, | ||||||||
}; | ||||||||
|
||||||||
export const DatasetSearchTable = (props) => { | ||||||||
|
@@ -49,8 +51,21 @@ export const DatasetSearchTable = (props) => { | |||||||
const [selectedTable, setSelectedTable] = useState(datasetSearchTableTabs.study); | ||||||||
const [searchTerm, setSearchTerm] = useState(''); | ||||||||
|
||||||||
const isFiltered = (filter, category) => (filters[category]).indexOf(filter) > -1; | ||||||||
const numSelectedFilters = (filters) => Object.values(filters).reduce((sum, array) => sum + array.length, 0); | ||||||||
const isFilteredArray = (filter, category) => (filters[category]).indexOf(filter) > -1; | ||||||||
|
||||||||
const numSelectedFilters = (filters) => { | ||||||||
rjohanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
var sum = 0; | ||||||||
for (const category in filters) { | ||||||||
if (isArray(filters[category])) { | ||||||||
sum += filters[category].length; | ||||||||
} else { | ||||||||
if (filters[category]) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would combine an
Suggested change
|
||||||||
sum += 1; | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
return sum; | ||||||||
}; | ||||||||
|
||||||||
const getExportableDatasets = async (datasets) => { | ||||||||
// Note the dataset identifier is in each sub-table row. | ||||||||
|
@@ -155,6 +170,15 @@ export const DatasetSearchTable = (props) => { | |||||||
} | ||||||||
}); | ||||||||
|
||||||||
filterTerms.push({ | ||||||||
'range': { | ||||||||
'participantCount': { | ||||||||
'gte': filters.participantCountMin, | ||||||||
'lte': filters.participantCountMax, | ||||||||
rjohanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
} | ||||||||
} | ||||||||
}); | ||||||||
|
||||||||
if (filterTerms.length > 0) { | ||||||||
filterQuery = [ | ||||||||
{ | ||||||||
|
@@ -179,12 +203,16 @@ export const DatasetSearchTable = (props) => { | |||||||
}; | ||||||||
}; | ||||||||
|
||||||||
const filterHandler = (event, data, category, filter) => { | ||||||||
const filterHandler = (category, filter) => { | ||||||||
var newFilters = _.clone(filters); | ||||||||
if (!isFiltered(filter, category) && filter !== '') { | ||||||||
newFilters[category] = filters[category].concat(filter); | ||||||||
if (isArray(newFilters[category])) { | ||||||||
if (!isFilteredArray(filter, category) && filter !== '') { | ||||||||
newFilters[category] = filters[category].concat(filter); | ||||||||
} else { | ||||||||
newFilters[category] = filters[category].filter((f) => f !== filter); | ||||||||
} | ||||||||
} else { | ||||||||
newFilters[category] = filters[category].filter((f) => f !== filter); | ||||||||
newFilters[category] = filter; | ||||||||
} | ||||||||
setFilters(newFilters); | ||||||||
rjohanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
}; | ||||||||
|
@@ -280,7 +308,7 @@ export const DatasetSearchTable = (props) => { | |||||||
</Box> | ||||||||
<Box sx={{display: 'flex', flexDirection: 'row', paddingTop: '2em'}}> | ||||||||
<Box sx={{width: '14%', padding: '0 1em'}}> | ||||||||
<DatasetFilterList datasets={datasets} filters={filters} filterHandler={filterHandler} isFiltered={isFiltered} onClear={() => setFilters(defaultFilters)}/> | ||||||||
<DatasetFilterList datasets={datasets} filterHandler={filterHandler} isFiltered={isFilteredArray} onClear={() => setFilters(defaultFilters)}/> | ||||||||
</Box> | ||||||||
<Box sx={{width: '85%', padding: '0 1em'}}> | ||||||||
{(() => { | ||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused