From 0cb5c216dad8178264237165db218f1f060d9d2c Mon Sep 17 00:00:00 2001 From: someone-here Date: Mon, 25 Sep 2023 16:02:36 +0530 Subject: [PATCH 1/2] Multiple task action replies shown --- src/libs/ReportActionsUtils.js | 6 ++-- src/libs/ReportUtils.js | 10 +++---- src/libs/actions/Task.js | 52 ++++++++++++++++++---------------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 19b0513b7e41..7f95a9a0f856 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -138,8 +138,8 @@ function getParentReportAction(report, allReportActionsParam = undefined) { * @param {String} parentReportID * @returns {Object} */ -function getParentReportActionInReport(childReportID, parentReportID) { - return _.find(allReportActions[parentReportID], (reportAction) => reportAction && `${reportAction.childReportID}` === `${childReportID}`); +function getParentReportActionsInReport(childReportID, parentReportID) { + return _.filter(allReportActions[parentReportID], (reportAction) => reportAction && `${reportAction.childReportID}` === `${childReportID}`); } /** @@ -674,7 +674,7 @@ export { getReportPreviewAction, isCreatedTaskReportAction, getParentReportAction, - getParentReportActionInReport, + getParentReportActionsInReport, isTransactionThread, isSentMoneyReportAction, isDeletedParentAction, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index fbc6f6a73033..d3d0451bbd70 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3362,20 +3362,20 @@ function isReportDataReady() { * @param {Object} taskReport * @returns {Object} */ -function getTaskParentReportActionIDInAssigneeReport(taskReport) { +function getTaskParentReportActionIDsInAssigneeReport(taskReport) { const assigneeChatReportID = lodashGet(getChatByParticipants(isReportManager(taskReport) ? [taskReport.ownerAccountID] : [taskReport.managerID]), 'reportID'); if (!assigneeChatReportID || assigneeChatReportID === taskReport.parentReportID) { return {}; } - const clonedParentReportActionID = lodashGet(ReportActionsUtils.getParentReportActionInReport(taskReport.reportID, assigneeChatReportID), 'reportActionID'); - if (!clonedParentReportActionID) { + const clonedParentReportActionIDs = _.map(ReportActionsUtils.getParentReportActionsInReport(taskReport.reportID, assigneeChatReportID), (a) => lodashGet(a, 'reportActionID', 0)); + if (!clonedParentReportActionIDs) { return {}; } return { reportID: assigneeChatReportID, - reportActionID: clonedParentReportActionID, + reportActionIDs: clonedParentReportActionIDs, }; } @@ -3723,7 +3723,7 @@ export { getBankAccountRoute, getParentReport, getRootParentReport, - getTaskParentReportActionIDInAssigneeReport, + getTaskParentReportActionIDsInAssigneeReport, getReportPreviewMessage, getModifiedExpenseMessage, shouldDisableWriteActions, diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 963bfebb7eb2..1dfdcad04aeb 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -276,18 +276,20 @@ function completeTask(taskReport, taskTitle) { // Multiple report actions can link to the same child. Both share destination (task parent) and assignee report link to the same report action. // We need to find and update the other parent report action (in assignee report). More info https://github.com/Expensify/App/issues/23920#issuecomment-1663092717 - const assigneeReportAction = ReportUtils.getTaskParentReportActionIDInAssigneeReport(taskReport); - if (!_.isEmpty(assigneeReportAction)) { - const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( - taskReportID, - completedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - assigneeReportAction.reportID, - assigneeReportAction.reportActionID, - ); - if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { - optimisticData.push(optimisticDataForClonedParentReportAction); - } + const assigneeReportActions = ReportUtils.getTaskParentReportActionIDsInAssigneeReport(taskReport); + if (!_.isEmpty(assigneeReportActions)) { + _.forEach(assigneeReportActions.reportActionIDs, (reportActionID) => { + const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( + taskReportID, + completedTaskReportAction.created, + CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + assigneeReportActions.reportID, + reportActionID, + ); + if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { + optimisticData.push(optimisticDataForClonedParentReportAction); + } + }); } API.write( @@ -363,18 +365,20 @@ function reopenTask(taskReport, taskTitle) { // Multiple report actions can link to the same child. Both share destination (task parent) and assignee report link to the same report action. // We need to find and update the other parent report action (in assignee report). More info https://github.com/Expensify/App/issues/23920#issuecomment-1663092717 - const assigneeReportAction = ReportUtils.getTaskParentReportActionIDInAssigneeReport(taskReport); - if (!_.isEmpty(assigneeReportAction)) { - const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( - taskReportID, - reopenedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - assigneeReportAction.reportID, - assigneeReportAction.reportActionID, - ); - if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { - optimisticData.push(optimisticDataForClonedParentReportAction); - } + const assigneeReportActions = ReportUtils.getTaskParentReportActionIDsInAssigneeReport(taskReport); + if (!_.isEmpty(assigneeReportActions)) { + _.forEach(assigneeReportActions.reportActionIDs, (reportActionID) => { + const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( + taskReportID, + reopenedTaskReportAction.created, + CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + assigneeReportActions.reportID, + reportActionID, + ); + if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { + optimisticData.push(optimisticDataForClonedParentReportAction); + } + }); } API.write( From d78e12c5ffa3dfc1f21fe177bcbe15c1a90737dc Mon Sep 17 00:00:00 2001 From: someone-here Date: Mon, 25 Sep 2023 16:32:19 +0530 Subject: [PATCH 2/2] Remove assignee task report reply on closing/opening --- src/libs/ReportActionsUtils.js | 12 ------------ src/libs/ReportUtils.js | 25 ----------------------- src/libs/actions/Task.js | 36 ---------------------------------- 3 files changed, 73 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 7f95a9a0f856..f37550e0d0ef 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -131,17 +131,6 @@ function getParentReportAction(report, allReportActionsParam = undefined) { return lodashGet(allReportActionsParam || allReportActions, [report.parentReportID, report.parentReportActionID], {}); } -/** - * Find the reportAction having the given childReportID in parent report actions - * - * @param {String} childReportID - * @param {String} parentReportID - * @returns {Object} - */ -function getParentReportActionsInReport(childReportID, parentReportID) { - return _.filter(allReportActions[parentReportID], (reportAction) => reportAction && `${reportAction.childReportID}` === `${childReportID}`); -} - /** * Determines if the given report action is sent money report action by checking for 'pay' type and presence of IOUDetails object. * @@ -674,7 +663,6 @@ export { getReportPreviewAction, isCreatedTaskReportAction, getParentReportAction, - getParentReportActionsInReport, isTransactionThread, isSentMoneyReportAction, isDeletedParentAction, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d3d0451bbd70..071cc9b6cce8 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3355,30 +3355,6 @@ function isReportDataReady() { return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key].reportID); } -/** - * Find the parent report action in assignee report for a task report - * Returns an empty object if assignee report is the same as the share destination report - * - * @param {Object} taskReport - * @returns {Object} - */ -function getTaskParentReportActionIDsInAssigneeReport(taskReport) { - const assigneeChatReportID = lodashGet(getChatByParticipants(isReportManager(taskReport) ? [taskReport.ownerAccountID] : [taskReport.managerID]), 'reportID'); - if (!assigneeChatReportID || assigneeChatReportID === taskReport.parentReportID) { - return {}; - } - - const clonedParentReportActionIDs = _.map(ReportActionsUtils.getParentReportActionsInReport(taskReport.reportID, assigneeChatReportID), (a) => lodashGet(a, 'reportActionID', 0)); - if (!clonedParentReportActionIDs) { - return {}; - } - - return { - reportID: assigneeChatReportID, - reportActionIDs: clonedParentReportActionIDs, - }; -} - /** * Return the errors we have when creating a chat or a workspace room * @param {Object} report @@ -3723,7 +3699,6 @@ export { getBankAccountRoute, getParentReport, getRootParentReport, - getTaskParentReportActionIDsInAssigneeReport, getReportPreviewMessage, getModifiedExpenseMessage, shouldDisableWriteActions, diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 1dfdcad04aeb..68ecdb24bde9 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -274,24 +274,6 @@ function completeTask(taskReport, taskTitle) { }, ]; - // Multiple report actions can link to the same child. Both share destination (task parent) and assignee report link to the same report action. - // We need to find and update the other parent report action (in assignee report). More info https://github.com/Expensify/App/issues/23920#issuecomment-1663092717 - const assigneeReportActions = ReportUtils.getTaskParentReportActionIDsInAssigneeReport(taskReport); - if (!_.isEmpty(assigneeReportActions)) { - _.forEach(assigneeReportActions.reportActionIDs, (reportActionID) => { - const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( - taskReportID, - completedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - assigneeReportActions.reportID, - reportActionID, - ); - if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { - optimisticData.push(optimisticDataForClonedParentReportAction); - } - }); - } - API.write( 'CompleteTask', { @@ -363,24 +345,6 @@ function reopenTask(taskReport, taskTitle) { }, ]; - // Multiple report actions can link to the same child. Both share destination (task parent) and assignee report link to the same report action. - // We need to find and update the other parent report action (in assignee report). More info https://github.com/Expensify/App/issues/23920#issuecomment-1663092717 - const assigneeReportActions = ReportUtils.getTaskParentReportActionIDsInAssigneeReport(taskReport); - if (!_.isEmpty(assigneeReportActions)) { - _.forEach(assigneeReportActions.reportActionIDs, (reportActionID) => { - const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( - taskReportID, - reopenedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - assigneeReportActions.reportID, - reportActionID, - ); - if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { - optimisticData.push(optimisticDataForClonedParentReportAction); - } - }); - } - API.write( 'ReopenTask', {