Skip to content

Commit

Permalink
[DT-778] Filter by Data Access Committee (#2720)
Browse files Browse the repository at this point in the history
  • Loading branch information
fboulnois committed Nov 13, 2024
1 parent 77ccc88 commit 207c400
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 43 deletions.
106 changes: 63 additions & 43 deletions src/components/data_search/DatasetFilterList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,82 @@ import ListItemText from '@mui/material/ListItemText';
import Divider from '@mui/material/Divider';
import { Typography } from '@mui/material';
import { Checkbox } from '@mui/material';
import { flatten, uniq, compact, capitalize } from 'lodash';
import { flatten, uniq, compact, capitalize, orderBy } from 'lodash';

export const FilterItemHeader = (props) => {
const { title, headerStyle = { fontFamily: 'Montserrat', fontWeight: '600', marginTop: '1em' } } = props;
return (
<Typography variant="h6" gutterBottom component="div" sx={headerStyle}>
{title}
</Typography>
);
}

export const FilterItemList = (props) => {
const { category, datasets, filter, filterHandler, isFiltered, filterNameFn } = props;
return (
<List sx={{ margin: '-0.5em -0.5em' }}>
{
filter.map((filter) => {
const filterName = filterNameFn(filter);
return (
<ListItem disablePadding key={filter}>
<ListItemButton sx={{ padding: '0' }} onClick={(event) => filterHandler(event, datasets, category, filter)}>
<ListItemIcon>
<Checkbox checked={isFiltered(filter, category)} />
</ListItemIcon>
<ListItemText primary={filterName} sx={{ fontFamily: 'Montserrat', transform: 'scale(1.2)' }} />
</ListItemButton>
</ListItem>
);
})
}
</List>
);
};

export const DatasetFilterList = (props) => {
const { datasets, filters, filterHandler, isFiltered } = 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 dacFilters = orderBy(uniq(compact(datasets.map((dataset) => dataset.dac?.dacName))), (dac) => dac.toLowerCase(), 'asc');

return (
<Box sx={{ bgcolor: 'background.paper' }}>
<Typography variant="h5" gutterBottom component="div" sx={{ fontFamily: 'Montserrat', fontWeight: '600' }}>
Filters
</Typography>
<Divider />
<Typography variant="h6" gutterBottom component="div" sx={{ fontFamily: 'Montserrat', fontWeight: '600' }} marginTop="1em">
Access Type
</Typography>
<List sx={{ margin: '-0.5em -0.5em'}}>
{
accessManagementFilters.map((filter) => {
const filterName = capitalize(filter);
const category = 'accessManagement';
return (
<ListItem disablePadding key={filter}>
<ListItemButton sx={{ padding: '0' }} onClick={(event) => filterHandler(event, datasets, category, filter)}>
<ListItemIcon>
<Checkbox checked={isFiltered(filter, category)} />
</ListItemIcon>
<ListItemText primary={filterName} sx={{ fontFamily: 'Montserrat', transform: 'scale(1.2)' }} />
</ListItemButton>
</ListItem>
);
})
}
</List>
<Typography variant="h6" gutterBottom component="div" sx={{ fontFamily: 'Montserrat', fontWeight: '600' }} marginTop="1em">
Primary Data Use
</Typography>
<List sx={{ margin: '-0.5em -0.5em'}}>
{
dataUseFilters.map((filter) => {
const filterName = filter.toUpperCase();
const category = 'dataUse';
return (
<ListItem disablePadding key={filter}>
<ListItemButton sx={{ padding: '0' }} onClick={(event) => filterHandler(event, datasets, category, filter)}>
<ListItemIcon>
<Checkbox checked={isFiltered(filter, category)} />
</ListItemIcon>
<ListItemText primary={filterName} sx={{ fontFamily: 'Montserrat', transform: 'scale(1.2)' }} />
</ListItemButton>
</ListItem>
);
})
}
</List>
<FilterItemHeader title="Access Type" />
<FilterItemList
category="accessManagement"
datasets={datasets}
filter={accessManagementFilters}
filterHandler={filterHandler}
isFiltered={isFiltered}
filterNameFn={capitalize} />
<FilterItemHeader title="Data Use" />
<FilterItemList
category="dataUse"
datasets={datasets}
filter={dataUseFilters}
filterHandler={filterHandler}
isFiltered={isFiltered}
filterNameFn={(filter) => filter.toUpperCase()}
/>
<FilterItemHeader
title={<><span style={{ fontWeight: '600' }}>Data Access Committee</span> <span>(DACs)</span></>}
headerStyle={{ fontFamily: 'Montserrat', marginTop: '1em' }}
/>
<FilterItemList
category="dac"
datasets={datasets}
filter={dacFilters}
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 @@ -35,6 +35,7 @@ const styles = {
const defaultFilters = {
accessManagement: [],
dataUse: [],
dac: [],
search: []
};

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

filterTerms.push({
'bool': {
'should':
filters.dac.map(term => ({
'match_phrase': {
'dac.dacName': term
}
}))
}
});

if (filterTerms.length > 0) {
filterQuery = [
{
Expand Down

0 comments on commit 207c400

Please sign in to comment.