From fadb29e884e70098d694302346e0de605c5c46f2 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 6 Dec 2023 12:55:20 +0530 Subject: [PATCH 1/4] delete transaction thread if only changelogs exist --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ed43569c360a..b1226fc9eabd 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1997,7 +1997,7 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView // STEP 2: Decide if we need to: // 1. Delete the transactionThread - delete if there are no visible comments in the thread // 2. Update the moneyRequestPreview to show [Deleted request] - update if the transactionThread exists AND it isn't being deleted - const shouldDeleteTransactionThread = transactionThreadID ? ReportActionsUtils.getLastVisibleMessage(transactionThreadID).lastMessageText.length === 0 : false; + const shouldDeleteTransactionThread = transactionThreadID ? lodashGet(reportAction, 'childVisibleActionCount', 0) === 0 : false; const shouldShowDeletedRequestMessage = transactionThreadID && !shouldDeleteTransactionThread; // STEP 3: Update the IOU reportAction and decide if the iouReport should be deleted. We delete the iouReport if there are no visible comments left in the report. From 5688c7b849876c7cf6f409c91bd73a6caae6a789 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Fri, 15 Dec 2023 10:49:23 +0530 Subject: [PATCH 2/4] unit test-money request deletion with changelogs --- tests/actions/IOUTest.js | 94 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 97c1bf35732f..c91419bbb60c 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -2236,6 +2236,86 @@ describe('actions/IOU', () => { expect(report).toBeFalsy(); }); + it('delete the transaction thread if there are only changelogs (i.e. MODIFIEDEXPENSE actions) in the thread', async () => { + // Given all promises are resolved + await waitForBatchedUpdates(); + jest.advanceTimersByTime(10); + + // Given a transaction thread + thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID); + + Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, + callback: (val) => (reportActions = val), + }); + + await waitForBatchedUpdates(); + + jest.advanceTimersByTime(10); + + // Given User logins from the participant accounts + const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs); + + // When Opening a thread report with the given details + Report.openReport(thread.reportID, userLogins, thread, createIOUAction.reportActionID); + await waitForBatchedUpdates(); + + // Then The iou action has the transaction report id as a child report ID + const allReportActions = await new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, + waitForCollectionCallback: true, + callback: (actions) => { + Onyx.disconnect(connectionID); + resolve(actions); + }, + }); + }); + const reportActionsForIOUReport = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.iouReportID}`]; + createIOUAction = _.find(reportActionsForIOUReport, (ra) => ra.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + expect(createIOUAction.childReportID).toBe(thread.reportID); + + await waitForBatchedUpdates(); + + jest.advanceTimersByTime(10); + IOU.editMoneyRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); + await waitForBatchedUpdates(); + + // Verify there are two actions (created + changelog) + expect(_.size(reportActions)).toBe(2); + + // Fetch the updated IOU Action from Onyx + await new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + waitForCollectionCallback: true, + callback: (reportActionsForReport) => { + Onyx.disconnect(connectionID); + createIOUAction = _.find(reportActionsForReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + resolve(); + }, + }); + }); + + // When Deleting a money request + IOU.deleteMoneyRequest(transaction.transactionID, createIOUAction, false); + await waitForBatchedUpdates(); + + // Then, the report for the given thread ID does not exist + const report = await new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT}${thread.reportID}`, + waitForCollectionCallback: true, + callback: (reportData) => { + Onyx.disconnect(connectionID); + resolve(reportData); + }, + }); + }); + + expect(report).toBeFalsy(); + }); + it('does not delete the transaction thread if there are visible comments in the thread', async () => { // Given initial environment is set up await waitForBatchedUpdates(); @@ -2367,6 +2447,20 @@ describe('actions/IOU', () => { Report.addComment(thread.reportID, 'Testing a comment'); await waitForBatchedUpdates(); + // Fetch the updated IOU Action from Onyx due to addition of comment to transaction thread. + // This needs to be fetched as `deleteMoneyRequest` depends on `childVisibleActionCount` in `createIOUAction`. + await new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + waitForCollectionCallback: true, + callback: (reportActionsForReport) => { + Onyx.disconnect(connectionID); + createIOUAction = _.find(reportActionsForReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + resolve(); + }, + }); + }); + let resultAction = _.find(reportActions, (ra) => ra.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT); reportActionID = resultAction.reportActionID; From 751e846fd408b89a17b324a9aa9cbf42265cea91 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Fri, 15 Dec 2023 16:29:41 +0530 Subject: [PATCH 3/4] offline update of childvisibleactioncount for task --- src/libs/actions/Task.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 5ed44fb5d983..01828815ddbd 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -14,6 +14,7 @@ import * as UserUtils from '@libs/UserUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import {isNotEmptyObject} from '@src/types/utils/EmptyObject'; import * as Report from './Report'; let currentUserEmail; @@ -179,6 +180,12 @@ function createTaskAndNavigate(parentReportID, title, description, assigneeEmail }, ); + // If needed, update optimistic data for parent report action of the parent report. + const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(parentReportID, currentTime, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + if (isNotEmptyObject(optimisticParentReportData)) { + optimisticData.push(optimisticParentReportData); + } + // FOR PARENT REPORT (SHARE DESTINATION) successData.push({ onyxMethod: Onyx.METHOD.MERGE, From 304ece8644534c1c767db0d676d76666b49e16d1 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 18 Dec 2023 13:07:06 +0530 Subject: [PATCH 4/4] reply count fix for cancellation of task --- src/libs/actions/Task.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index a2354d7074bd..4242b974390c 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -779,6 +779,19 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum }, ]; + // Update optimistic data for parent report action if the report is a child report and the task report has no visible child + const childVisibleActionCount = lodashGet(parentReportAction, 'childVisibleActionCount', 0); + if (childVisibleActionCount === 0) { + const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction( + parentReport.reportID, + parentReport.lastVisibleActionCreated || '', + CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + ); + if (isNotEmptyObject(optimisticParentReportData)) { + optimisticData.push(optimisticParentReportData); + } + } + const successData = [ { onyxMethod: Onyx.METHOD.MERGE,