Skip to content

Commit f79441b

Browse files
committed
Use route.name instead of route.path
1 parent ff64eb0 commit f79441b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/pages/workspace/withFullPolicy.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import _ from 'underscore';
22
import lodashGet from 'lodash/get';
33
import React from 'react';
44
import PropTypes from 'prop-types';
5+
import Str from 'expensify-common/lib/str';
56
import {withOnyx} from 'react-native-onyx';
67
import {useNavigationState} from '@react-navigation/native';
78
import CONST from '../../CONST';
89
import getComponentDisplayName from '../../libs/getComponentDisplayName';
910
import * as Policy from '../../libs/actions/Policy';
1011
import ONYXKEYS from '../../ONYXKEYS';
1112

12-
let previousRoute = '';
13+
let previousRouteName = '';
14+
let previousRoutePolicyID = '';
1315

1416
/**
1517
* @param {Object} route
@@ -19,6 +21,19 @@ function getPolicyIDFromRoute(route) {
1921
return lodashGet(route, 'params.policyID', '');
2022
}
2123

24+
/**
25+
* @param {String} routeName
26+
* @param {String} policyID
27+
* @returns {Boolean}
28+
*/
29+
function isPreviousRouteInSameWorkspace(routeName, policyID) {
30+
return (
31+
Str.startsWith(routeName, 'Workspace')
32+
&& Str.startsWith(previousRouteName, 'Workspace')
33+
&& policyID === previousRoutePolicyID
34+
);
35+
}
36+
2237
const fullPolicyPropTypes = {
2338
/** The full policy object for the current route (as opposed to the policy summary object) */
2439
policy: PropTypes.shape({
@@ -74,11 +89,12 @@ export default function (WrappedComponent) {
7489
const currentRoute = _.last(useNavigationState(state => state.routes || []));
7590
const policyID = getPolicyIDFromRoute(currentRoute);
7691

77-
if (_.isString(policyID) && !previousRoute.includes(policyID)) {
92+
if (_.isString(policyID) && !_.isEmpty(policyID) && !isPreviousRouteInSameWorkspace(currentRoute.name, policyID)) {
7893
Policy.loadFullPolicy(policyID);
7994
}
8095

81-
previousRoute = lodashGet(currentRoute, 'path', '');
96+
previousRouteName = currentRoute.name;
97+
previousRoutePolicyID = policyID;
8298

8399
const rest = _.omit(props, ['forwardedRef', 'policy']);
84100
return (

0 commit comments

Comments
 (0)