From ed32f42a57526f5654c8a91aa20610a8c0638496 Mon Sep 17 00:00:00 2001 From: Vividh Pandey <91251535+VividhPandey003@users.noreply.github.com> Date: Wed, 6 Dec 2023 02:14:31 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Enable=20filtering=20of?= =?UTF-8?q?=20skills=20on=20homepage=20(#1045)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Skills filtering on Homepage Signed-off-by: Vividh Pandey * Prettier Checks Signed-off-by: Vividh Pandey * Fixed Test Cases Signed-off-by: Vividh Pandey * Fixed Test Cases Signed-off-by: Vividh Pandey --------- Signed-off-by: Vividh Pandey --- .../utils/__tests__/filterValidation.spec.ts | 2 +- frontend/app/src/people/utils/filterValidation.ts | 14 +++++++++++--- .../src/people/widgetViews/WidgetSwitchViewer.tsx | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/app/src/people/utils/__tests__/filterValidation.spec.ts b/frontend/app/src/people/utils/__tests__/filterValidation.spec.ts index f1051b8e7..321026833 100644 --- a/frontend/app/src/people/utils/__tests__/filterValidation.spec.ts +++ b/frontend/app/src/people/utils/__tests__/filterValidation.spec.ts @@ -27,7 +27,7 @@ describe('testing filters', () => { describe('bountyHeaderLanguageFilter', () => { test('match', () => { expect(bountyHeaderLanguageFilter(['Javascript', 'Python'], { Javascript: true })).toEqual( - false + true ); }); test('no-match', () => { diff --git a/frontend/app/src/people/utils/filterValidation.ts b/frontend/app/src/people/utils/filterValidation.ts index e9558665d..63a0d9eab 100644 --- a/frontend/app/src/people/utils/filterValidation.ts +++ b/frontend/app/src/people/utils/filterValidation.ts @@ -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) + ); + } }; diff --git a/frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx b/frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx index 25ce34221..f0da4a0d6 100644 --- a/frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx +++ b/frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx @@ -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) ); });