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

Refactor advanced search results attribute processing #1363

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
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
42 changes: 18 additions & 24 deletions frontend/src/pages/AdvancedSearchResultsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,39 +278,33 @@ export const AdvancedSearchResultsPage: FC = () => {
// attrinfo and its related joined attrinfo
attrInfo
.map((info) => {
const results = [];

results.push({
const base = {
key: info.name,
val: {
filterKey:
info.filterKey ||
AdvancedSearchResultAttrInfoFilterKeyEnum.CLEARED,
keyword: info.keyword || "",
},
});
};

// weave joined attributes into the defaultAttrFilterArray
joinAttrs.forEach((join) => {
if (join.name === info.name) {
join.attrinfo.forEach((joinedInfo) => {
results.push({
key: `${join.name}.${joinedInfo.name}`,
val: {
filterKey:
joinedInfo.filterKey ||
AdvancedSearchResultAttrInfoFilterKeyEnum.CLEARED,
keyword: joinedInfo.keyword || "",
baseAttrname: join.name,
joinedAttrname: joinedInfo.name,
},
});
});
}
});
return results;
const joined = joinAttrs
.filter((join) => join.name === info.name)
.flatMap((join) =>
join.attrinfo.map((joinedInfo) => ({
key: `${join.name}.${joinedInfo.name}`,
val: {
filterKey:
joinedInfo.filterKey ||
AdvancedSearchResultAttrInfoFilterKeyEnum.CLEARED,
keyword: joinedInfo.keyword || "",
baseAttrname: join.name,
joinedAttrname: joinedInfo.name,
},
}))
);

// this convert array to dict using reduce()
return [base, ...joined];
})
.flat()
.reduce((a, x) => ({ ...a, [x.key]: x.val }), {})
Expand Down
Loading