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

On workspace delete, do cleanup / cascade delete #14379

Merged
merged 5 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 getPolicyReports(policyID) {
s77rt marked this conversation as resolved.
Show resolved Hide resolved
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,
getPolicyReports,
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) alognside removing any draft comments
// More info: https://github.com/Expensify/App/issues/14260
s77rt marked this conversation as resolved.
Show resolved Hide resolved
const policyID = key.replace(ONYXKEYS.COLLECTION.POLICY, '');
tgolen marked this conversation as resolved.
Show resolved Hide resolved
const policyReports = ReportUtils.getPolicyReports(policyID);
s77rt marked this conversation as resolved.
Show resolved Hide resolved
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