From 313d2e56e05182be7206ffc372b8cc612baa704d Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 3 Aug 2023 06:31:08 -0500 Subject: [PATCH 01/17] fix: update parent action for assignee report as well --- .../ReportActionItem/TaskPreview.js | 4 +- src/components/ReportActionItem/TaskView.js | 2 +- src/libs/ReportActionsUtils.js | 15 +++++ src/libs/ReportUtils.js | 1 + src/libs/actions/Task.js | 65 +++++++++++++++++-- 5 files changed, 77 insertions(+), 10 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 740ab345fa74..d05ebd4bfd09 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -88,9 +88,9 @@ function TaskPreview(props) { disabled={ReportUtils.isCanceledTaskReport(props.taskReport)} onPress={() => { if (isTaskCompleted) { - Task.reopenTask(props.taskReportID, taskTitle); + Task.reopenTask(props.taskReport, taskTitle); } else { - Task.completeTask(props.taskReportID, taskTitle); + Task.completeTask(props.taskReport, taskTitle); } }} accessibilityLabel={props.translate('task.task')} diff --git a/src/components/ReportActionItem/TaskView.js b/src/components/ReportActionItem/TaskView.js index a08f341acb1f..57d40450b4be 100644 --- a/src/components/ReportActionItem/TaskView.js +++ b/src/components/ReportActionItem/TaskView.js @@ -71,7 +71,7 @@ function TaskView(props) { {props.translate('task.title')} (isCompleted ? Task.reopenTask(props.report.reportID, taskTitle) : Task.completeTask(props.report.reportID, taskTitle))} + onPress={() => (isCompleted ? Task.reopenTask(props.report, taskTitle) : Task.completeTask(props.report, taskTitle))} isChecked={isCompleted} style={styles.taskMenuItemCheckbox} containerSize={24} diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 3cd5621e5e32..64dae0c4294b 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -547,6 +547,20 @@ function getIOUReportIDFromReportActionPreview(reportAction) { return lodashGet(reportAction, 'originalMessage.linkedReportID', ''); } +/** + * Find the reportAction whose childReportID is taskReportID in reportActions with reportID + * + * @param {String} taskReportID + * @param {String} reportID + * @returns {Object} + */ +function getParentReportActionForTask(taskReportID, reportID) { + return _.find( + allReportActions[reportID], + (reportAction) => reportAction && `${reportAction.childReportID}` === `${taskReportID}` && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, + ); +} + function isCreatedTaskReportAction(reportAction) { return reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && _.has(reportAction.originalMessage, 'taskReportID'); } @@ -593,4 +607,5 @@ export { isWhisperAction, isPendingRemove, getReportAction, + getParentReportActionForTask, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 91c35d4cd956..298d59edf831 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1618,6 +1618,7 @@ function buildOptimisticTaskCommentReportAction(taskReportID, taskTitle, taskAss reportAction.reportAction.childType = CONST.REPORT.TYPE.TASK; reportAction.reportAction.childReportName = taskTitle; reportAction.reportAction.childManagerAccountID = taskAssigneeAccountID; + reportAction.reportAction.participantAccountIDs = [taskAssigneeAccountID]; reportAction.reportAction.childStatusNum = CONST.REPORT.STATUS.OPEN; reportAction.reportAction.childStateNum = CONST.REPORT.STATE_NUM.OPEN; diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 850149a83635..8c2a5b235174 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -207,7 +207,13 @@ function createTaskAndNavigate(parentReportID, title, description, assignee, ass Navigation.dismissModal(optimisticTaskReport.reportID); } -function completeTask(taskReportID, taskTitle) { +/** + * Complete a task + * @param {Object} taskReport task report + * @param {String} taskTitle Title of the task + */ +function completeTask(taskReport, taskTitle) { + const taskReportID = taskReport.reportID; const message = `completed task: ${taskTitle}`; const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED, message); @@ -259,10 +265,32 @@ function completeTask(taskReportID, taskTitle) { }, ]; - // Update optimistic data for parent report action + // Update optimistic data and failure data for parent report action const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); if (!_.isEmpty(optimisticParentReportData)) { optimisticData.push(optimisticParentReportData); + const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { + const parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); + if (parentReportAction) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: { + [parentReportAction.reportActionID]: _.values(optimisticParentReportData.value)[0], + }, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: { + [parentReportAction.reportActionID]: { + errors: ErrorUtils.getMicroSecondOnyxError('task.messages.error'), + }, + }, + }); + } + } } API.write( @@ -276,11 +304,12 @@ function completeTask(taskReportID, taskTitle) { } /** - * Reopens a closed task - * @param {string} taskReportID ReportID of the task - * @param {string} taskTitle Title of the task + * Reopen a closed task + * @param {Object} taskReport task report + * @param {String} taskTitle Title of the task */ -function reopenTask(taskReportID, taskTitle) { +function reopenTask(taskReport, taskTitle) { + const taskReportID = taskReport.reportID; const message = `reopened task: ${taskTitle}`; const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKREOPENED, message); @@ -335,10 +364,32 @@ function reopenTask(taskReportID, taskTitle) { }, ]; - // Update optimistic data for parent report action + // Update optimistic data and failure data for parent report action const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); if (!_.isEmpty(optimisticParentReportData)) { optimisticData.push(optimisticParentReportData); + const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { + const parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); + if (parentReportAction) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: { + [parentReportAction.reportActionID]: _.values(optimisticParentReportData.value)[0], + }, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: { + [parentReportAction.reportActionID]: { + errors: ErrorUtils.getMicroSecondOnyxError('task.messages.error'), + }, + }, + }); + } + } } API.write( From 9728aa290e63dcd7e3a62a0772567e3c6c9eca48 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 3 Aug 2023 07:05:08 -0500 Subject: [PATCH 02/17] fix: optimistic data 'participantAccountIDs' in task report, not in report action --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 298d59edf831..4520b2b8a9d9 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1618,7 +1618,6 @@ function buildOptimisticTaskCommentReportAction(taskReportID, taskTitle, taskAss reportAction.reportAction.childType = CONST.REPORT.TYPE.TASK; reportAction.reportAction.childReportName = taskTitle; reportAction.reportAction.childManagerAccountID = taskAssigneeAccountID; - reportAction.reportAction.participantAccountIDs = [taskAssigneeAccountID]; reportAction.reportAction.childStatusNum = CONST.REPORT.STATUS.OPEN; reportAction.reportAction.childStateNum = CONST.REPORT.STATE_NUM.OPEN; @@ -2170,6 +2169,7 @@ function buildOptimisticTaskReport(ownerAccountID, assigneeAccountID = 0, parent description, ownerAccountID, managerID: assigneeAccountID, + participantAccountIDs: [assigneeAccountID], type: CONST.REPORT.TYPE.TASK, parentReportID, stateNum: CONST.REPORT.STATE_NUM.OPEN, From 574c144fa8ac0afcf1899e679b8beedec3c0a9d5 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 3 Aug 2023 07:09:31 -0500 Subject: [PATCH 03/17] fix: console warning --- src/pages/home/HeaderView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 85cdd239dae7..47fc4f1ac1fb 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -192,7 +192,7 @@ function HeaderView(props) { {!_.isEmpty(parentNavigationSubtitleData) && ( )} From 1e380ae19dd5d51b85d1af7801c605ef9bee9ba9 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 3 Aug 2023 18:39:36 -0500 Subject: [PATCH 04/17] fix: add comments, remove failureData for assignee report action --- src/components/ParentNavigationSubtitle.js | 4 ++-- src/components/TaskHeaderActionButton.js | 4 ++-- src/libs/actions/Task.js | 24 ++++++---------------- src/pages/home/HeaderView.js | 2 +- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/components/ParentNavigationSubtitle.js b/src/components/ParentNavigationSubtitle.js index fd388b00a8a7..934216815f37 100644 --- a/src/components/ParentNavigationSubtitle.js +++ b/src/components/ParentNavigationSubtitle.js @@ -18,7 +18,7 @@ const propTypes = { }).isRequired, /** parent Report ID */ - parentReportID: PropTypes.string, + parentReportID: PropTypes.number, /** PressableWithoutFeedack additional styles */ // eslint-disable-next-line react/forbid-prop-types @@ -26,7 +26,7 @@ const propTypes = { }; const defaultProps = { - parentReportID: '', + parentReportID: 0, pressableStyles: [], }; diff --git a/src/components/TaskHeaderActionButton.js b/src/components/TaskHeaderActionButton.js index e0a2549b2f0c..59b8bb80e961 100644 --- a/src/components/TaskHeaderActionButton.js +++ b/src/components/TaskHeaderActionButton.js @@ -51,8 +51,8 @@ function TaskHeaderActionButton(props) { text={props.translate(ReportUtils.isCompletedTaskReport(props.report) ? 'task.markAsIncomplete' : 'task.markAsDone')} onPress={() => ReportUtils.isCompletedTaskReport(props.report) - ? Task.reopenTask(props.report.reportID, props.report.reportName) - : Task.completeTask(props.report.reportID, props.report.reportName) + ? Task.reopenTask(props.report, props.report.reportName) + : Task.completeTask(props.report, props.report.reportName) } style={[styles.flex1]} /> diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 914184f7b4dc..264ada91c8d8 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -269,7 +269,9 @@ function completeTask(taskReport, taskTitle) { const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); if (!_.isEmpty(optimisticParentReportData)) { optimisticData.push(optimisticParentReportData); + // Get assignee report from participantAccountIDs as in creating task const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { const parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); if (parentReportAction) { @@ -277,18 +279,10 @@ function completeTask(taskReport, taskTitle) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, value: { + // Copy optimistic report action data from shareDestination [parentReportAction.reportActionID]: _.values(optimisticParentReportData.value)[0], }, }); - failureData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: { - [parentReportAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError('task.messages.error'), - }, - }, - }); } } } @@ -368,7 +362,9 @@ function reopenTask(taskReport, taskTitle) { const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); if (!_.isEmpty(optimisticParentReportData)) { optimisticData.push(optimisticParentReportData); + // Get assignee report from participantAccountIDs as in creating task const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { const parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); if (parentReportAction) { @@ -376,18 +372,10 @@ function reopenTask(taskReport, taskTitle) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, value: { + // Copy optimistic report action data from shareDestination [parentReportAction.reportActionID]: _.values(optimisticParentReportData.value)[0], }, }); - failureData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: { - [parentReportAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError('task.messages.error'), - }, - }, - }); } } } diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 47fc4f1ac1fb..85cdd239dae7 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -192,7 +192,7 @@ function HeaderView(props) { {!_.isEmpty(parentNavigationSubtitleData) && ( )} From abff05774157bf557599c62fcd75b35aae9d16b1 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 3 Aug 2023 18:41:12 -0500 Subject: [PATCH 05/17] fix: prettier --- src/components/TaskHeaderActionButton.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/TaskHeaderActionButton.js b/src/components/TaskHeaderActionButton.js index 59b8bb80e961..148cf81ce672 100644 --- a/src/components/TaskHeaderActionButton.js +++ b/src/components/TaskHeaderActionButton.js @@ -50,9 +50,7 @@ function TaskHeaderActionButton(props) { medium text={props.translate(ReportUtils.isCompletedTaskReport(props.report) ? 'task.markAsIncomplete' : 'task.markAsDone')} onPress={() => - ReportUtils.isCompletedTaskReport(props.report) - ? Task.reopenTask(props.report, props.report.reportName) - : Task.completeTask(props.report, props.report.reportName) + ReportUtils.isCompletedTaskReport(props.report) ? Task.reopenTask(props.report, props.report.reportName) : Task.completeTask(props.report, props.report.reportName) } style={[styles.flex1]} /> From a5eac4027a63235fd29c5d9140a6f2ec4c5d37ca Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 3 Aug 2023 23:20:37 -0500 Subject: [PATCH 06/17] fix: use of updateOptimisticParentReportAction for both assignee and shareDestination reports --- src/components/ParentNavigationSubtitle.js | 2 +- src/libs/actions/Task.js | 88 +++++++++++++--------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/components/ParentNavigationSubtitle.js b/src/components/ParentNavigationSubtitle.js index 934216815f37..a59fb52b78ce 100644 --- a/src/components/ParentNavigationSubtitle.js +++ b/src/components/ParentNavigationSubtitle.js @@ -18,7 +18,7 @@ const propTypes = { }).isRequired, /** parent Report ID */ - parentReportID: PropTypes.number, + parentReportID: PropTypes.string, /** PressableWithoutFeedack additional styles */ // eslint-disable-next-line react/forbid-prop-types diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 264ada91c8d8..f92d944e0626 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -266,23 +266,32 @@ function completeTask(taskReport, taskTitle) { ]; // Update optimistic data and failure data for parent report action - const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - if (!_.isEmpty(optimisticParentReportData)) { - optimisticData.push(optimisticParentReportData); - // Get assignee report from participantAccountIDs as in creating task - const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { - const parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); - if (parentReportAction) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: { - // Copy optimistic report action data from shareDestination - [parentReportAction.reportActionID]: _.values(optimisticParentReportData.value)[0], - }, - }); + if (taskReport.parentReportActionID) { + let parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); + if (parentReportAction && parentReportAction.reportActionID) { + const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction(parentReportAction, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, + value: { + [parentReportAction.reportActionID]: optimisticParentReportActionData, + }, + }); + + // Get assignee report from participantAccountIDs as in creating task according to https://github.com/Expensify/App/issues/23920#issuecomment-1663092717 + const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same + if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { + parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); + if (parentReportAction && parentReportAction.reportActionID) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: { + [parentReportAction.reportActionID]: optimisticParentReportActionData, + }, + }); + } } } } @@ -358,24 +367,33 @@ function reopenTask(taskReport, taskTitle) { }, ]; - // Update optimistic data and failure data for parent report action - const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - if (!_.isEmpty(optimisticParentReportData)) { - optimisticData.push(optimisticParentReportData); - // Get assignee report from participantAccountIDs as in creating task - const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { - const parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); - if (parentReportAction) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: { - // Copy optimistic report action data from shareDestination - [parentReportAction.reportActionID]: _.values(optimisticParentReportData.value)[0], - }, - }); + // Update optimistic data for parent report action + if (taskReport.parentReportActionID) { + let parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); + if (parentReportAction && parentReportAction.reportActionID) { + const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction(parentReportAction, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, + value: { + [parentReportAction.reportActionID]: optimisticParentReportActionData, + }, + }); + + // Get assignee report from participantAccountIDs as in creating task according to https://github.com/Expensify/App/issues/23920#issuecomment-1663092717 + const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same + if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { + parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); + if (parentReportAction && parentReportAction.reportActionID) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: { + [parentReportAction.reportActionID]: optimisticParentReportActionData, + }, + }); + } } } } From 688217fa7328ea91776a5b3676d4ccf1e68e57ab Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 3 Aug 2023 23:23:15 -0500 Subject: [PATCH 07/17] fix: prettier --- src/libs/actions/Task.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index f92d944e0626..e8f5c8e573cd 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -269,7 +269,11 @@ function completeTask(taskReport, taskTitle) { if (taskReport.parentReportActionID) { let parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); if (parentReportAction && parentReportAction.reportActionID) { - const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction(parentReportAction, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( + parentReportAction, + completedTaskReportAction.created, + CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + ); optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, @@ -371,7 +375,11 @@ function reopenTask(taskReport, taskTitle) { if (taskReport.parentReportActionID) { let parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); if (parentReportAction && parentReportAction.reportActionID) { - const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction(parentReportAction, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( + parentReportAction, + reopenedTaskReportAction.created, + CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + ); optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, From d4dd9644e38fdce656ece8c06918381bd91a051d Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Fri, 4 Aug 2023 20:59:00 -0500 Subject: [PATCH 08/17] fix: rnaming, comments --- src/components/ParentNavigationSubtitle.js | 2 +- src/libs/actions/Task.js | 119 ++++++++++----------- 2 files changed, 60 insertions(+), 61 deletions(-) diff --git a/src/components/ParentNavigationSubtitle.js b/src/components/ParentNavigationSubtitle.js index a59fb52b78ce..fd388b00a8a7 100644 --- a/src/components/ParentNavigationSubtitle.js +++ b/src/components/ParentNavigationSubtitle.js @@ -26,7 +26,7 @@ const propTypes = { }; const defaultProps = { - parentReportID: 0, + parentReportID: '', pressableStyles: [], }; diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index e8f5c8e573cd..280037060bdd 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -266,36 +266,35 @@ function completeTask(taskReport, taskTitle) { ]; // Update optimistic data and failure data for parent report action - if (taskReport.parentReportActionID) { - let parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); - if (parentReportAction && parentReportAction.reportActionID) { - const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( - parentReportAction, - completedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - ); - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, - value: { - [parentReportAction.reportActionID]: optimisticParentReportActionData, - }, - }); - - // Get assignee report from participantAccountIDs as in creating task according to https://github.com/Expensify/App/issues/23920#issuecomment-1663092717 - const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { - parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); - if (parentReportAction && parentReportAction.reportActionID) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: { - [parentReportAction.reportActionID]: optimisticParentReportActionData, - }, - }); - } + const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); + if (parentReportAction && parentReportAction.reportActionID) { + const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( + parentReportAction, + completedTaskReportAction.created, + CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + ); + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, + value: { + [parentReportAction.reportActionID]: optimisticParentReportActionData, + }, + }); + + // 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same + if (assigneeChatReportID && assigneeChatReportID !== String(taskReport.parentReportID)) { + const clonedParentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); + if (clonedParentReportAction && clonedParentReportAction.reportActionID) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: { + [clonedParentReportAction.reportActionID]: optimisticParentReportActionData, + }, + }); } } } @@ -372,36 +371,36 @@ function reopenTask(taskReport, taskTitle) { ]; // Update optimistic data for parent report action - if (taskReport.parentReportActionID) { - let parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); - if (parentReportAction && parentReportAction.reportActionID) { - const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( - parentReportAction, - reopenedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - ); - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, - value: { - [parentReportAction.reportActionID]: optimisticParentReportActionData, - }, - }); - - // Get assignee report from participantAccountIDs as in creating task according to https://github.com/Expensify/App/issues/23920#issuecomment-1663092717 - const assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && `${assigneeChatReportID}` !== `${taskReport.parentReportID}`) { - parentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); - if (parentReportAction && parentReportAction.reportActionID) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: { - [parentReportAction.reportActionID]: optimisticParentReportActionData, - }, - }); - } + // Update optimistic data and failure data for parent report action + const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); + if (parentReportAction && parentReportAction.reportActionID) { + const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( + parentReportAction, + reopenedTaskReportAction.created, + CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + ); + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, + value: { + [parentReportAction.reportActionID]: optimisticParentReportActionData, + }, + }); + + // 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same + if (assigneeChatReportID && assigneeChatReportID !== String(taskReport.parentReportID)) { + const clonedParentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); + if (clonedParentReportAction && clonedParentReportAction.reportActionID) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: { + [clonedParentReportAction.reportActionID]: optimisticParentReportActionData, + }, + }); } } } From fbed766e522fcad450df1d9ce3c8e988ee42a298 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Fri, 4 Aug 2023 21:10:01 -0500 Subject: [PATCH 09/17] fix: comments, string constructor --- src/libs/ReportActionsUtils.js | 2 +- src/libs/actions/Task.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 64dae0c4294b..66da06294ae2 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -557,7 +557,7 @@ function getIOUReportIDFromReportActionPreview(reportAction) { function getParentReportActionForTask(taskReportID, reportID) { return _.find( allReportActions[reportID], - (reportAction) => reportAction && `${reportAction.childReportID}` === `${taskReportID}` && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, + (reportAction) => reportAction && `${reportAction.childReportID}` === `${taskReportID}`, ); } diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 280037060bdd..8294a37383d2 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -265,7 +265,7 @@ function completeTask(taskReport, taskTitle) { }, ]; - // Update optimistic data and failure data for parent report action + // Update optimistic data for parent report action const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); if (parentReportAction && parentReportAction.reportActionID) { const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( @@ -285,7 +285,7 @@ function completeTask(taskReport, taskTitle) { // 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && assigneeChatReportID !== String(taskReport.parentReportID)) { + if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { const clonedParentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); if (clonedParentReportAction && clonedParentReportAction.reportActionID) { optimisticData.push({ @@ -371,7 +371,6 @@ function reopenTask(taskReport, taskTitle) { ]; // Update optimistic data for parent report action - // Update optimistic data and failure data for parent report action const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); if (parentReportAction && parentReportAction.reportActionID) { const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( @@ -391,7 +390,7 @@ function reopenTask(taskReport, taskTitle) { // 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && assigneeChatReportID !== String(taskReport.parentReportID)) { + if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { const clonedParentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); if (clonedParentReportAction && clonedParentReportAction.reportActionID) { optimisticData.push({ From 6a977fdb4657acf953c0ad004bb34534d4f04490 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Fri, 4 Aug 2023 21:16:16 -0500 Subject: [PATCH 10/17] fix: prettier --- src/libs/ReportActionsUtils.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 66da06294ae2..5baa2e0f7abb 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -555,10 +555,7 @@ function getIOUReportIDFromReportActionPreview(reportAction) { * @returns {Object} */ function getParentReportActionForTask(taskReportID, reportID) { - return _.find( - allReportActions[reportID], - (reportAction) => reportAction && `${reportAction.childReportID}` === `${taskReportID}`, - ); + return _.find(allReportActions[reportID], (reportAction) => reportAction && `${reportAction.childReportID}` === `${taskReportID}`); } function isCreatedTaskReportAction(reportAction) { From fafcfa99af172e6431563d8a0d4de2dfc7aa26dd Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Sun, 6 Aug 2023 19:13:24 -0500 Subject: [PATCH 11/17] fix: update getOptimisticDataForParentReportAction --- src/libs/ReportActionsUtils.js | 10 ++-- src/libs/ReportUtils.js | 34 +++++++++----- src/libs/actions/Task.js | 86 +++++++++++----------------------- 3 files changed, 54 insertions(+), 76 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 5baa2e0f7abb..24be293b85c7 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -548,14 +548,14 @@ function getIOUReportIDFromReportActionPreview(reportAction) { } /** - * Find the reportAction whose childReportID is taskReportID in reportActions with reportID + * Find the reportAction whose childReportID is childReportID in reportActions with reportID * - * @param {String} taskReportID + * @param {String} childReportID * @param {String} reportID * @returns {Object} */ -function getParentReportActionForTask(taskReportID, reportID) { - return _.find(allReportActions[reportID], (reportAction) => reportAction && `${reportAction.childReportID}` === `${taskReportID}`); +function getParentReportActionInReport(childReportID, reportID) { + return _.find(allReportActions[reportID], (reportAction) => reportAction && `${reportAction.childReportID}` === `${childReportID}`); } function isCreatedTaskReportAction(reportAction) { @@ -604,5 +604,5 @@ export { isWhisperAction, isPendingRemove, getReportAction, - getParentReportActionForTask, + getParentReportActionInReport, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 80ac26e17e00..538a4e49f988 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1576,21 +1576,29 @@ function updateOptimisticParentReportAction(parentReportAction, lastVisibleActio * @param {String} type The type of action in the child report * @returns {Object} */ -const getOptimisticDataForParentReportAction = (reportID, lastVisibleActionCreated, type) => { +const getOptimisticDataForParentReportAction = (reportID, lastVisibleActionCreated, type, parentReportID = 0, parentReportActionID = 0) => { const report = getReport(reportID); - if (report && report.parentReportActionID) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); - if (parentReportAction && parentReportAction.reportActionID) { - return { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, - value: { - [parentReportAction.reportActionID]: updateOptimisticParentReportAction(parentReportAction, lastVisibleActionCreated, type), - }, - }; - } + const parentReportAction = ReportActionsUtils.getParentReportAction(report); + if (_.isEmpty(parentReportAction)) { + return {}; } - return {}; + + const optimisticParentReportAction = updateOptimisticParentReportAction(parentReportAction, lastVisibleActionCreated, type); + if (!parentReportID) { + parentReportID = report.parentReportID; + } + + if (!parentReportActionID) { + parentReportActionID = report.parentReportActionID; + } + + return { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, + value: { + [parentReportActionID]: optimisticParentReportAction, + }, + }; }; /** diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 8294a37383d2..13c683665517 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -266,35 +266,20 @@ function completeTask(taskReport, taskTitle) { ]; // Update optimistic data for parent report action - const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); - if (parentReportAction && parentReportAction.reportActionID) { - const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( - parentReportAction, - completedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - ); - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, - value: { - [parentReportAction.reportActionID]: optimisticParentReportActionData, - }, - }); - - // 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { - const clonedParentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); - if (clonedParentReportAction && clonedParentReportAction.reportActionID) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: { - [clonedParentReportAction.reportActionID]: optimisticParentReportActionData, - }, - }); + const optimisticDataForParentReportAction = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + if (!_.isEmpty(optimisticDataForParentReportAction)) { + optimisticData.push(optimisticDataForParentReportAction); + } + // 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same + if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { + const clonedParentReportAction = ReportActionsUtils.getParentReportActionInReport(taskReportID, assigneeChatReportID); + if (clonedParentReportAction && clonedParentReportAction.reportActionID) { + const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, assigneeChatReportID, clonedParentReportAction.reportActionID); + if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { + optimisticData.push(optimisticDataForClonedParentReportAction); } } } @@ -371,35 +356,20 @@ function reopenTask(taskReport, taskTitle) { ]; // Update optimistic data for parent report action - const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); - if (parentReportAction && parentReportAction.reportActionID) { - const optimisticParentReportActionData = ReportUtils.updateOptimisticParentReportAction( - parentReportAction, - reopenedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - ); - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport.parentReportID}`, - value: { - [parentReportAction.reportActionID]: optimisticParentReportActionData, - }, - }); - - // 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { - const clonedParentReportAction = ReportActionsUtils.getParentReportActionForTask(taskReportID, assigneeChatReportID); - if (clonedParentReportAction && clonedParentReportAction.reportActionID) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: { - [clonedParentReportAction.reportActionID]: optimisticParentReportActionData, - }, - }); + const optimisticDataForParentReportAction = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + if (!_.isEmpty(optimisticDataForParentReportAction)) { + optimisticData.push(optimisticDataForParentReportAction); + } + // 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same + if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { + const clonedParentReportAction = ReportActionsUtils.getParentReportActionInReport(taskReportID, assigneeChatReportID); + if (clonedParentReportAction && clonedParentReportAction.reportActionID) { + const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, assigneeChatReportID, clonedParentReportAction.reportActionID); + if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { + optimisticData.push(optimisticDataForClonedParentReportAction); } } } From 99018a5aee58daf417fd63133f4e1f8b86e1a82f Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Sun, 6 Aug 2023 19:23:28 -0500 Subject: [PATCH 12/17] fix: lint and prettier --- src/libs/ReportUtils.js | 16 +++++----------- src/libs/actions/Task.js | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 538a4e49f988..7416da07143d 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1574,9 +1574,11 @@ function updateOptimisticParentReportAction(parentReportAction, lastVisibleActio * @param {String} reportID The reportID of the report that is updated * @param {String} lastVisibleActionCreated Last visible action created of the child report * @param {String} type The type of action in the child report + * @param {String} parentReportID Custom reportID to be updated + * @param {String} parentReportActionID Custom reportActionID to be updated * @returns {Object} */ -const getOptimisticDataForParentReportAction = (reportID, lastVisibleActionCreated, type, parentReportID = 0, parentReportActionID = 0) => { +const getOptimisticDataForParentReportAction = (reportID, lastVisibleActionCreated, type, parentReportID = '', parentReportActionID = '') => { const report = getReport(reportID); const parentReportAction = ReportActionsUtils.getParentReportAction(report); if (_.isEmpty(parentReportAction)) { @@ -1584,19 +1586,11 @@ const getOptimisticDataForParentReportAction = (reportID, lastVisibleActionCreat } const optimisticParentReportAction = updateOptimisticParentReportAction(parentReportAction, lastVisibleActionCreated, type); - if (!parentReportID) { - parentReportID = report.parentReportID; - } - - if (!parentReportActionID) { - parentReportActionID = report.parentReportActionID; - } - return { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID || report.parentReportID}`, value: { - [parentReportActionID]: optimisticParentReportAction, + [parentReportActionID || report.parentReportActionID]: optimisticParentReportAction, }, }; }; diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 13c683665517..009414969146 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -277,7 +277,13 @@ function completeTask(taskReport, taskTitle) { if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { const clonedParentReportAction = ReportActionsUtils.getParentReportActionInReport(taskReportID, assigneeChatReportID); if (clonedParentReportAction && clonedParentReportAction.reportActionID) { - const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, assigneeChatReportID, clonedParentReportAction.reportActionID); + const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( + taskReportID, + completedTaskReportAction.created, + CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + assigneeChatReportID, + clonedParentReportAction.reportActionID, + ); if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { optimisticData.push(optimisticDataForClonedParentReportAction); } @@ -367,7 +373,13 @@ function reopenTask(taskReport, taskTitle) { if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { const clonedParentReportAction = ReportActionsUtils.getParentReportActionInReport(taskReportID, assigneeChatReportID); if (clonedParentReportAction && clonedParentReportAction.reportActionID) { - const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, assigneeChatReportID, clonedParentReportAction.reportActionID); + const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( + taskReportID, + reopenedTaskReportAction.created, + CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + assigneeChatReportID, + clonedParentReportAction.reportActionID, + ); if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { optimisticData.push(optimisticDataForClonedParentReportAction); } From c474825fb953b24019dedf29aedd15a71cae42c4 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Sun, 6 Aug 2023 21:25:34 -0500 Subject: [PATCH 13/17] fix: refactor completeTask/reopenTask --- src/libs/ReportActionsUtils.js | 24 ++++++++-------- src/libs/ReportUtils.js | 27 +++++++++++++++++- src/libs/actions/Task.js | 52 ++++++++++++++-------------------- 3 files changed, 60 insertions(+), 43 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 24be293b85c7..6d777533360d 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -119,6 +119,17 @@ 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 getParentReportActionInReport(childReportID, parentReportID) { + return _.find(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. * @@ -547,17 +558,6 @@ function getIOUReportIDFromReportActionPreview(reportAction) { return lodashGet(reportAction, 'originalMessage.linkedReportID', ''); } -/** - * Find the reportAction whose childReportID is childReportID in reportActions with reportID - * - * @param {String} childReportID - * @param {String} reportID - * @returns {Object} - */ -function getParentReportActionInReport(childReportID, reportID) { - return _.find(allReportActions[reportID], (reportAction) => reportAction && `${reportAction.childReportID}` === `${childReportID}`); -} - function isCreatedTaskReportAction(reportAction) { return reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && _.has(reportAction.originalMessage, 'taskReportID'); } @@ -594,6 +594,7 @@ export { getReportPreviewAction, isCreatedTaskReportAction, getParentReportAction, + getParentReportActionInReport, isTransactionThread, getFormattedAmount, isSentMoneyReportAction, @@ -604,5 +605,4 @@ export { isWhisperAction, isPendingRemove, getReportAction, - getParentReportActionInReport, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7416da07143d..fcc9c0e8b818 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1578,7 +1578,7 @@ function updateOptimisticParentReportAction(parentReportAction, lastVisibleActio * @param {String} parentReportActionID Custom reportActionID to be updated * @returns {Object} */ -const getOptimisticDataForParentReportAction = (reportID, lastVisibleActionCreated, type, parentReportID = '', parentReportActionID = '') => { +function getOptimisticDataForParentReportAction(reportID, lastVisibleActionCreated, type, parentReportID = '', parentReportActionID = '') { const report = getReport(reportID); const parentReportAction = ReportActionsUtils.getParentReportAction(report); if (_.isEmpty(parentReportAction)) { @@ -2773,6 +2773,30 @@ function getParentReport(report) { return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, {}); } +/** + * Find the parent report action in assignee report for a task report + * + * @param {Object} taskReport + * @returns {Object} + */ +function getAssigneeParentReportAction(taskReport) { + const assigneeChatReportID = lodashGet(getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + // No need to go ahead if reports for assignee and shareDestination are the same + if (!assigneeChatReportID || assigneeChatReportID === taskReport.parentReportID) { + return {}; + } + + const clonedParentReportActionID = lodashGet(ReportActionsUtils.getParentReportActionInReport(taskReport.reportID, assigneeChatReportID), 'reportActionID', ''); + if (!clonedParentReportActionID) { + return {}; + } + + return { + reportID: assigneeChatReportID, + reportActionID: clonedParentReportActionID, + }; +} + /** * Return true if the composer should be hidden * @param {Object} report @@ -2953,6 +2977,7 @@ export { getMoneyRequestAction, getBankAccountRoute, getParentReport, + getAssigneeParentReportAction, getReportPreviewMessage, shouldHideComposer, getOriginalReportID, diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 009414969146..b8fe9dd8c779 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -272,21 +272,17 @@ 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { - const clonedParentReportAction = ReportActionsUtils.getParentReportActionInReport(taskReportID, assigneeChatReportID); - if (clonedParentReportAction && clonedParentReportAction.reportActionID) { - const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( - taskReportID, - completedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - assigneeChatReportID, - clonedParentReportAction.reportActionID, - ); - if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { - optimisticData.push(optimisticDataForClonedParentReportAction); - } + const assigneeReportAction = ReportUtils.getAssigneeParentReportAction(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); } } @@ -368,21 +364,17 @@ 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 assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // We don't need to create optmistic report action for assignee report if assignee and shareDestination are the same - if (assigneeChatReportID && assigneeChatReportID !== taskReport.parentReportID) { - const clonedParentReportAction = ReportActionsUtils.getParentReportActionInReport(taskReportID, assigneeChatReportID); - if (clonedParentReportAction && clonedParentReportAction.reportActionID) { - const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( - taskReportID, - reopenedTaskReportAction.created, - CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - assigneeChatReportID, - clonedParentReportAction.reportActionID, - ); - if (!_.isEmpty(optimisticDataForClonedParentReportAction)) { - optimisticData.push(optimisticDataForClonedParentReportAction); - } + const assigneeReportAction = ReportUtils.getAssigneeParentReportAction(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); } } From e87bed829d643d47d53327867e66616b3cdc7824 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Sun, 6 Aug 2023 21:27:29 -0500 Subject: [PATCH 14/17] fix: run prettier --- src/libs/ReportUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index fcc9c0e8b818..7d499f906c5c 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1593,7 +1593,7 @@ function getOptimisticDataForParentReportAction(reportID, lastVisibleActionCreat [parentReportActionID || report.parentReportActionID]: optimisticParentReportAction, }, }; -}; +} /** * Builds an optimistic reportAction for the parent report when a task is created @@ -2775,8 +2775,8 @@ function getParentReport(report) { /** * Find the parent report action in assignee report for a task report - * - * @param {Object} taskReport + * + * @param {Object} taskReport * @returns {Object} */ function getAssigneeParentReportAction(taskReport) { From a5f4dfbcba4290718b387265a7dce6ccee837903 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Mon, 7 Aug 2023 07:33:58 -0500 Subject: [PATCH 15/17] fix: reopen/complete task in HeaderView --- src/pages/home/HeaderView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 85cdd239dae7..fafd6caf4f1f 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -104,7 +104,7 @@ function HeaderView(props) { threeDotMenuItems.push({ icon: Expensicons.Checkmark, text: props.translate('task.markAsDone'), - onSelected: () => Task.completeTask(props.report.reportID, title), + onSelected: () => Task.completeTask(props.report, title), }); } @@ -113,7 +113,7 @@ function HeaderView(props) { threeDotMenuItems.push({ icon: Expensicons.Checkmark, text: props.translate('task.markAsIncomplete'), - onSelected: () => Task.reopenTask(props.report.reportID, title), + onSelected: () => Task.reopenTask(props.report, title), }); } From 2e3f28eeb50026804a1ffbf1af0e081cb5bdfbb6 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Mon, 7 Aug 2023 08:23:01 -0500 Subject: [PATCH 16/17] fix: comments and function name --- src/libs/ReportUtils.js | 8 ++++---- src/libs/actions/Task.js | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7d499f906c5c..e82fac0e34f5 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2775,18 +2775,18 @@ function getParentReport(report) { /** * 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 getAssigneeParentReportAction(taskReport) { +function getTaskParentReportActionIDInAssigneeReport(taskReport) { const assigneeChatReportID = lodashGet(getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); - // No need to go ahead if reports for assignee and shareDestination are the same if (!assigneeChatReportID || assigneeChatReportID === taskReport.parentReportID) { return {}; } - const clonedParentReportActionID = lodashGet(ReportActionsUtils.getParentReportActionInReport(taskReport.reportID, assigneeChatReportID), 'reportActionID', ''); + const clonedParentReportActionID = lodashGet(ReportActionsUtils.getParentReportActionInReport(taskReport.reportID, assigneeChatReportID), 'reportActionID'); if (!clonedParentReportActionID) { return {}; } @@ -2977,7 +2977,7 @@ export { getMoneyRequestAction, getBankAccountRoute, getParentReport, - getAssigneeParentReportAction, + getTaskParentReportActionIDInAssigneeReport, getReportPreviewMessage, shouldHideComposer, getOriginalReportID, diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index b8fe9dd8c779..c0823a182b9d 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -270,9 +270,10 @@ function completeTask(taskReport, taskTitle) { if (!_.isEmpty(optimisticDataForParentReportAction)) { optimisticData.push(optimisticDataForParentReportAction); } + // 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.getAssigneeParentReportAction(taskReport); + const assigneeReportAction = ReportUtils.getTaskParentReportActionIDInAssigneeReport(taskReport); if (!_.isEmpty(assigneeReportAction)) { const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( taskReportID, @@ -362,9 +363,10 @@ function reopenTask(taskReport, taskTitle) { if (!_.isEmpty(optimisticDataForParentReportAction)) { optimisticData.push(optimisticDataForParentReportAction); } + // 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.getAssigneeParentReportAction(taskReport); + const assigneeReportAction = ReportUtils.getTaskParentReportActionIDInAssigneeReport(taskReport); if (!_.isEmpty(assigneeReportAction)) { const optimisticDataForClonedParentReportAction = ReportUtils.getOptimisticDataForParentReportAction( taskReportID, From 5152ef3f5c1ed27b7320e470a8114d8dcad81c01 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Mon, 7 Aug 2023 11:52:33 -0500 Subject: [PATCH 17/17] fix: uncovered case for report with task owner when log in with assignee --- src/libs/ReportUtils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index e82fac0e34f5..501e712249a0 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2185,7 +2185,6 @@ function buildOptimisticTaskReport(ownerAccountID, assigneeAccountID = 0, parent description, ownerAccountID, managerID: assigneeAccountID, - participantAccountIDs: [assigneeAccountID], type: CONST.REPORT.TYPE.TASK, parentReportID, stateNum: CONST.REPORT.STATE_NUM.OPEN, @@ -2781,7 +2780,7 @@ function getParentReport(report) { * @returns {Object} */ function getTaskParentReportActionIDInAssigneeReport(taskReport) { - const assigneeChatReportID = lodashGet(getChatByParticipants(taskReport.participantAccountIDs), 'reportID'); + const assigneeChatReportID = lodashGet(getChatByParticipants(isTaskAssignee(taskReport) ? [taskReport.ownerAccountID] : [taskReport.managerID]), 'reportID'); if (!assigneeChatReportID || assigneeChatReportID === taskReport.parentReportID) { return {}; }