From 746538527305d780481889e248b51efa031a71ff Mon Sep 17 00:00:00 2001 From: fboulnois Date: Fri, 15 Nov 2024 12:42:08 -0500 Subject: [PATCH] [DT-776] Filter by Data Type (#2726) --- .../DataSearch/dataset_search_filters.spec.js | 27 +++++++++++++++ .../DataSearch/dataset_search_page.spec.js | 33 +++++++++++++++++++ .../data_search/DatasetFilterList.jsx | 10 ++++++ .../data_search/DatasetSearchTable.jsx | 12 +++++++ 4 files changed, 82 insertions(+) create mode 100644 cypress/component/DataSearch/dataset_search_filters.spec.js create mode 100644 cypress/component/DataSearch/dataset_search_page.spec.js diff --git a/cypress/component/DataSearch/dataset_search_filters.spec.js b/cypress/component/DataSearch/dataset_search_filters.spec.js new file mode 100644 index 000000000..d19a0f712 --- /dev/null +++ b/cypress/component/DataSearch/dataset_search_filters.spec.js @@ -0,0 +1,27 @@ +/* eslint-disable no-undef */ + +import { mount } from 'cypress/react'; +import React from 'react'; +import {Storage} from '../../../src/libs/storage'; +import DatasetFilterList from '../../../src/components/data_search/DatasetFilterList'; + +const duosUser = { + isSigningOfficial: false, +}; + +describe('Data Library Filters', () => { + // Intercept configuration calls + beforeEach(() => { + cy.intercept({ + method: 'GET', + url: '/config.json', + hostname: 'localhost', + }, { 'env': 'ci' }); + }); + + it('Renders the data library filters', () => { + const props = { datasets: [], filters: [], filterHandler: () => {}, isFiltered: () => {}}; + mount(); + cy.get('div').should('contain', 'Filters'); + }); +}); diff --git a/cypress/component/DataSearch/dataset_search_page.spec.js b/cypress/component/DataSearch/dataset_search_page.spec.js new file mode 100644 index 000000000..6bba8e28e --- /dev/null +++ b/cypress/component/DataSearch/dataset_search_page.spec.js @@ -0,0 +1,33 @@ +/* eslint-disable no-undef */ + +import { mount } from 'cypress/react'; +import React from 'react'; +import {Storage} from '../../../src/libs/storage'; +import DatasetSearch from '../../../src/pages/DatasetSearch'; + +const duosUser = { + isSigningOfficial: false, +}; + +describe('Data Library', () => { + // Intercept configuration calls + beforeEach(() => { + cy.intercept({ + method: 'GET', + url: '/config.json', + hostname: 'localhost', + }, { 'env': 'ci' }); + }); + + it('Renders the data library without a query', () => { + const props = { match: { params: { query: undefined } } }; + cy.stub(Storage, 'getCurrentUser').returns(duosUser); + mount(); + }); + + it('Renders the data library with a query', () => { + const props = { match: { params: { query: 'test' } } }; + cy.stub(Storage, 'getCurrentUser').returns(duosUser); + mount(); + }); +}); diff --git a/src/components/data_search/DatasetFilterList.jsx b/src/components/data_search/DatasetFilterList.jsx index 040665458..82167f443 100644 --- a/src/components/data_search/DatasetFilterList.jsx +++ b/src/components/data_search/DatasetFilterList.jsx @@ -47,6 +47,7 @@ export const DatasetFilterList = (props) => { const accessManagementFilters = uniq(compact(datasets.map((dataset) => dataset.accessManagement))); const dataUseFilters = uniq(compact(flatten(datasets.map((dataset) => dataset.dataUse?.primary))).map((dataUse) => dataUse.code)); + const dataTypeFilters = uniq(flatten(datasets.map((dataset) => dataset.study.dataTypes))); const dacFilters = orderBy(uniq(compact(datasets.map((dataset) => dataset.dac?.dacName))), (dac) => dac.toLowerCase(), 'asc'); return ( @@ -89,6 +90,15 @@ export const DatasetFilterList = (props) => { isFiltered={isFiltered} filterNameFn={(filter) => filter} /> + + filter} + /> ); }; diff --git a/src/components/data_search/DatasetSearchTable.jsx b/src/components/data_search/DatasetSearchTable.jsx index 25d0181fd..188646a0a 100644 --- a/src/components/data_search/DatasetSearchTable.jsx +++ b/src/components/data_search/DatasetSearchTable.jsx @@ -36,6 +36,7 @@ const styles = { const defaultFilters = { accessManagement: [], dataUse: [], + dataType: [], dac: [] }; @@ -132,6 +133,17 @@ export const DatasetSearchTable = (props) => { } }); + filterTerms.push({ + 'bool': { + 'should': + filters.dataType.map(term => ({ + 'match': { + 'study.dataTypes': term + } + })) + } + }); + filterTerms.push({ 'bool': { 'should':