From 078c57d2422fa61b8a06752d63163d20d94b3726 Mon Sep 17 00:00:00 2001 From: sumo_slonik Date: Wed, 13 Nov 2024 12:10:25 +0100 Subject: [PATCH 1/4] fix condition by adding check if taxes are enabled --- src/libs/PolicyUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 4592500e9250..80a816fd85ed 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -483,7 +483,7 @@ function getTaxByID(policy: OnyxEntry, taxID: string): TaxRate | undefin function getAllTaxRatesNamesAndKeys(): Record { const allTaxRates: Record = {}; Object.values(allPolicies ?? {})?.forEach((policy) => { - if (!policy?.taxRates?.taxes) { + if (!policy?.taxRates?.taxes || !policy?.tax?.trackingEnabled) { return; } Object.entries(policy?.taxRates?.taxes).forEach(([taxRateKey, taxRate]) => { From 2b8150c4f75c2544bbda620bc7ac6b56a273770c Mon Sep 17 00:00:00 2001 From: sumo_slonik Date: Wed, 13 Nov 2024 17:05:31 +0100 Subject: [PATCH 2/4] fix problems with other disabled filters --- src/pages/Search/AdvancedSearchFilters.tsx | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index 4398f89e3ecc..a1ac9bcba1b1 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -18,7 +18,7 @@ import {convertToDisplayStringWithoutCurrency} from '@libs/CurrencyUtils'; import localeCompare from '@libs/LocaleCompare'; import Navigation from '@libs/Navigation/Navigation'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; -import {getAllTaxRates, getTagNamesFromTagsLists} from '@libs/PolicyUtils'; +import {getAllTaxRates, getTagNamesFromTagsLists, isPolicyFeatureEnabled} from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as SearchQueryUtils from '@libs/SearchQueryUtils'; import * as SearchUIUtils from '@libs/SearchUIUtils'; @@ -28,6 +28,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {SearchAdvancedFiltersForm} from '@src/types/form'; import type {CardList, PersonalDetailsList, Policy, PolicyTagLists, Report} from '@src/types/onyx'; +import type {PolicyFeatureName} from '@src/types/onyx/Policy'; const baseFilterConfig = { date: { @@ -251,6 +252,14 @@ function getFilterInDisplayTitle(filters: Partial, _: : undefined; } +function shouldDisplayFilter(numberOfFilters: number, isFeatureEnabled: boolean, optionalCondition = false): boolean { + return (numberOfFilters !== 0 || optionalCondition) && isFeatureEnabled; +} + +function isFeatureEnabledInPolicies(policies: OnyxCollection, featureName: PolicyFeatureName) { + return Object.values(policies ?? {}).some((policy) => isPolicyFeatureEnabled(policy, featureName)); +} + function AdvancedSearchFilters() { const {translate} = useLocalize(); const styles = useThemeStyles(); @@ -260,7 +269,6 @@ function AdvancedSearchFilters() { const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES); const [searchAdvancedFilters = {} as SearchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); const policyID = searchAdvancedFilters.policyID ?? '-1'; - const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST); const taxRates = getAllTaxRates(); const personalDetails = usePersonalDetails(); @@ -281,10 +289,17 @@ function AdvancedSearchFilters() { .map((policy) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy.id}`); const nonPersonalPolicyCategoryCount = Object.keys(allPolicyCategories).filter((policyCategoryId) => nonPersonalPolicyCategoryIds.includes(policyCategoryId)).length; - const shouldDisplayCategoryFilter = nonPersonalPolicyCategoryCount !== 0 || !!singlePolicyCategories; - const shouldDisplayTagFilter = tagListsUnpacked.length !== 0 || !!singlePolicyTagLists; - const shouldDisplayCardFilter = Object.keys(cardList).length !== 0; - const shouldDisplayTaxFilter = Object.keys(taxRates).length !== 0; + const areCategoriesEnabled = isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED); + const areTagsEnabled = isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED); + const areCardsEnabled = + isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED) || + isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED); + const areTaxEnabled = isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED); + + const shouldDisplayCategoryFilter = shouldDisplayFilter(nonPersonalPolicyCategoryCount, areCategoriesEnabled, !!singlePolicyCategories); + const shouldDisplayTagFilter = shouldDisplayFilter(tagListsUnpacked.length, areTagsEnabled, !!singlePolicyTagLists); + const shouldDisplayCardFilter = shouldDisplayFilter(Object.keys(cardList).length, areCardsEnabled); + const shouldDisplayTaxFilter = shouldDisplayFilter(Object.keys(taxRates).length, areTaxEnabled); let currentType = searchAdvancedFilters?.type ?? CONST.SEARCH.DATA_TYPES.EXPENSE; if (!Object.keys(typeFiltersKeys).includes(currentType)) { From 27cc80573eca9c0bb8170dec789032931a2cb680 Mon Sep 17 00:00:00 2001 From: sumo_slonik Date: Wed, 13 Nov 2024 17:08:09 +0100 Subject: [PATCH 3/4] remove unnecessary change --- src/libs/PolicyUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 80a816fd85ed..4592500e9250 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -483,7 +483,7 @@ function getTaxByID(policy: OnyxEntry, taxID: string): TaxRate | undefin function getAllTaxRatesNamesAndKeys(): Record { const allTaxRates: Record = {}; Object.values(allPolicies ?? {})?.forEach((policy) => { - if (!policy?.taxRates?.taxes || !policy?.tax?.trackingEnabled) { + if (!policy?.taxRates?.taxes) { return; } Object.entries(policy?.taxRates?.taxes).forEach(([taxRateKey, taxRate]) => { From 0e0a3dfe67bcfc68418706c75f0e4594be88a257 Mon Sep 17 00:00:00 2001 From: sumo_slonik Date: Fri, 15 Nov 2024 11:49:35 +0100 Subject: [PATCH 4/4] changes after Mateusz CR --- src/pages/Search/AdvancedSearchFilters.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index a1ac9bcba1b1..796e127dbbc0 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -29,6 +29,7 @@ import ROUTES from '@src/ROUTES'; import type {SearchAdvancedFiltersForm} from '@src/types/form'; import type {CardList, PersonalDetailsList, Policy, PolicyTagLists, Report} from '@src/types/onyx'; import type {PolicyFeatureName} from '@src/types/onyx/Policy'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; const baseFilterConfig = { date: { @@ -252,12 +253,15 @@ function getFilterInDisplayTitle(filters: Partial, _: : undefined; } -function shouldDisplayFilter(numberOfFilters: number, isFeatureEnabled: boolean, optionalCondition = false): boolean { - return (numberOfFilters !== 0 || optionalCondition) && isFeatureEnabled; +function shouldDisplayFilter(numberOfFilters: number, isFeatureEnabled: boolean, singlePolicyCondition = false): boolean { + return (numberOfFilters !== 0 || singlePolicyCondition) && isFeatureEnabled; } function isFeatureEnabledInPolicies(policies: OnyxCollection, featureName: PolicyFeatureName) { - return Object.values(policies ?? {}).some((policy) => isPolicyFeatureEnabled(policy, featureName)); + if (isEmptyObject(policies)) { + return false; + } + return Object.values(policies).some((policy) => isPolicyFeatureEnabled(policy, featureName)); } function AdvancedSearchFilters() {