From b862234e5f8f97cdd8638acc7b1e88a3037bf6ba Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Mon, 31 Jul 2023 09:24:15 -0700 Subject: [PATCH 01/24] Add parent reportAction isDeletedParentAction --- src/components/ReportActionItem/TaskPreview.js | 7 +++++-- src/languages/en.js | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 740ab345fa74..b8b676a7e2b5 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -22,6 +22,7 @@ import * as ReportUtils from '../../libs/ReportUtils'; import RenderHTML from '../RenderHTML'; import PressableWithoutFeedback from '../Pressable/PressableWithoutFeedback'; import personalDetailsPropType from '../../pages/personalDetailsPropType'; +import * as ReportActionsUtils from '../../libs/ReportActionsUtils'; const propTypes = { /** All personal details asssociated with user */ @@ -71,8 +72,10 @@ function TaskPreview(props) { const assigneeDisplayName = lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'displayName'], ''); const taskAssignee = assigneeLogin || assigneeDisplayName; const htmlForTaskPreview = taskAssignee ? `@${taskAssignee} ${taskTitle}` : `${taskTitle}`; - - return ( + const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(props.action); + return isDeletedParentAction ? ( + ${props.translate('parentReportAction.deletedTask')}`} /> + ) : ( Navigation.navigate(ROUTES.getReportRoute(props.taskReportID))} diff --git a/src/languages/en.js b/src/languages/en.js index b7a130addf18..42e0de6eb037 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -1503,6 +1503,7 @@ export default { parentReportAction: { deletedMessage: '[Deleted message]', deletedRequest: '[Deleted request]', + deletedTask: '[Deleted task]', hiddenMessage: '[Hidden message]', }, threads: { From 69b67846de69452edd27e79d272f0126c6e54077 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Tue, 1 Aug 2023 15:00:54 -0700 Subject: [PATCH 02/24] Add isDeletedParentAction check --- src/pages/home/report/ReportActionItem.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 8c6defcb2951..00467a50def0 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -449,8 +449,8 @@ function ReportActionItem(props) { }; if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { - const parentReport = ReportActionsUtils.getParentReportAction(props.report); - if (ReportActionsUtils.isTransactionThread(parentReport)) { + const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); + if (ReportActionsUtils.isTransactionThread(parentReportAction)) { return ( ); } - if (ReportUtils.isTaskReport(props.report)) { + if (ReportUtils.isTaskReport(props.report) && !ReportActionsUtils.isDeletedParentAction(parentReportAction)) { return ( Date: Tue, 1 Aug 2023 15:21:07 -0700 Subject: [PATCH 03/24] Update header view on cancelled task --- src/pages/home/HeaderView.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 7622a0e73f18..1be79bb6fa92 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -31,6 +31,7 @@ import PinButton from '../../components/PinButton'; import Navigation from '../../libs/Navigation/Navigation'; import ROUTES from '../../ROUTES'; import TaskHeaderActionButton from '../../components/TaskHeaderActionButton'; +import * as ReportActionsUtils from '../../libs/ReportActionsUtils'; const propTypes = { /** Toggles the navigationMenu open and closed */ @@ -94,12 +95,14 @@ function HeaderView(props) { const isConcierge = ReportUtils.hasSingleParticipant(props.report) && _.contains(participants, CONST.ACCOUNT_ID.CONCIERGE); const isAutomatedExpensifyAccount = ReportUtils.hasSingleParticipant(props.report) && ReportUtils.hasAutomatedExpensifyAccountIDs(participants); const guideCalendarLink = lodashGet(props.account, 'guideCalendarLink'); + const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); + const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(parentReportAction); // We hide the button when we are chatting with an automated Expensify account since it's not possible to contact // these users via alternative means. It is possible to request a call with Concierge so we leave the option for them. const shouldShowCallButton = (isConcierge && guideCalendarLink) || (!isAutomatedExpensifyAccount && !isTaskReport); const threeDotMenuItems = []; - if (isTaskReport) { + if (isTaskReport && !isDeletedParentAction) { const isTaskAssigneeOrTaskOwner = Task.isTaskAssigneeOrTaskOwner(props.report, props.session.accountID); if (ReportUtils.isOpenTaskReport(props.report) && isTaskAssigneeOrTaskOwner) { threeDotMenuItems.push({ @@ -133,7 +136,7 @@ function HeaderView(props) { const defaultSubscriptSize = ReportUtils.isExpenseRequest(props.report) ? CONST.AVATAR_SIZE.SMALL_NORMAL : CONST.AVATAR_SIZE.DEFAULT; const icons = ReportUtils.getIcons(reportHeaderData, props.personalDetails); const brickRoadIndicator = ReportUtils.hasReportNameError(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; - const shouldShowBorderBottom = !isTaskReport || !props.isSmallScreenWidth; + const shouldShowBorderBottom = !props.isSmallScreenWidth; return ( Date: Tue, 1 Aug 2023 15:31:47 -0700 Subject: [PATCH 04/24] update the header --- src/libs/ReportUtils.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index f5d417fb0a79..4e400345a544 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1244,8 +1244,8 @@ function getReportPreviewMessage(report, reportAction = {}) { */ function getReportName(report, policy = undefined) { let formattedName; + const parentReportAction = ReportActionsUtils.getParentReportAction(report); if (isChatThread(report)) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); if (ReportActionsUtils.isTransactionThread(parentReportAction)) { return getTransactionReportName(parentReportAction); } @@ -1263,6 +1263,11 @@ function getReportName(report, policy = undefined) { } return parentReportActionMessage || Localize.translateLocal('parentReportAction.deletedMessage'); } + + if (isTaskReport(report) && ReportActionsUtils.isDeletedParentAction(parentReportAction)) { + return Localize.translateLocal('parentReportAction.deletedTask'); + } + if (isChatRoom(report) || isTaskReport(report)) { formattedName = report.reportName; } From 1c887daf3d549624ad5730c4df44281df68d955a Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Tue, 1 Aug 2023 17:36:03 -0700 Subject: [PATCH 05/24] add method to get all reportActions --- src/libs/ReportActionsUtils.js | 22 ++++++++++++++++++++++ src/libs/actions/Task.js | 1 + 2 files changed, 23 insertions(+) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 3cd5621e5e32..d6a59921dc0b 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -561,6 +561,27 @@ function isMessageDeleted(reportAction) { return lodashGet(reportAction, ['message', 0, 'isDeletedParentAction'], false); } +/** + * When you change assignees, a task created reportAction is added to that specific assignee's report. + * You can do this multiple times, so when we perform an action that modifies the parent report, we need to update all the parent report actions + * @param {*} taskReportID + * @returns {Array} taskCreatedReportActions + */ +function getTaskCreatedReportActions(taskReportID) { + const taskCreatedReportActions = []; + _.each(allReports, (report) => { + _.each(report.reportActions, (reportAction) => { + if (reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT || reportAction.originalMessage.taskReportID !== taskReportID) + { + return; + } + + taskCreatedReportActions.push(reportAction); + }); + }); + return taskCreatedReportActions; +} + export { getSortedReportActions, getLastVisibleAction, @@ -593,4 +614,5 @@ export { isWhisperAction, isPendingRemove, getReportAction, + getTaskCreatedReportActions, }; diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 3c6ddefbc32d..6bba6a052e75 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -621,6 +621,7 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum const message = `canceled task: ${taskTitle}`; const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED, message); const optimisticReportActionID = optimisticCancelReportAction.reportActionID; + const parentReportAction = ReportActionsUtils.getParentReportAction(taskReportID); const optimisticData = [ { From c9df9ce550c7415b34205b4b95fd3b66cad32334 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 2 Aug 2023 16:19:48 -0700 Subject: [PATCH 06/24] update cancelTask method --- src/languages/en.js | 2 +- src/libs/actions/Task.js | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index b6f947a7b0c1..507bd150b3ff 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -1332,7 +1332,7 @@ export default { completed: 'Completed', messages: { completed: 'completed task', - canceled: 'canceled task', + canceled: 'deleted task', reopened: 'reopened task', error: 'You do not have the permission to do the requested action.', }, diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 433f555168a9..5dc86635e5c4 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -618,20 +618,14 @@ function getShareDestination(reportID, reports, personalDetails) { * @param {number} originalStatusNum */ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum) { - const message = `canceled task: ${taskTitle}`; + const message = `deleted task: ${taskTitle}`; const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED, message); const optimisticReportActionID = optimisticCancelReportAction.reportActionID; - const parentReportAction = ReportActionsUtils.getParentReportAction(taskReportID); + const taskReport = ReportUtils.getReport(taskReportID); + const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); + const parentReport = ReportUtils.getParentReport(taskReport); const optimisticData = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, - value: { - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS.CLOSED, - }, - }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, @@ -648,6 +642,27 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum [optimisticReportActionID]: optimisticCancelReportAction, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport.reportID}`, + value: { + [parentReportAction.reportActionID]: { + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + previousMessage: parentReportAction.message, + message: { + translationKey: '', + type: 'COMMENT', + html: '', + text: '', + isEdited: true, + isDeletedParentAction: true, + }, + errors: null, + linkMetaData: [], + }, + }, + } + ]; const successData = [ From f640ac2bbd8010b262f48d147d24a198ea92d0bf Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 2 Aug 2023 17:14:38 -0700 Subject: [PATCH 07/24] fix message not showing up --- src/libs/actions/Task.js | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 5dc86635e5c4..8c94e1f73c31 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -625,6 +625,25 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); const parentReport = ReportUtils.getParentReport(taskReport); + const optimisticReportActions = { + [parentReportAction.reportActionID]: { + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + previousMessage: parentReportAction.message, + message: [{ + translationKey: '', + type: 'COMMENT', + html: '', + text: '', + isEdited: true, + isDeletedParentAction: true, + }], + errors: null, + linkMetaData: [], + }, + }; + + // TODO: Figure out some way to get the previous message to show in the LHN for the parent report + const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -633,6 +652,7 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum lastVisibleActionCreated: optimisticCancelReportAction.created, lastMessageText: message, lastActorAccountID: optimisticCancelReportAction.actorAccountID, + updateReportInLHN: true, }, }, { @@ -645,24 +665,8 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport.reportID}`, - value: { - [parentReportAction.reportActionID]: { - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, - previousMessage: parentReportAction.message, - message: { - translationKey: '', - type: 'COMMENT', - html: '', - text: '', - isEdited: true, - isDeletedParentAction: true, - }, - errors: null, - linkMetaData: [], - }, - }, - } - + value: optimisticReportActions, + }, ]; const successData = [ From 24fc6c8f2356ee8691313f048de644bfcd892b77 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 2 Aug 2023 17:40:55 -0700 Subject: [PATCH 08/24] show the parent --- src/components/ReportActionItem/TaskPreview.js | 12 ++++++++---- src/pages/home/report/ReportActionItem.js | 13 ++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index b8b676a7e2b5..d8298312df0d 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -73,9 +73,7 @@ function TaskPreview(props) { const taskAssignee = assigneeLogin || assigneeDisplayName; const htmlForTaskPreview = taskAssignee ? `@${taskAssignee} ${taskTitle}` : `${taskTitle}`; const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(props.action); - return isDeletedParentAction ? ( - ${props.translate('parentReportAction.deletedTask')}`} /> - ) : ( + return ( Navigation.navigate(ROUTES.getReportRoute(props.taskReportID))} @@ -83,7 +81,11 @@ function TaskPreview(props) { accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON} accessibilityLabel={props.translate('task.task')} > - + { + isDeletedParentAction ? ( + ${props.translate('parentReportAction.deletedTask')}`} /> + ) : ( + + ) + } ); } - if (ReportUtils.isTaskReport(props.report) && !ReportActionsUtils.isDeletedParentAction(parentReportAction)) { + if (ReportUtils.isTaskReport(props.report)) { + if (ReportActionsUtils.isDeletedParentAction(parentReportAction)) { + return ( + + ) + } + return ( Date: Thu, 3 Aug 2023 15:32:20 -0700 Subject: [PATCH 09/24] Remove the link in Preview isDeletedParentAction --- src/components/ReportActionItem/TaskPreview.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index d8298312df0d..9179858163d8 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -73,6 +73,11 @@ function TaskPreview(props) { const taskAssignee = assigneeLogin || assigneeDisplayName; const htmlForTaskPreview = taskAssignee ? `@${taskAssignee} ${taskTitle}` : `${taskTitle}`; const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(props.action); + + if (isDeletedParentAction) { + return ${props.translate('parentReportAction.deletedTask')}`} />; + } + return ( - { - isDeletedParentAction ? ( - ${props.translate('parentReportAction.deletedTask')}`} /> - ) : ( - + - ) - } + Date: Thu, 3 Aug 2023 16:04:01 -0700 Subject: [PATCH 10/24] Update method that checks isCanceledTaskReport --- src/libs/ReportUtils.js | 15 ++++++++++++--- src/pages/home/report/ReportActionItem.js | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d1d88986e385..f2402122eda0 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -159,13 +159,22 @@ function isOpenTaskReport(report) { } /** - * Checks if the current user is assigned to the task report + * Checks if a task has been cancelled + * When a task is deleted, the parentReportAction is updated to have a isDeletedParentAction deleted flag + * This is because when you delete a task, we still allow you to chat on the report itself + * There's another situation where you don't have access to the parentReportAction (because it was created in a chat you don't have access to) + * In this case, we have added the key to the report itself * * @param {Object} report + * @param {Object} parentReportAction * @returns {Boolean} */ -function isCanceledTaskReport(report) { - return isTaskReport(report) && report.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report.statusNum === CONST.REPORT.STATUS.CLOSED; +function isCanceledTaskReport(report, parentReportAction = {}) { + if (parentReportAction && ReportActionsUtils.isMessageDeleted(parentReportAction)) { + return true; + } + + return isTaskReport(report) && report.isDeletedParentAction; } /** diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 52ae9e688a16..de107bd139fc 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -463,9 +463,9 @@ function ReportActionItem(props) { if (ReportActionsUtils.isDeletedParentAction(parentReportAction)) { return ( ) } From 0665968fbda982bc2cc0e28edc55842326a6066e Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Thu, 3 Aug 2023 16:16:45 -0700 Subject: [PATCH 11/24] Update places we check isCancelled task report --- src/components/ReportActionItem/TaskPreview.js | 2 +- src/libs/ReportUtils.js | 10 +++++++--- src/pages/home/HeaderView.js | 4 ++-- src/pages/home/ReportScreen.js | 2 +- src/pages/home/report/ReportActionItem.js | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 9179858163d8..b1babba2c220 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -72,7 +72,7 @@ function TaskPreview(props) { const assigneeDisplayName = lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'displayName'], ''); const taskAssignee = assigneeLogin || assigneeDisplayName; const htmlForTaskPreview = taskAssignee ? `@${taskAssignee} ${taskTitle}` : `${taskTitle}`; - const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(props.action); + const isDeletedParentAction = ReportUtils.isCanceledTaskReport(props.taskReport, props.action); if (isDeletedParentAction) { return ${props.translate('parentReportAction.deletedTask')}`} />; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index f2402122eda0..14d7987ad09b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -169,12 +169,16 @@ function isOpenTaskReport(report) { * @param {Object} parentReportAction * @returns {Boolean} */ -function isCanceledTaskReport(report, parentReportAction = {}) { - if (parentReportAction && ReportActionsUtils.isMessageDeleted(parentReportAction)) { +function isCanceledTaskReport(report = {}, parentReportAction = {}) { + if (!_.isEmpty(parentReportAction) && ReportActionsUtils.isMessageDeleted(parentReportAction)) { return true; } - return isTaskReport(report) && report.isDeletedParentAction; + if (!_.isEmpty(report) && report.isDeletedParentAction) { + return true; + } + + return false; } /** diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 0d707239bb28..afd9d98c0391 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -95,13 +95,13 @@ function HeaderView(props) { const isAutomatedExpensifyAccount = ReportUtils.hasSingleParticipant(props.report) && ReportUtils.hasAutomatedExpensifyAccountIDs(participants); const guideCalendarLink = lodashGet(props.account, 'guideCalendarLink'); const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); - const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(parentReportAction); + const isCanceledTaskReport = ReportUtils.isCanceledTaskReport(props.report, parentReportAction); // We hide the button when we are chatting with an automated Expensify account since it's not possible to contact // these users via alternative means. It is possible to request a call with Concierge so we leave the option for them. const shouldShowCallButton = (isConcierge && guideCalendarLink) || (!isAutomatedExpensifyAccount && !isTaskReport); const threeDotMenuItems = []; - if (isTaskReport && !isDeletedParentAction) { + if (isTaskReport && !isCanceledTaskReport) { const canModifyTask = Task.canModifyTask(props.report, props.session.accountID); if (ReportUtils.isOpenTaskReport(props.report) && canModifyTask) { threeDotMenuItems.push({ diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 94fe5e2beb00..7036dc1c5c9f 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -328,7 +328,7 @@ class ReportScreen extends React.Component { needsOffscreenAlphaCompositing > {headerView} - {ReportUtils.isTaskReport(this.props.report) && this.props.isSmallScreenWidth && ReportUtils.isOpenTaskReport(this.props.report) && ( + {ReportUtils.isTaskReport(this.props.report) && this.props.isSmallScreenWidth && ReportUtils.isOpenTaskReport(this.props.report) && !ReportUtils.isCanceledTaskReport(this.props.report, parentReportAction) && ( diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index de107bd139fc..1a7c5cd65d0e 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -460,7 +460,7 @@ function ReportActionItem(props) { ); } if (ReportUtils.isTaskReport(props.report)) { - if (ReportActionsUtils.isDeletedParentAction(parentReportAction)) { + if (ReportUtils.isCanceledTaskReport(props.taskReport, parentReportAction)) { return ( Date: Thu, 3 Aug 2023 16:27:20 -0700 Subject: [PATCH 12/24] Update places isCanceledTaskReport --- src/libs/ReportUtils.js | 4 ++-- src/pages/home/HeaderView.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 14d7987ad09b..9c7d95162a5b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -170,7 +170,7 @@ function isOpenTaskReport(report) { * @returns {Boolean} */ function isCanceledTaskReport(report = {}, parentReportAction = {}) { - if (!_.isEmpty(parentReportAction) && ReportActionsUtils.isMessageDeleted(parentReportAction)) { + if (!_.isEmpty(parentReportAction) && lodashGet(parentReportAction, ['message', 0, 'isDeletedParentAction'], false)) { return true; } @@ -1328,7 +1328,7 @@ function getReportName(report, policy = undefined) { return parentReportActionMessage || Localize.translateLocal('parentReportAction.deletedMessage'); } - if (isTaskReport(report) && ReportActionsUtils.isDeletedParentAction(parentReportAction)) { + if (isTaskReport(report) && isCanceledTaskReport(report, parentReportAction)) { return Localize.translateLocal('parentReportAction.deletedTask'); } diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index afd9d98c0391..f7eefce127b9 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -218,7 +218,7 @@ function HeaderView(props) { )} - {isTaskReport && !props.isSmallScreenWidth && ReportUtils.isOpenTaskReport(props.report) && } + {isTaskReport && !props.isSmallScreenWidth && ReportUtils.isOpenTaskReport(props.report) && !isCanceledTaskReport && } {shouldShowCallButton && ( Date: Thu, 3 Aug 2023 16:27:31 -0700 Subject: [PATCH 13/24] onyx updates --- src/libs/ReportActionsUtils.js | 7 +++---- src/libs/actions/Task.js | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index d6a59921dc0b..495e79558071 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -564,18 +564,17 @@ function isMessageDeleted(reportAction) { /** * When you change assignees, a task created reportAction is added to that specific assignee's report. * You can do this multiple times, so when we perform an action that modifies the parent report, we need to update all the parent report actions - * @param {*} taskReportID + * @param {*} taskReportID * @returns {Array} taskCreatedReportActions */ function getTaskCreatedReportActions(taskReportID) { const taskCreatedReportActions = []; _.each(allReports, (report) => { _.each(report.reportActions, (reportAction) => { - if (reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT || reportAction.originalMessage.taskReportID !== taskReportID) - { + if (reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT || reportAction.originalMessage.taskReportID !== taskReportID) { return; } - + taskCreatedReportActions.push(reportAction); }); }); diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 97b105e3a8ad..9d4f2e0f0417 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -651,14 +651,16 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum [parentReportAction.reportActionID]: { pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, previousMessage: parentReportAction.message, - message: [{ - translationKey: '', - type: 'COMMENT', - html: '', - text: '', - isEdited: true, - isDeletedParentAction: true, - }], + message: [ + { + translationKey: '', + type: 'COMMENT', + html: '', + text: '', + isEdited: true, + isDeletedParentAction: true, + }, + ], errors: null, linkMetaData: [], }, @@ -675,6 +677,7 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum lastMessageText: message, lastActorAccountID: optimisticCancelReportAction.actorAccountID, updateReportInLHN: true, + isDeletedParentAction: true, }, }, { From 84d289b9a0e19cdf3f59104089e0bc036091bd56 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Thu, 3 Aug 2023 16:41:49 -0700 Subject: [PATCH 14/24] pass the actual report --- src/pages/home/report/ReportActionItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 1a7c5cd65d0e..3c2f4ce7c438 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -460,7 +460,7 @@ function ReportActionItem(props) { ); } if (ReportUtils.isTaskReport(props.report)) { - if (ReportUtils.isCanceledTaskReport(props.taskReport, parentReportAction)) { + if (ReportUtils.isCanceledTaskReport(props.report, parentReportAction)) { return ( Date: Thu, 10 Aug 2023 16:42:08 -0700 Subject: [PATCH 15/24] Make sure we don't include cancelled tasks in the selector --- src/pages/tasks/TaskShareDestinationSelectorModal.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.js b/src/pages/tasks/TaskShareDestinationSelectorModal.js index 8272406b4cbe..61d6868ebb1e 100644 --- a/src/pages/tasks/TaskShareDestinationSelectorModal.js +++ b/src/pages/tasks/TaskShareDestinationSelectorModal.js @@ -52,7 +52,8 @@ function TaskShareDestinationSelectorModal(props) { if ( !ReportUtils.isAllowedToComment(props.reports[reportKey]) || ReportUtils.isArchivedRoom(props.reports[reportKey]) || - ReportUtils.isExpensifyOnlyParticipantInReport(props.reports[reportKey]) + ReportUtils.isExpensifyOnlyParticipantInReport(props.reports[reportKey]) || + ReportUtils.isCanceledTaskReport(props.reports[reportKey]) ) { return; } From 61bc6ae3bcdee5484e966a70523c635da1be5736 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Thu, 17 Aug 2023 11:43:09 -0500 Subject: [PATCH 16/24] Add RenderHTML to show deleted reportAction --- src/components/ReportActionItem/TaskPreview.js | 1 - src/pages/home/report/ReportActionItem.js | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 4f2c2c7dab8b..37a53aba35c4 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -22,7 +22,6 @@ import * as ReportUtils from '../../libs/ReportUtils'; import RenderHTML from '../RenderHTML'; import PressableWithoutFeedback from '../Pressable/PressableWithoutFeedback'; import personalDetailsPropType from '../../pages/personalDetailsPropType'; -import * as ReportActionsUtils from '../../libs/ReportActionsUtils'; import * as Session from '../../libs/actions/Session'; const propTypes = { diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 2d2b090b75ae..9eb83e5c6648 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -66,6 +66,7 @@ import * as store from '../../../libs/actions/ReimbursementAccount/store'; import * as BankAccounts from '../../../libs/actions/BankAccounts'; import ReportScreenContext from '../ReportScreenContext'; import Permissions from '../../../libs/Permissions'; +import RenderHTML from '../../../components/RenderHTML'; const propTypes = { ...windowDimensionsPropTypes, @@ -484,7 +485,9 @@ function ReportActionItem(props) { showHeader={!props.draftMessage} wrapperStyles={[styles.chatItem]} report={props.report} - /> + > + ${props.translate('parentReportAction.deletedTask')}`} /> + ) } From 1d0064ee071babf270f9c44c7660c5c093bb6bfd Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 30 Aug 2023 15:46:29 -0700 Subject: [PATCH 17/24] Move around Cancel Task check --- src/libs/ReportUtils.js | 21 +++++++++++---------- src/pages/home/ReportScreen.js | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index b5c3c7a82b32..680b0a1720fe 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -184,16 +184,6 @@ function isTaskReport(report) { return lodashGet(report, 'type') === CONST.REPORT.TYPE.TASK; } -/** - * Checks if a report is an open task report. - * - * @param {Object} report - * @returns {Boolean} - */ -function isOpenTaskReport(report) { - return isTaskReport(report) && report.stateNum === CONST.REPORT.STATE_NUM.OPEN && report.statusNum === CONST.REPORT.STATUS.OPEN; -} - /** * Checks if a task has been cancelled * When a task is deleted, the parentReportAction is updated to have a isDeletedParentAction deleted flag @@ -217,6 +207,17 @@ function isCanceledTaskReport(report = {}, parentReportAction = {}) { return false; } +/** + * Checks if a report is an open task report. + * + * @param {Object} report + * @param {Object} parentReportAction - The parent report action of the report (Used to check if the task has been canceled) + * @returns {Boolean} + */ +function isOpenTaskReport(report, parentReportAction = {}) { + return isTaskReport(report) && !isCanceledTaskReport(report, parentReportAction) && report.stateNum === CONST.REPORT.STATE_NUM.OPEN && report.statusNum === CONST.REPORT.STATUS.OPEN; +} + /** * Checks if a report is a completed task report. * diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 910907372191..bd4fd1e9b0da 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -310,7 +310,7 @@ function ReportScreen({ needsOffscreenAlphaCompositing > {headerView} - {ReportUtils.isTaskReport(report) && isSmallScreenWidth &&ReportUtils.isOpenTaskReport(this.props.report) && !ReportUtils.isCanceledTaskReport(this.props.report, parentReportAction) && ( + {ReportUtils.isTaskReport(report) && isSmallScreenWidth && ReportUtils.isOpenTaskReport(this.props.report, parentReportAction) && ( From 52b3f9c1d0a9d9f091b9af1ddb3a6bc5a7f2881c Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 30 Aug 2023 15:52:05 -0700 Subject: [PATCH 18/24] Clean up items related to new openTask check --- src/components/ReportActionItem/TaskPreview.js | 1 - src/pages/home/HeaderView.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 37a53aba35c4..d0181e3d736a 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -103,7 +103,6 @@ function TaskPreview(props) { /> - - {isTaskReport && !props.isSmallScreenWidth && ReportUtils.isOpenTaskReport(props.report) && !isCanceledTaskReport && } + {isTaskReport && !props.isSmallScreenWidth && ReportUtils.isOpenTaskReport(props.report) && } {shouldShowCallButton && ( Date: Mon, 11 Sep 2023 16:33:56 +0800 Subject: [PATCH 19/24] add parent update --- src/libs/actions/Task.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index c3309b32de20..9db62a5e441a 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -774,7 +774,7 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum const optimisticReportActions = { [parentReportAction.reportActionID]: { - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, previousMessage: parentReportAction.message, message: [ { @@ -791,8 +791,6 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum }, }; - // TODO: Figure out some way to get the previous message to show in the LHN for the parent report - const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -805,6 +803,14 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum isDeletedParentAction: true, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, + value: { + lastMessageText: ReportActionsUtils.getLastVisibleMessage(parentReport.reportID, {[parentReportAction.reportActionID]: null}).lastMessageText, + lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(parentReport.reportID, {[parentReportAction.reportActionID]: null}).created, + } + }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`, From 59e8fffa114bb76ace432785da61eb80c5ffc3d0 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Mon, 11 Sep 2023 16:40:41 +0800 Subject: [PATCH 20/24] remove the method for getting all created task reportActions --- src/libs/ReportActionsUtils.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 8dcaca8180d0..fd2e9b436b7a 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -576,26 +576,6 @@ function isMessageDeleted(reportAction) { return lodashGet(reportAction, ['message', 0, 'isDeletedParentAction'], false); } -/** - * When you change assignees, a task created reportAction is added to that specific assignee's report. - * You can do this multiple times, so when we perform an action that modifies the parent report, we need to update all the parent report actions - * @param {*} taskReportID - * @returns {Array} taskCreatedReportActions - */ -function getTaskCreatedReportActions(taskReportID) { - const taskCreatedReportActions = []; - _.each(allReports, (report) => { - _.each(report.reportActions, (reportAction) => { - if (reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT || reportAction.originalMessage.taskReportID !== taskReportID) { - return; - } - - taskCreatedReportActions.push(reportAction); - }); - }); - return taskCreatedReportActions; -} - /* * Returns the number of money requests associated with a report preview * From 3de64e19414ae2fc7c07474adda4e3bf35eaf1cc Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Mon, 11 Sep 2023 16:56:25 +0800 Subject: [PATCH 21/24] component got converted --- src/pages/home/ReportScreen.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index c9b0805cf140..1fd3b30e3c02 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -314,7 +314,7 @@ function ReportScreen({ needsOffscreenAlphaCompositing > {headerView} - {ReportUtils.isTaskReport(report) && isSmallScreenWidth && ReportUtils.isOpenTaskReport(this.props.report, parentReportAction) && ( + {ReportUtils.isTaskReport(report) && isSmallScreenWidth && ReportUtils.isOpenTaskReport(report, parentReportAction) && ( From 4bb1b319ea3c135999ba9ec37600b712ce6bc6a1 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Mon, 11 Sep 2023 16:57:26 +0800 Subject: [PATCH 22/24] prettier, fix compilation issues --- src/libs/ReportActionsUtils.js | 1 - src/libs/ReportUtils.js | 2 +- src/libs/actions/Task.js | 2 +- src/pages/home/report/ReportActionItem.js | 4 ++-- src/pages/tasks/TaskShareDestinationSelectorModal.js | 6 +++++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index fd2e9b436b7a..c1b6432c5a3c 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -649,7 +649,6 @@ export { isWhisperAction, isPendingRemove, getReportAction, - getTaskCreatedReportActions, getNumberOfMoneyRequests, isSplitBillAction, isTaskAction, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 655dda7ba8a0..ef436c15c788 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -217,7 +217,7 @@ function isCanceledTaskReport(report = {}, parentReportAction = {}) { /** * Checks if a report is an open task report. - * + * * @param {Object} report * @param {Object} parentReportAction - The parent report action of the report (Used to check if the task has been canceled) * @returns {Boolean} diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 9db62a5e441a..72f5d2a7736f 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -809,7 +809,7 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum value: { lastMessageText: ReportActionsUtils.getLastVisibleMessage(parentReport.reportID, {[parentReportAction.reportActionID]: null}).lastMessageText, lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(parentReport.reportID, {[parentReportAction.reportActionID]: null}).created, - } + }, }, { onyxMethod: Onyx.METHOD.MERGE, diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index fa1b549ec2fa..3c9ac01fedfb 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -507,10 +507,10 @@ function ReportActionItem(props) { showHeader={!props.draftMessage} wrapperStyles={[styles.chatItem]} report={props.report} - > + > ${props.translate('parentReportAction.deletedTask')}`} /> - ) + ); } return ( diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.js b/src/pages/tasks/TaskShareDestinationSelectorModal.js index 3369e190a426..a6db3d80c03e 100644 --- a/src/pages/tasks/TaskShareDestinationSelectorModal.js +++ b/src/pages/tasks/TaskShareDestinationSelectorModal.js @@ -49,7 +49,11 @@ function TaskShareDestinationSelectorModal(props) { const filteredReports = useMemo(() => { const reports = {}; _.keys(props.reports).forEach((reportKey) => { - if (ReportUtils.shouldDisableWriteActions(props.reports[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(props.reports[reportKey]) || ReportUtils.isCanceledTaskReport(props.reports[reportKey])) { + if ( + ReportUtils.shouldDisableWriteActions(props.reports[reportKey]) || + ReportUtils.isExpensifyOnlyParticipantInReport(props.reports[reportKey]) || + ReportUtils.isCanceledTaskReport(props.reports[reportKey]) + ) { return; } reports[reportKey] = props.reports[reportKey]; From b35d7586494422006adedeabba58234f094c4f5e Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Mon, 11 Sep 2023 17:14:12 +0800 Subject: [PATCH 23/24] Add translations --- src/languages/es.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index 8610f41308e1..aaf1d4051c8b 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1537,7 +1537,7 @@ export default { completed: 'Completada', messages: { completed: 'tarea completada', - canceled: 'tarea cancelada', + canceled: 'tarea eliminado', reopened: 'tarea reabrir', error: 'No tiene permiso para realizar la acción solicitada.', }, @@ -2169,6 +2169,7 @@ export default { parentReportAction: { deletedMessage: '[Mensaje eliminado]', deletedRequest: '[Pedido eliminado]', + deletedTask: '[Tarea eliminado]', hiddenMessage: '[Mensaje oculto]', }, threads: { From e80fd05c5b044907f68523c5b508216ee0114983 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Tue, 12 Sep 2023 14:04:12 +0800 Subject: [PATCH 24/24] Add horizontal rule --- src/libs/ReportActionsUtils.js | 2 +- src/pages/home/report/ReportActionItem.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index c1b6432c5a3c..9bb365c0f42a 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -576,7 +576,7 @@ function isMessageDeleted(reportAction) { return lodashGet(reportAction, ['message', 0, 'isDeletedParentAction'], false); } -/* +/** * Returns the number of money requests associated with a report preview * * @param {Object|null} reportPreviewAction diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 3c9ac01fedfb..408ac694858c 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -502,14 +502,17 @@ function ReportActionItem(props) { if (ReportUtils.isTaskReport(props.report)) { if (ReportUtils.isCanceledTaskReport(props.report, parentReportAction)) { return ( - - ${props.translate('parentReportAction.deletedTask')}`} /> - + <> + + ${props.translate('parentReportAction.deletedTask')}`} /> + + + ); }