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

Remove optimistic CLOSED actions on success #39008

Merged
merged 5 commits into from
Mar 26, 2024
Merged
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
19 changes: 15 additions & 4 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ function deleteWorkspace(policyID: string, policyName: string) {
const reportsToArchive = Object.values(allReports ?? {}).filter(
(report) => report?.policyID === policyID && (ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isTaskReport(report)),
);
const finallyData: OnyxUpdate[] = [];
reportsToArchive.forEach((report) => {
const {reportID, ownerAccountID} = report ?? {};
optimisticData.push({
Expand Down Expand Up @@ -369,12 +370,22 @@ function deleteWorkspace(policyID: string, policyName: string) {
emailClosingReport = allPersonalDetails?.[ownerAccountID]?.login ?? '';
}
const optimisticClosedReportAction = ReportUtils.buildOptimisticClosedReportAction(emailClosingReport, policyName, CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED);
const optimisticReportActions: Record<string, ReportAction> = {};
optimisticReportActions[optimisticClosedReportAction.reportActionID] = optimisticClosedReportAction as ReportAction;
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: optimisticReportActions,
value: {
[optimisticClosedReportAction.reportActionID]: optimisticClosedReportAction as ReportAction,
},
});

// We are temporarily adding this workaround because 'DeleteWorkspace' doesn't
// support receiving the optimistic reportActions' ids for the moment.
finallyData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[optimisticClosedReportAction.reportActionID]: null,
},
});
});

Expand Down Expand Up @@ -406,7 +417,7 @@ function deleteWorkspace(policyID: string, policyName: string) {

const params: DeleteWorkspaceParams = {policyID};

API.write(WRITE_COMMANDS.DELETE_WORKSPACE, params, {optimisticData, failureData});
API.write(WRITE_COMMANDS.DELETE_WORKSPACE, params, {optimisticData, finallyData, failureData});

// Reset the lastAccessedWorkspacePolicyID
if (policyID === lastAccessedWorkspacePolicyID) {
Expand Down
Loading