Skip to content

Commit

Permalink
[DT-776] Filter by Data Type (#2726)
Browse files Browse the repository at this point in the history
  • Loading branch information
fboulnois authored Nov 15, 2024
1 parent dcbcf31 commit 7465385
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cypress/component/DataSearch/dataset_search_filters.spec.js
Original file line number Diff line number Diff line change
@@ -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(<DatasetFilterList {...props} />);
cy.get('div').should('contain', 'Filters');
});
});
33 changes: 33 additions & 0 deletions cypress/component/DataSearch/dataset_search_page.spec.js
Original file line number Diff line number Diff line change
@@ -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(<DatasetSearch {...props} />);
});

it('Renders the data library with a query', () => {
const props = { match: { params: { query: 'test' } } };
cy.stub(Storage, 'getCurrentUser').returns(duosUser);
mount(<DatasetSearch {...props} />);
});
});
10 changes: 10 additions & 0 deletions src/components/data_search/DatasetFilterList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -89,6 +90,15 @@ export const DatasetFilterList = (props) => {
isFiltered={isFiltered}
filterNameFn={(filter) => filter}
/>
<FilterItemHeader title="Data Type" />
<FilterItemList
category="dataType"
datasets={datasets}
filter={dataTypeFilters}
filterHandler={filterHandler}
isFiltered={isFiltered}
filterNameFn={(filter) => filter}
/>
</Box>
);
};
Expand Down
12 changes: 12 additions & 0 deletions src/components/data_search/DatasetSearchTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const styles = {
const defaultFilters = {
accessManagement: [],
dataUse: [],
dataType: [],
dac: []
};

Expand Down Expand Up @@ -132,6 +133,17 @@ export const DatasetSearchTable = (props) => {
}
});

filterTerms.push({
'bool': {
'should':
filters.dataType.map(term => ({
'match': {
'study.dataTypes': term
}
}))
}
});

filterTerms.push({
'bool': {
'should':
Expand Down

0 comments on commit 7465385

Please sign in to comment.