Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Only load full policies one-by-one as needed #6087

Merged
merged 19 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,13 @@ function GetIOUReport(parameters) {

/**
* @returns {Promise}
* @param {Array<String>} policyIDList
*/
function GetPolicyList() {
function GetPolicyList(policyIDList = []) {
const commandName = 'Get';
const parameters = {
returnValueList: 'policyList',
policyIDList,
};
return Network.post(commandName, parameters);
}
Expand Down
7 changes: 0 additions & 7 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
SettingsModalStackNavigator,
EnablePaymentsStackNavigator,
AddPersonalBankAccountModalStackNavigator,
WorkspaceInviteModalStackNavigator,
RequestCallModalStackNavigator,
ReportDetailsModalStackNavigator,
} from './ModalStackNavigators';
Expand Down Expand Up @@ -355,12 +354,6 @@ class AuthScreens extends React.Component {
component={AddPersonalBankAccountModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="WorkspaceInvite"
options={modalScreenOptions}
component={WorkspaceInviteModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="RequestCall"
options={modalScreenOptions}
Expand Down
16 changes: 6 additions & 10 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import IOURequestPage from '../../../pages/iou/IOURequestPage';
import IOUBillPage from '../../../pages/iou/IOUBillPage';
import IOUSendPage from '../../../pages/iou/IOUSendPage';
import IOUDetailsModal from '../../../pages/iou/IOUDetailsModal';
import SettingsInitialPage from '../../../pages/settings/InitialPage';
import SettingsInitialPage from '../../../pages/settings/InitialSettingsPage';
import SettingsProfilePage from '../../../pages/settings/Profile/ProfilePage';
import SettingsPreferencesPage from '../../../pages/settings/PreferencesPage';
import SettingsAboutPage from '../../../pages/settings/AboutPage';
Expand Down Expand Up @@ -55,9 +55,7 @@ function createModalStackNavigator(screens) {
const ModalStackNavigator = createStackNavigator();
return () => (
<ModalStackNavigator.Navigator
screenOptions={{
...defaultSubRouteOptions,
}}
screenOptions={defaultSubRouteOptions}
>
{_.map(screens, screen => (
<ModalStackNavigator.Screen
Expand Down Expand Up @@ -220,6 +218,10 @@ const SettingsModalStackNavigator = createModalStackNavigator([
Component: WorkspaceBankAccountPage,
name: 'Workspace_BankAccount',
},
{
Component: WorkspaceInvitePage,
name: 'Workspace_Invite',
},
{
Component: ReimbursementAccountPage,
name: 'ReimbursementAccount',
Expand All @@ -242,11 +244,6 @@ const ReimbursementAccountModalStackNavigator = createModalStackNavigator([{
name: 'ReimbursementAccount_Root',
}]);

const WorkspaceInviteModalStackNavigator = createModalStackNavigator([{
Component: WorkspaceInvitePage,
name: 'WorkspaceInvite_Root',
}]);

const RequestCallModalStackNavigator = createModalStackNavigator([{
Component: RequestCallPage,
name: 'RequestCall_Root',
Expand All @@ -267,6 +264,5 @@ export {
EnablePaymentsStackNavigator,
AddPersonalBankAccountModalStackNavigator,
ReimbursementAccountModalStackNavigator,
WorkspaceInviteModalStackNavigator,
RequestCallModalStackNavigator,
};
2 changes: 1 addition & 1 deletion src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function navigate(route = ROUTES.HOME) {
/**
* Dismisses a screen presented modally and returns us back to the previous view.
*
* @param {Boolean} shouldOpenDrawer
* @param {Boolean} [shouldOpenDrawer]
*/
function dismissModal(shouldOpenDrawer = false) {
if (!navigationRef.isReady()) {
Expand Down
8 changes: 3 additions & 5 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export default {
path: ROUTES.WORKSPACE_BANK_ACCOUNT,
exact: true,
},
Workspace_Invite: {
path: ROUTES.WORKSPACE_INVITE,
},
ReimbursementAccount: {
path: ROUTES.BANK_ACCOUNT,
exact: true,
Expand Down Expand Up @@ -169,11 +172,6 @@ export default {
IOU_Enable_Payments: ROUTES.IOU_ENABLE_PAYMENTS,
},
},
WorkspaceInvite: {
screens: {
WorkspaceInvite_Root: ROUTES.WORKSPACE_INVITE,
},
},
RequestCall: {
screens: {
RequestCall_Root: ROUTES.REQUEST_CALL,
Expand Down
66 changes: 33 additions & 33 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,29 @@ function getSimplifiedEmployeeList(employeeList) {
* Takes a full policy that is returned from the policyList and simplifies it so we are only storing
* the pieces of data that we need to in Onyx
*
* @param {Object} fullPolicy
* @param {String} fullPolicy.id
* @param {String} fullPolicy.name
* @param {String} fullPolicy.role
* @param {String} fullPolicy.type
* @param {String} fullPolicy.outputCurrency
* @param {Object} fullPolicy.value.employeeList
* @param {String} [fullPolicy.value.avatarURL]
* @param {Object} fullPolicyOrPolicySummary
* @param {String} fullPolicyOrPolicySummary.id
* @param {String} fullPolicyOrPolicySummary.name
* @param {String} fullPolicyOrPolicySummary.role
* @param {String} fullPolicyOrPolicySummary.type
* @param {String} fullPolicyOrPolicySummary.outputCurrency
* @param {String} [fullPolicyOrPolicySummary.value.avatarURL]
* @param {Object} [fullPolicyOrPolicySummary.value.employeeList]
* @returns {Object}
*/
function getSimplifiedPolicyObject(fullPolicy) {
function getSimplifiedPolicyObject(fullPolicyOrPolicySummary) {
return {
id: fullPolicy.id,
name: fullPolicy.name,
role: fullPolicy.role,
type: fullPolicy.type,
owner: fullPolicy.owner,
outputCurrency: fullPolicy.outputCurrency,
employeeList: getSimplifiedEmployeeList(lodashGet(fullPolicy, 'value.employeeList')),
avatarURL: lodashGet(fullPolicy, 'value.avatarURL', ''),
id: fullPolicyOrPolicySummary.id,
name: fullPolicyOrPolicySummary.name,
role: fullPolicyOrPolicySummary.role,
type: fullPolicyOrPolicySummary.type,
owner: fullPolicyOrPolicySummary.owner,
outputCurrency: fullPolicyOrPolicySummary.outputCurrency,
avatarURL: fullPolicyOrPolicySummary.avatarURL || '',
employeeList: getSimplifiedEmployeeList(lodashGet(fullPolicyOrPolicySummary, 'value.employeeList')),
};
}

/**
* @param {Array<Object>} policyList
* @returns {Object}
*/
function transformPolicyListToOnyxCollection(policyList) {
return _.reduce(policyList, (memo, policy) => ({
...memo,
[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: getSimplifiedPolicyObject(policy),
}), {});
}

/**
* Used to update ALL of the policies at once. If a policy is present locally, but not in the policies object passed here it will be removed.
* @param {Object} policyCollection - object of policy key and partial policy object
Expand Down Expand Up @@ -159,21 +148,31 @@ function getPolicyList(shouldCreateNewPolicy = false) {
})
.then((data) => {
if (data.jsonCode === 200) {
const policyDataToStore = transformPolicyListToOnyxCollection(data.policySummaryList || []);
const policyDataToStore = _.reduce(data.policySummaryList, (memo, policy) => ({
...memo,
[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: getSimplifiedPolicyObject(policy),
}), {});
updateAllPolicies(policyDataToStore);
}

if (shouldCreateNewPolicy) {
Navigation.dismissModal();
Navigation.navigate(newPolicyID ? ROUTES.getWorkspaceInitialRoute(newPolicyID) : ROUTES.HOME);
}
});
}

return API.GetPolicyList();
})
/**
* @param {String} policyID
*/
function loadFullPolicy(policyID) {
API.GetPolicyList([policyID])
.then((data) => {
if (data.jsonCode === 200) {
const policyDataToStore = transformPolicyListToOnyxCollection(data.policyList || []);
updateAllPolicies(policyDataToStore);
const policy = data.policyList[0] || {};
if (policy.id) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`, getSimplifiedPolicyObject(policy));
}
}
});
}
Expand Down Expand Up @@ -356,6 +355,7 @@ function hideWorkspaceAlertMessage(policyID) {

export {
getPolicyList,
loadFullPolicy,
removeMembers,
invite,
isAdminOfFreePolicy,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/workspace/WorkspaceBankAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ROUTES from '../../ROUTES';
import reimbursementAccountPropTypes from '../ReimbursementAccount/reimbursementAccountPropTypes';
import WorkspaceSection from './WorkspaceSection';
import WorkspaceResetBankAccountModal from './WorkspaceResetBankAccountModal';
import withFullPolicy from './withFullPolicy';

const propTypes = {
/** ACH data for the withdrawal account actively being set up */
Expand Down Expand Up @@ -125,6 +126,7 @@ WorkspaceBankAccountPage.defaultProps = defaultProps;

export default compose(
withLocalize,
withFullPolicy,
withOnyx({
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/workspace/WorkspaceInitialPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import Avatar from '../../components/Avatar';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import withFullPolicy from './withFullPolicy';

const propTypes = {
/** Whether the current screen is focused. */
Expand Down Expand Up @@ -206,6 +207,7 @@ export default compose(
withLocalize,
withWindowDimensions,
withNavigationFocus,
withFullPolicy,
withOnyx({
policy: {
key: (props) => {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CONST, {EXPENSIFY_EMAILS} from '../../CONST';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import {openExternalLink} from '../../libs/actions/Link';
import Text from '../../components/Text';
import withFullPolicy from './withFullPolicy';

const personalDetailsPropTypes = PropTypes.shape({
/** The login of the person (either email or phone number) */
Expand Down Expand Up @@ -350,6 +351,7 @@ WorkspaceInvitePage.defaultProps = defaultProps;

export default compose(
withLocalize,
withFullPolicy,
withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
Expand Down
5 changes: 4 additions & 1 deletion src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/
import OptionRow from '../home/sidebar/OptionRow';
import CheckboxWithTooltip from '../../components/CheckboxWithTooltip';
import Hoverable from '../../components/Hoverable';
import withFullPolicy from './withFullPolicy';

const propTypes = {
...withLocalizePropTypes,
Expand Down Expand Up @@ -72,6 +73,7 @@ class WorkspaceMembersPage extends React.Component {
};

this.renderItem = this.renderItem.bind(this);
this.inviteUser = this.inviteUser.bind(this);
this.addUser = this.addUser.bind(this);
this.removeUser = this.removeUser.bind(this);
this.askForConfirmationToRemove = this.askForConfirmationToRemove.bind(this);
Expand Down Expand Up @@ -284,7 +286,7 @@ class WorkspaceMembersPage extends React.Component {
small
success
text={this.props.translate('common.invite')}
onPress={() => this.inviteUser()}
onPress={this.inviteUser}
/>
<Button
small
Expand Down Expand Up @@ -328,6 +330,7 @@ WorkspaceMembersPage.defaultProps = defaultProps;
export default compose(
withLocalize,
withWindowDimensions,
withFullPolicy,
withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/workspace/WorkspaceSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ExpensiTextInput from '../../components/ExpensiTextInput';
import FixedFooter from '../../components/FixedFooter';
import WorkspacePageWithSections from './WorkspacePageWithSections';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import withFullPolicy from './withFullPolicy';

const propTypes = {
/** List of betas */
Expand Down Expand Up @@ -200,6 +201,7 @@ WorkspaceSettingsPage.propTypes = propTypes;
WorkspaceSettingsPage.defaultProps = defaultProps;

export default compose(
withFullPolicy,
withOnyx({
betas: {
key: ONYXKEYS.BETAS,
Expand Down
7 changes: 6 additions & 1 deletion src/pages/workspace/bills/WorkspaceBillsPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import compose from '../../../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import withFullPolicy from '../withFullPolicy';
import WorkspaceBillsNoVBAView from './WorkspaceBillsNoVBAView';
import WorkspaceBillsVBAView from './WorkspaceBillsVBAView';
import WorkspacePageWithSections from '../WorkspacePageWithSections';
Expand Down Expand Up @@ -37,4 +39,7 @@ const WorkspaceBillsPage = ({translate, route}) => (

WorkspaceBillsPage.propTypes = propTypes;
WorkspaceBillsPage.displayName = 'WorkspaceBillsPage';
export default withLocalize(WorkspaceBillsPage);
export default compose(
withLocalize,
withFullPolicy,
)(WorkspaceBillsPage);
7 changes: 6 additions & 1 deletion src/pages/workspace/card/WorkspaceCardPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import compose from '../../../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import withFullPolicy from '../withFullPolicy';
import WorkspaceCardNoVBAView from './WorkspaceCardNoVBAView';
import WorkspaceCardVBANoECardView from './WorkspaceCardVBANoECardView';
import WorkspaceCardVBAWithECardView from './WorkspaceCardVBAWithECardView';
Expand Down Expand Up @@ -45,4 +47,7 @@ const WorkspaceCardPage = ({translate, route}) => (
WorkspaceCardPage.propTypes = propTypes;
WorkspaceCardPage.displayName = 'WorkspaceCardPage';

export default withLocalize(WorkspaceCardPage);
export default compose(
withLocalize,
withFullPolicy,
)(WorkspaceCardPage);
7 changes: 6 additions & 1 deletion src/pages/workspace/invoices/WorkspaceInvoicesPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import compose from '../../../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import withFullPolicy from '../withFullPolicy';
import WorkspacePageWithSections from '../WorkspacePageWithSections';
import WorkspaceInvoicesNoVBAView from './WorkspaceInvoicesNoVBAView';
import WorkspaceInvoicesVBAView from './WorkspaceInvoicesVBAView';
Expand Down Expand Up @@ -38,4 +40,7 @@ const WorkspaceInvoicesPage = ({translate, route}) => (
WorkspaceInvoicesPage.propTypes = propTypes;
WorkspaceInvoicesPage.displayName = 'WorkspaceInvoicesPage';

export default withLocalize(WorkspaceInvoicesPage);
export default compose(
withLocalize,
withFullPolicy,
)(WorkspaceInvoicesPage);
7 changes: 6 additions & 1 deletion src/pages/workspace/reimburse/WorkspaceReimbursePage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import compose from '../../../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import withFullPolicy from '../withFullPolicy';
import WorkspaceReimburseNoVBAView from './WorkspaceReimburseNoVBAView';
import WorkspaceReimburseVBAView from './WorkspaceReimburseVBAView';
import WorkspacePageWithSections from '../WorkspacePageWithSections';
Expand Down Expand Up @@ -38,4 +40,7 @@ const WorkspaceReimbursePage = ({translate, route}) => (
WorkspaceReimbursePage.propTypes = propTypes;
WorkspaceReimbursePage.displayName = 'WorkspaceReimbursePage';

export default withLocalize(WorkspaceReimbursePage);
export default compose(
withLocalize,
withFullPolicy,
)(WorkspaceReimbursePage);
Loading