From a61f2aac16c18122e30f3b092688e3bada20724e Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Tue, 17 Jan 2023 22:43:13 +0100 Subject: [PATCH 1/5] On workspace delete, do cleanup / cascade delete --- src/libs/ReportUtils.js | 10 ++++++++++ src/libs/actions/Policy.js | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 45b9319a430a..7e60383db98f 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1182,6 +1182,15 @@ function getChatByParticipants(newParticipantList) { }); } +/** + * Get policy reports + * @param {String} policyID + * @returns {Array} + */ +function getPolicyReports(policyID) { + return _.filter(allReports, report => report && report.policyID === policyID); +} + /** * Returns true if Chronos is one of the chat participants (1:1) * @param {Object} report @@ -1256,6 +1265,7 @@ export { buildOptimisticReportAction, shouldReportBeInOptionList, getChatByParticipants, + getPolicyReports, getIOUReportActionMessage, getDisplayNameForParticipant, isIOUReport, diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 5a2de0e7e1f6..b895a5583edc 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -22,8 +22,17 @@ Onyx.connect({ if (!key) { return; } - if (val === null || val === undefined) { + const policyID = key.replace(ONYXKEYS.COLLECTION.POLICY, ''); + const policyReports = ReportUtils.getPolicyReports(policyID); + const cleanUpMergeQueries = {}; + const cleanUpSetQueries = {}; + _.each(policyReports, ({reportID}) => { + cleanUpMergeQueries[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] = {hasDraft: false}; + cleanUpSetQueries[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`] = null; + }); + Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, cleanUpMergeQueries); + Onyx.multiSet(cleanUpSetQueries); delete allPolicies[key]; return; } From 2f4ee7f8e0e0c349029d4cac611008556b0bb4ae Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 18 Jan 2023 18:12:53 +0100 Subject: [PATCH 2/5] Update src/libs/ReportUtils.js Co-authored-by: Tim Golen --- src/libs/ReportUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7e60383db98f..bf34e53b1819 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1183,7 +1183,6 @@ function getChatByParticipants(newParticipantList) { } /** - * Get policy reports * @param {String} policyID * @returns {Array} */ From 6fd023ce01b10bb7f969446c4b1d56933e8e7f24 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 18 Jan 2023 18:41:47 +0100 Subject: [PATCH 3/5] Update Policy.js --- src/libs/actions/Policy.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index b895a5583edc..aba47ecba0fe 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -23,6 +23,9 @@ Onyx.connect({ return; } if (val === null || val === undefined) { + // If we are deleting a policy, we have to check every report linked to that policy + // and unset the draft indicator (pencil icon) alognside removing any draft comments + // More info: https://github.com/Expensify/App/issues/14260 const policyID = key.replace(ONYXKEYS.COLLECTION.POLICY, ''); const policyReports = ReportUtils.getPolicyReports(policyID); const cleanUpMergeQueries = {}; From 39b212de5302714e0941dae116d2337cd59ad632 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 18 Jan 2023 19:08:16 +0100 Subject: [PATCH 4/5] Update src/libs/actions/Policy.js Co-authored-by: Tim Golen --- src/libs/actions/Policy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index aba47ecba0fe..c9aef8c1600c 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -24,7 +24,7 @@ Onyx.connect({ } if (val === null || val === undefined) { // If we are deleting a policy, we have to check every report linked to that policy - // and unset the draft indicator (pencil icon) alognside removing any draft comments + // and unset the draft indicator (pencil icon) alongside removing any draft comments. Clearing these values will keep the newly archived chats from being displayed in the LHN. // More info: https://github.com/Expensify/App/issues/14260 const policyID = key.replace(ONYXKEYS.COLLECTION.POLICY, ''); const policyReports = ReportUtils.getPolicyReports(policyID); From 787967f576d0669a66f29900c223b833d22309b9 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Thu, 19 Jan 2023 00:48:09 +0100 Subject: [PATCH 5/5] renamed getPolicyReports to getAllPolicyReports --- src/libs/ReportUtils.js | 4 ++-- src/libs/actions/Policy.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index bf34e53b1819..359582b7977c 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1186,7 +1186,7 @@ function getChatByParticipants(newParticipantList) { * @param {String} policyID * @returns {Array} */ -function getPolicyReports(policyID) { +function getAllPolicyReports(policyID) { return _.filter(allReports, report => report && report.policyID === policyID); } @@ -1264,7 +1264,7 @@ export { buildOptimisticReportAction, shouldReportBeInOptionList, getChatByParticipants, - getPolicyReports, + getAllPolicyReports, getIOUReportActionMessage, getDisplayNameForParticipant, isIOUReport, diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index c9aef8c1600c..58c70231e29d 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -27,7 +27,7 @@ Onyx.connect({ // and unset the draft indicator (pencil icon) alongside removing any draft comments. Clearing these values will keep the newly archived chats from being displayed in the LHN. // More info: https://github.com/Expensify/App/issues/14260 const policyID = key.replace(ONYXKEYS.COLLECTION.POLICY, ''); - const policyReports = ReportUtils.getPolicyReports(policyID); + const policyReports = ReportUtils.getAllPolicyReports(policyID); const cleanUpMergeQueries = {}; const cleanUpSetQueries = {}; _.each(policyReports, ({reportID}) => {