From fc1669c0204301b756981a4173a3cc602297494c Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Thu, 6 Oct 2022 15:06:51 +0530 Subject: [PATCH 1/5] updated code to include status of loading policy data --- src/libs/actions/App.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 265de152b3d5..5b8adcf6d67d 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -121,17 +121,35 @@ function openApp() { onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: true, - }], + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_POLICY_DATA, + value: true, + }, + ], successData: [{ onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: false, - }], + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_POLICY_DATA, + value: false, + }, + ], failureData: [{ onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: false, - }], + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_POLICY_DATA, + value: false, + }, + ], }); } From 264f9bc31a8d82eaf2be308f694d528df12afd64 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Mon, 10 Oct 2022 12:13:26 +0530 Subject: [PATCH 2/5] updated code to remove loading policy data flag for Welecome.js --- src/libs/actions/App.js | 15 --------------- src/libs/actions/Welcome.js | 12 +----------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 5b8adcf6d67d..9eba8a24fa19 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -122,33 +122,18 @@ function openApp() { key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: true, }, - { - onyxMethod: CONST.ONYX.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_POLICY_DATA, - value: true, - }, ], successData: [{ onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: false, }, - { - onyxMethod: CONST.ONYX.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_POLICY_DATA, - value: false, - }, ], failureData: [{ onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: false, }, - { - onyxMethod: CONST.ONYX.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_POLICY_DATA, - value: false, - }, ], }); } diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index 41c559093941..70ede6d9709d 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -17,7 +17,6 @@ let isReadyPromise = new Promise((resolve) => { let isFirstTimeNewExpensifyUser; let isLoadingReportData = true; -let isLoadingPolicyData = true; let email = ''; /** @@ -28,7 +27,7 @@ let email = ''; * - Whether we have loaded all reports the server knows about */ function checkOnReady() { - if (!_.isBoolean(isFirstTimeNewExpensifyUser) || isLoadingPolicyData || isLoadingReportData) { + if (!_.isBoolean(isFirstTimeNewExpensifyUser) || isLoadingReportData) { return; } @@ -53,15 +52,6 @@ Onyx.connect({ }, }); -Onyx.connect({ - key: ONYXKEYS.IS_LOADING_POLICY_DATA, - initWithStoredValues: false, - callback: (val) => { - isLoadingPolicyData = val; - checkOnReady(); - }, -}); - const allReports = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, From 6b08625f9f8d4d96d18cb2bb2175d03bfbc07bc3 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 12 Oct 2022 22:47:30 +0530 Subject: [PATCH 3/5] removed getPolicyList and key IS_LOADING_POLICY_DATA --- src/ONYXKEYS.js | 3 --- src/libs/actions/App.js | 9 +++------ src/libs/actions/Policy.js | 35 ----------------------------------- 3 files changed, 3 insertions(+), 44 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 0b1f45006fc2..21ff401c72c7 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -155,9 +155,6 @@ export default { // Is report data loading? IS_LOADING_REPORT_DATA: 'isLoadingReportData', - // Is policy data loading? - IS_LOADING_POLICY_DATA: 'isLoadingPolicyData', - // Is Keyboard shortcuts modal open? IS_SHORTCUTS_MODAL_OPEN: 'isShortcutsModalOpen', diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 9eba8a24fa19..265de152b3d5 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -121,20 +121,17 @@ function openApp() { onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: true, - }, - ], + }], successData: [{ onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: false, - }, - ], + }], failureData: [{ onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.IS_LOADING_REPORT_DATA, value: false, - }, - ], + }], }); } diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 6af4d574bcbb..0b8b4dcc1c4f 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -147,40 +147,6 @@ function deleteWorkspace(policyID) { } } -/** - * Fetches policy list from the API and saves a simplified version in Onyx, optionally creating a new policy first. - * - * More specifically, this action will: - * 1. Optionally create a new policy. - * 2. Fetch policy summaries. - * 3. Optionally navigate to the new policy. - * 4. Then fetch full policies. - * - * This way, we ensure that there's no race condition between creating the new policy and fetching existing ones, - * and we also don't have to wait for full policies to load before navigating to the new policy. - */ -function getPolicyList() { - Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, true); - DeprecatedAPI.GetPolicySummaryList() - .then((data) => { - if (data.jsonCode !== 200) { - Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false); - return; - } - - const policyCollection = _.reduce(data.policySummaryList, (memo, policy) => ({ - ...memo, - [`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: getSimplifiedPolicyObject(policy, false), - }), {}); - - if (!_.isEmpty(policyCollection)) { - updateAllPolicies(policyCollection); - } - - Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false); - }); -} - /** * @param {String} policyID */ @@ -937,7 +903,6 @@ function openWorkspaceInvitePage(policyID, clientMemberEmails) { } export { - getPolicyList, loadFullPolicy, removeMembers, addMembersToWorkspace, From 9aec997ca39dc5909bc5a1e389dab4b06c9a0c8e Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 12 Oct 2022 23:04:59 +0530 Subject: [PATCH 4/5] fixed linter --- src/libs/actions/Policy.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 0b8b4dcc1c4f..b1048ffbdd76 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -98,26 +98,6 @@ function updateLastAccessedWorkspace(policyID) { Onyx.set(ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID, policyID); } -/** - * 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 - */ -function updateAllPolicies(policyCollection) { - // Clear out locally cached policies that have been deleted (i.e. they exist locally but not in our new policy collection object) - _.each(allPolicies, (policy, key) => { - if (policyCollection[key]) { - return; - } - - Onyx.set(key, null); - }); - - // Set all the policies - _.each(policyCollection, (policyData, key) => { - Onyx.merge(key, {...policyData, alertMessage: '', errors: null}); - }); -} - /** * Delete the workspace * From 321990e3333032d351c2bcce2fafc14517e878ca Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Thu, 13 Oct 2022 05:31:22 +0530 Subject: [PATCH 5/5] fixed loading of reports in policy case --- src/libs/actions/Welcome.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index 70ede6d9709d..d1130b9450b2 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -67,7 +67,7 @@ Onyx.connect({ const allPolicies = {}; Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, + key: ONYXKEYS.COLLECTION.POLICY, callback: (val, key) => { if (!val || !key) { return;