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

[DT-778] Filter by Data Access Committee #2720

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 23 additions & 1 deletion src/components/data_search/DatasetFilterList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ 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 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');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does a case-ignore sort

fboulnois marked this conversation as resolved.
Show resolved Hide resolved

return (
<Box sx={{ bgcolor: 'background.paper' }}>
Expand Down Expand Up @@ -64,6 +65,27 @@ export const DatasetFilterList = (props) => {
})
}
</List>
<Typography variant="h6" gutterBottom component="div" sx={{ fontFamily: 'Montserrat' }} marginTop="1em">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these elements be refactored to avoid code duplication? They look pretty similar to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely want to do this long term, let me see how much work it would be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't too challenging, I created two new components.

<span style={{ fontWeight: '600' }}>Data Access Committee</span> <span>(DACs)</span>
</Typography>
<List sx={{ margin: '-0.5em -0.5em'}}>
{
dacFilters.map((filter) => {
const filterName = filter;
const category = 'dac';
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>
</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({
fboulnois marked this conversation as resolved.
Show resolved Hide resolved
'bool': {
'should':
filters.dac.map(term => ({
'match_phrase': {
'dac.dacName': term
}
}))
}
});

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