Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,14 @@ function getChatByParticipants(newParticipantList) {
});
}

/**
* @param {String} policyID
* @returns {Array}
*/
function getAllPolicyReports(policyID) {
return _.filter(allReports, report => report && report.policyID === policyID);
}

/**
* Returns true if Chronos is one of the chat participants (1:1)
* @param {Object} report
Expand Down Expand Up @@ -1256,6 +1264,7 @@ export {
buildOptimisticReportAction,
shouldReportBeInOptionList,
getChatByParticipants,
getAllPolicyReports,
getIOUReportActionMessage,
getDisplayNameForParticipant,
isIOUReport,
Expand Down
14 changes: 13 additions & 1 deletion src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ Onyx.connect({
if (!key) {
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) 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, '');
Comment thread
tgolen marked this conversation as resolved.
const policyReports = ReportUtils.getAllPolicyReports(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;
}
Expand Down