Skip to content

Commit

Permalink
🐛 Fix: Enable filtering of skills on homepage (#1045)
Browse files Browse the repository at this point in the history
* Skills filtering on Homepage

Signed-off-by: Vividh Pandey <[email protected]>

* Prettier Checks

Signed-off-by: Vividh Pandey <[email protected]>

* Fixed Test Cases

Signed-off-by: Vividh Pandey <[email protected]>

* Fixed Test Cases

Signed-off-by: Vividh Pandey <[email protected]>

---------

Signed-off-by: Vividh Pandey <[email protected]>
  • Loading branch information
VividhPandey003 authored Dec 5, 2023
1 parent 06f9c30 commit ed32f42
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('testing filters', () => {
describe('bountyHeaderLanguageFilter', () => {
test('match', () => {
expect(bountyHeaderLanguageFilter(['Javascript', 'Python'], { Javascript: true })).toEqual(
false
true
);
});
test('no-match', () => {
Expand Down
14 changes: 11 additions & 3 deletions frontend/app/src/people/utils/filterValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ export const bountyHeaderFilter = (
};

export const bountyHeaderLanguageFilter = (codingLanguage: any, filterLanguage: any) => {
if (Object.keys(filterLanguage)?.every((key: any) => !filterLanguage[key])) {
return true;
} else return codingLanguage?.some(({ value }: any) => filterLanguage[value]) ?? false;
const selectedLanguages: string[] = Object.keys(filterLanguage).filter(
(key: string) => filterLanguage[key]
);
if (!Array.isArray(selectedLanguages) || selectedLanguages.length === 0) {
return true; // No filter selected, show all bounties
} else {
// Use "and" logic - all selected skills must match- thus using every
return selectedLanguages.every((selectedLanguage: string) =>
codingLanguage.includes(selectedLanguage)
);
}
};
2 changes: 1 addition & 1 deletion frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function WidgetSwitchViewer(props: any) {
const value = { ...body };
return (
bountyHeaderFilter(props?.checkboxIdToSelectedMap, value?.paid, !!value?.assignee) &&
bountyHeaderLanguageFilter(value?.codingLanguage, props?.checkboxIdToSelectedMapLanguage)
bountyHeaderLanguageFilter(value?.coding_languages, props?.checkboxIdToSelectedMapLanguage)
);
});

Expand Down

0 comments on commit ed32f42

Please sign in to comment.