Skip to content

Commit

Permalink
Move getPolicyIDFromNavigationState to PolicyUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBoman committed Mar 22, 2024
1 parent b71d2ad commit eb11d74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
11 changes: 1 addition & 10 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((resolve) => {
Expand Down Expand Up @@ -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<RootStackParamList>);
}

export default {
setShouldPopAllStateOnUP,
navigate,
Expand All @@ -387,7 +379,6 @@ export default {
closeFullScreen,
navigateWithSwitchPolicyID,
resetToHome,
getPolicyIDFromNavigationState,
};

export {navigationRef};
12 changes: 11 additions & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>;
type UnitRate = {rate: number};
Expand Down Expand Up @@ -297,6 +299,13 @@ function isPolicyFeatureEnabled(policy: OnyxEntry<Policy> | 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<RootStackParamList>);
}

export {
getActivePolicies,
hasAccountingConnections,
Expand Down Expand Up @@ -332,6 +341,7 @@ export {
hasTaxRateError,
getTaxByID,
hasPolicyCategoriesError,
getPolicyIDFromNavigationState,
};

export type {MemberEmailsToAccountIDs};
4 changes: 2 additions & 2 deletions src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down

0 comments on commit eb11d74

Please sign in to comment.