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-781: Use logical AND to combine filters in the DUOS UI #2715

Merged
merged 3 commits into from
Nov 7, 2024
Merged
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
44 changes: 16 additions & 28 deletions src/components/data_search/DatasetSearchTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,60 +104,48 @@ export const DatasetSearchTable = (props) => {
queryChunks.push(...searchModifier);
}

var filterQuery = {};
let filterQuery = {};
Copy link
Member Author

Choose a reason for hiding this comment

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

I think var is not recommended now that we have let and const. The difference is that var has function scope, whereas let and const have block scope, which is usually what you want.

if (numSelectedFilters(filters) > 0) {
const shouldTerms = [];
const filterTerms = [];

filters.accessManagement.forEach(term => {
shouldTerms.push({
filterTerms.push({
'term': {
'accessManagement': term
}
});
});

filters.dataUse.forEach(term => {
shouldTerms.push({
filterTerms.push({
'match': {
'dataUse.primary.code': term
}
});
});

if (shouldTerms.length > 0) {
if (filterTerms.length > 0) {
filterQuery = [
{
'bool': {
'should': shouldTerms
'must': filterTerms
}
}
];
}
}

// do not add filter subquery if no filters are applied
if (numSelectedFilters(filters) > 0) {
return {
'from': 0,
'size': 10000,
'query': {
'bool': {
'must': queryChunks,
'filter': filterQuery
}
}
};
} else {
return {
'from': 0,
'size': 10000,
'query': {
'bool': {
'must': queryChunks
}
return {
Copy link
Member Author

Choose a reason for hiding this comment

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

This change wasn't required, but I thought it would be nice to

  • combine the code fragments to avoid duplication
  • test filterQuery instead of recomputing numSelectedFilters(filters), since filterQuery is the value actually used in the code block

'from': 0,
'size': 10000,
'query': {
'bool': {
'must': queryChunks,
// do not add filter subquery if no filters are applied
...(Object.keys(filterQuery).length > 0 && { 'filter': filterQuery })
}
};
}
}
};
};

const filterHandler = (event, data, category, filter) => {
Expand Down
Loading