diff --git a/package.json b/package.json index 881d15ce8128..35f0297a5a68 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand", "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", - "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=198 --cache --cache-location=node_modules/.cache/eslint", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=197 --cache --cache-location=node_modules/.cache/eslint", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "lint-watch": "npx eslint-watch --watch --changed", "shellcheck": "./scripts/shellCheck.sh", diff --git a/src/hooks/useSearchTypeMenuSections.ts b/src/hooks/useSearchTypeMenuSections.ts index 76e7e9d0acca..acc19195e138 100644 --- a/src/hooks/useSearchTypeMenuSections.ts +++ b/src/hooks/useSearchTypeMenuSections.ts @@ -38,11 +38,22 @@ const useSearchTypeMenuSections = () => { const {isOffline} = useNetwork(); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (policies) => mapOnyxCollectionItems(policies, policySelector), canBeMissing: true}); const [currentUserLoginAndAccountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => ({email: session?.email, accountID: session?.accountID}), canBeMissing: false}); + const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true}); const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true}); const typeMenuSections = useMemo( - () => createTypeMenuSections(currentUserLoginAndAccountID?.email, currentUserLoginAndAccountID?.accountID, cardFeedsByPolicy, defaultCardFeed, allPolicies, savedSearches, isOffline), - [currentUserLoginAndAccountID?.email, currentUserLoginAndAccountID?.accountID, cardFeedsByPolicy, defaultCardFeed, allPolicies, savedSearches, isOffline], + () => + createTypeMenuSections( + currentUserLoginAndAccountID?.email, + currentUserLoginAndAccountID?.accountID, + cardFeedsByPolicy, + defaultCardFeed, + allPolicies, + activePolicyID, + savedSearches, + isOffline, + ), + [currentUserLoginAndAccountID?.email, currentUserLoginAndAccountID?.accountID, cardFeedsByPolicy, defaultCardFeed, allPolicies, activePolicyID, savedSearches, isOffline], ); return {typeMenuSections}; diff --git a/src/libs/Firebase/types.ts b/src/libs/Firebase/types.ts index 2f6a8b42505e..560b2758f1ff 100644 --- a/src/libs/Firebase/types.ts +++ b/src/libs/Firebase/types.ts @@ -17,8 +17,6 @@ type PerfAttributes = { transactionViolationsLength: string; policiesLength: string; transactionsLength: string; - policyType: string; - policyRole: string; }; // TODO confirm which attributes are required for Firebase diff --git a/src/libs/Firebase/utils.ts b/src/libs/Firebase/utils.ts index 93b271cdb6b9..729eed25654c 100644 --- a/src/libs/Firebase/utils.ts +++ b/src/libs/Firebase/utils.ts @@ -1,6 +1,5 @@ // We have opted for `Onyx.connectWithoutView` here as this logic is strictly non-UI in nature. import Onyx from 'react-native-onyx'; -import {getActivePolicy} from '@libs/PolicyUtils'; import * as SessionUtils from '@libs/SessionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PerfAttributes} from './types'; @@ -60,7 +59,6 @@ Onyx.connectWithoutView({ function getAttributes(attributes?: T[]): Pick { const session = SessionUtils.getSession(); - const policy = getActivePolicy(); const allAttributes: PerfAttributes = { accountId: session?.accountID?.toString() ?? 'N/A', @@ -70,8 +68,6 @@ function getAttributes(attributes?: T[]): Pick

0) { diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index efce1707a02b..65a474fdc725 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -56,7 +56,6 @@ type ConnectionWithLastSyncData = { }; let allPolicies: OnyxCollection; -let activePolicyId: OnyxEntry; Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, @@ -64,11 +63,6 @@ Onyx.connect({ callback: (value) => (allPolicies = value), }); -Onyx.connect({ - key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, - callback: (value) => (activePolicyId = value), -}); - /** * Filter out the active policies, which will exclude policies with pending deletion * and policies the current user doesn't belong to. @@ -1354,12 +1348,6 @@ function getWorkflowApprovalsUnavailable(policy: OnyxEntry) { return policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL || !!policy?.errorFields?.approvalMode; } -function getActivePolicy(): OnyxEntry { - // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 - // eslint-disable-next-line deprecation/deprecation - return getPolicy(activePolicyId); -} - function getUserFriendlyWorkspaceType(workspaceType: ValueOf) { switch (workspaceType) { case CONST.POLICY.TYPE.CORPORATE: @@ -1647,7 +1635,6 @@ export { hasUnsupportedIntegration, getWorkflowApprovalsUnavailable, getNetSuiteImportCustomFieldLabel, - getActivePolicy, getUserFriendlyWorkspaceType, isPolicyAccessible, hasOtherControlWorkspaces, diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 7cb8a34dc27c..396092efabfb 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -70,7 +70,7 @@ import {translateLocal} from './Localize'; import Navigation from './Navigation/Navigation'; import Parser from './Parser'; import {getDisplayNameOrDefault} from './PersonalDetailsUtils'; -import {arePaymentsEnabled, canSendInvoice, getActivePolicy, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy, isPolicyPayer} from './PolicyUtils'; +import {arePaymentsEnabled, canSendInvoice, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy, isPolicyPayer} from './PolicyUtils'; import { getOriginalMessage, getReportActionHtml, @@ -1863,6 +1863,7 @@ function createTypeMenuSections( cardFeedsByPolicy: Record, defaultCardFeed: CardFeedForDisplay | undefined, policies: OnyxCollection, + activePolicyID: string | undefined, savedSearches: OnyxEntry, isOffline: boolean, ): SearchTypeMenuSection[] { @@ -1894,7 +1895,7 @@ function createTypeMenuSections( buttonText: 'report.newReport.createReport', buttonAction: () => { interceptAnonymousUser(() => { - const activePolicy = getActivePolicy(); + const activePolicy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`]; const personalDetails = getPersonalDetailsForAccountID(currentUserAccountID) as OnyxTypes.PersonalDetails; let workspaceIDForReportCreation: string | undefined; diff --git a/tests/unit/FirebaseUtilsTest.ts b/tests/unit/FirebaseUtilsTest.ts index efe273c0d6e1..0af89b256e22 100644 --- a/tests/unit/FirebaseUtilsTest.ts +++ b/tests/unit/FirebaseUtilsTest.ts @@ -11,8 +11,6 @@ describe('getAttributes', () => { 'policiesLength', 'transactionsLength', 'transactionViolationsLength', - 'policyType', - 'policyRole', ]; const checkAttributes = (attributes: Partial, expectedAttributes: Array>) => { diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index e9a46827de1c..e0d025f686d5 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1873,7 +1873,7 @@ describe('SearchUIUtils', () => { describe('Test createTypeMenuItems', () => { it('should return the default menu items', () => { - const menuItems = SearchUIUtils.createTypeMenuSections(undefined, undefined, {}, undefined, {}, {}, false) + const menuItems = SearchUIUtils.createTypeMenuSections(undefined, undefined, {}, undefined, {}, undefined, {}, false) .map((section) => section.menuItems) .flat(); @@ -1951,7 +1951,7 @@ describe('SearchUIUtils', () => { const mockSavedSearches = {}; - const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, mockSavedSearches, false); + const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, undefined, mockSavedSearches, false); const todoSection = sections.find((section) => section.translationPath === 'common.todo'); expect(todoSection).toBeDefined(); @@ -2001,7 +2001,7 @@ describe('SearchUIUtils', () => { const mockSavedSearches = {}; - const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, mockSavedSearches, false); + const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, undefined, mockSavedSearches, false); const accountingSection = sections.find((section) => section.translationPath === 'workspace.common.accounting'); expect(accountingSection).toBeDefined(); @@ -2030,7 +2030,7 @@ describe('SearchUIUtils', () => { }, }; - const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, {}, mockSavedSearches, false); + const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, {}, undefined, mockSavedSearches, false); const savedSection = sections.find((section) => section.translationPath === 'search.savedSearchesMenuItemTitle'); expect(savedSection).toBeDefined(); @@ -2039,7 +2039,7 @@ describe('SearchUIUtils', () => { it('should not show saved section when there are no saved searches', () => { const mockSavedSearches = {}; - const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, {}, mockSavedSearches, false); + const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, {}, undefined, mockSavedSearches, false); const savedSection = sections.find((section) => section.translationPath === 'search.savedSearchesMenuItemTitle'); expect(savedSection).toBeUndefined(); @@ -2061,6 +2061,7 @@ describe('SearchUIUtils', () => { {}, undefined, {}, + undefined, mockSavedSearches, false, // not offline ); @@ -2085,6 +2086,7 @@ describe('SearchUIUtils', () => { {}, undefined, {}, + undefined, mockSavedSearches, true, // offline ); @@ -2107,7 +2109,7 @@ describe('SearchUIUtils', () => { }, }; - const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, mockPolicies, {}, false); + const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, mockPolicies, undefined, {}, false); const todoSection = sections.find((section) => section.translationPath === 'common.todo'); expect(todoSection).toBeUndefined(); @@ -2133,6 +2135,7 @@ describe('SearchUIUtils', () => { {}, // no card feeds undefined, mockPolicies, + undefined, {}, false, ); @@ -2165,7 +2168,7 @@ describe('SearchUIUtils', () => { }, }; - const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, mockPolicies, {}, false); + const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, mockPolicies, undefined, {}, false); const accountingSection = sections.find((section) => section.translationPath === 'workspace.common.accounting'); expect(accountingSection).toBeDefined(); @@ -2190,7 +2193,7 @@ describe('SearchUIUtils', () => { }; const mockCardFeedsByPolicy: Record = {}; - const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, {}, false); + const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, undefined, {}, false); const accountingSection = sections.find((section) => section.translationPath === 'workspace.common.accounting'); expect(accountingSection).toBeDefined(); @@ -2199,7 +2202,7 @@ describe('SearchUIUtils', () => { }); it('should generate correct routes', () => { - const menuItems = SearchUIUtils.createTypeMenuSections(undefined, undefined, {}, undefined, {}, {}, false) + const menuItems = SearchUIUtils.createTypeMenuSections(undefined, undefined, {}, undefined, {}, undefined, {}, false) .map((section) => section.menuItems) .flat();