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

fix: clear duplicated report data #45295

Merged
merged 3 commits into from
Jul 15, 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
33 changes: 29 additions & 4 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ Onyx.connect({
callback: (val) => (quickAction = val),
});

let allReportDraftComments: Record<string, string | undefined> = {};

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT,
waitForCollectionCallback: true,
callback: (value) => (allReportDraftComments = value),
});

registerPaginationConfig({
initialCommand: WRITE_COMMANDS.OPEN_REPORT,
previousCommand: READ_COMMANDS.GET_OLDER_ACTIONS,
Expand Down Expand Up @@ -1321,6 +1329,7 @@ function handleReportChanged(report: OnyxEntry<Report>) {
if (report?.reportID && report.preexistingReportID) {
let callback = () => {
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to clear the REPORT_DRAFT_COMMENT of report.reportID as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, null);
};
// Only re-route them if they are still looking at the optimistically created report
if (Navigation.getActiveRoute().includes(`/r/${report.reportID}`)) {
Expand All @@ -1329,11 +1338,27 @@ function handleReportChanged(report: OnyxEntry<Report>) {
currCallback();
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID ?? '-1'), CONST.NAVIGATION.TYPE.UP);
};

// The report screen will listen to this event and transfer the draft comment to the existing report
// This will allow the newest draft comment to be transferred to the existing report
DeviceEventEmitter.emit(`switchToPreExistingReport_${report.reportID}`, {
preexistingReportID: report.preexistingReportID,
callback,
});

return;
}
DeviceEventEmitter.emit(`switchToPreExistingReport_${report.reportID}`, {
preexistingReportID: report.preexistingReportID,
callback,
});

// In case the user is not on the report screen, we will transfer the report draft comment directly to the existing report
// after that clear the optimistically created report
const draftReportComment = allReportDraftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`];
if (!draftReportComment) {
callback();
return;
}

saveReportDraftComment(report.preexistingReportID ?? '-1', draftReportComment, callback);

return;
}

Expand Down
Loading