From eb11d74f2ca7fea0cbb2dab78a34a5bb495345da Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 22 Mar 2024 16:26:52 +0100 Subject: [PATCH] Move getPolicyIDFromNavigationState to PolicyUtils --- src/libs/Navigation/Navigation.ts | 11 +---------- src/libs/PolicyUtils.ts | 12 +++++++++++- .../home/sidebar/SidebarScreen/BaseSidebarScreen.js | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index f6d871724291..d57d0272738b 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -13,14 +13,13 @@ import type {Report} from '@src/types/onyx'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import originalDismissModal from './dismissModal'; import originalDismissModalWithReport from './dismissModalWithReport'; -import getPolicyIDFromState from './getPolicyIDFromState'; import originalGetTopmostReportActionId from './getTopmostReportActionID'; import originalGetTopmostReportId from './getTopmostReportId'; import linkingConfig from './linkingConfig'; import linkTo from './linkTo'; import navigationRef from './navigationRef'; import switchPolicyID from './switchPolicyID'; -import type {NavigationStateRoute, RootStackParamList, State, StateOrRoute, SwitchPolicyIDParams} from './types'; +import type {NavigationStateRoute, State, StateOrRoute, SwitchPolicyIDParams} from './types'; let resolveNavigationIsReadyPromise: () => void; const navigationIsReadyPromise = new Promise((resolve) => { @@ -360,13 +359,6 @@ function navigateWithSwitchPolicyID(params: SwitchPolicyIDParams) { return switchPolicyID(navigationRef.current, params); } -/** - * Returns the currently selected policy ID stored in the navigation state. - */ -function getPolicyIDFromNavigationState() { - return getPolicyIDFromState(navigationRef.getRootState() as State); -} - export default { setShouldPopAllStateOnUP, navigate, @@ -387,7 +379,6 @@ export default { closeFullScreen, navigateWithSwitchPolicyID, resetToHome, - getPolicyIDFromNavigationState, }; export {navigationRef}; diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 7717513d3f59..687f39fdf7c5 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -8,7 +8,9 @@ import type {PersonalDetailsList, Policy, PolicyCategories, PolicyMembers, Polic import type {PolicyFeatureName} from '@src/types/onyx/Policy'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import Navigation from './Navigation/Navigation'; +import getPolicyIDFromState from './Navigation/getPolicyIDFromState'; +import Navigation, {navigationRef} from './Navigation/Navigation'; +import type {RootStackParamList, State} from './Navigation/types'; type MemberEmailsToAccountIDs = Record; type UnitRate = {rate: number}; @@ -297,6 +299,13 @@ function isPolicyFeatureEnabled(policy: OnyxEntry | EmptyObject, feature return Boolean(policy?.[featureName]); } +/** + * Get the currently selected policy ID stored in the navigation state. + */ +function getPolicyIDFromNavigationState() { + return getPolicyIDFromState(navigationRef.getRootState() as State); +} + export { getActivePolicies, hasAccountingConnections, @@ -332,6 +341,7 @@ export { hasTaxRateError, getTaxByID, hasPolicyCategoriesError, + getPolicyIDFromNavigationState, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js index 9dafeb796fb2..d34f821b4b9b 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js @@ -4,8 +4,8 @@ import ScreenWrapper from '@components/ScreenWrapper'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Browser from '@libs/Browser'; import TopBar from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar'; -import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; +import {getPolicyIDFromNavigationState} from '@libs/PolicyUtils'; import SidebarLinksData from '@pages/home/sidebar/SidebarLinksData'; import Timing from '@userActions/Timing'; import CONST from '@src/CONST'; @@ -21,7 +21,7 @@ const startTimer = () => { function BaseSidebarScreen(props) { const styles = useThemeStyles(); - const activeWorkspaceID = Navigation.getPolicyIDFromNavigationState(); + const activeWorkspaceID = getPolicyIDFromNavigationState(); useEffect(() => { Performance.markStart(CONST.TIMING.SIDEBAR_LOADED); Timing.start(CONST.TIMING.SIDEBAR_LOADED, true);