From 48fb202b6b9dd03c460fbccebea45aae07536fc6 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Mon, 16 Oct 2023 16:01:03 -0700 Subject: [PATCH 1/6] allow new accounts --- src/pages/tasks/TaskAssigneeSelectorModal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index bfa3ac884e4a..1935e97aab1f 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -98,7 +98,7 @@ function TaskAssigneeSelectorModal(props) { false, {}, [], - false, + true, ); setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0 || currentUserOption, Boolean(userToInvite), searchValue)); From 7c84211eef5f195a9322f514c51207f9fe01b813 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 20 Dec 2023 15:06:44 -0800 Subject: [PATCH 2/6] Update cancel to delete --- 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 2182cc5f6359..4bf363d33d70 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -135,7 +135,7 @@ function HeaderView(props) { if (props.report.stateNum !== CONST.REPORT.STATE_NUM.SUBMITTED && props.report.statusNum !== CONST.REPORT.STATUS.CLOSED && canModifyTask) { threeDotMenuItems.push({ icon: Expensicons.Trashcan, - text: translate('common.cancel'), + text: translate('common.delete'), onSelected: Session.checkIfActionIsAllowed(() => Task.cancelTask(props.report.reportID, props.report.reportName, props.report.stateNum, props.report.statusNum)), }); } From cad48f12b663047776e403ddba576754f81d8e53 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Thu, 21 Dec 2023 14:05:18 -0800 Subject: [PATCH 3/6] Redirect to parent report if the task should be deleted --- src/libs/actions/Task.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 0fe6a528cda1..53d47dc9827e 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -720,6 +720,11 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); const parentReport = ReportUtils.getParentReport(taskReport); + // Determine if we should remove the task completely if there are no other visible actions on it + const lastMessageText = ReportActionsUtils.getLastVisibleMessage(taskReportID).lastMessageText; + const shouldDeleteTask = !lastMessageText || lastMessageText.length === 0; + + const optimisticReportActions = { [parentReportAction.reportActionID]: { pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, @@ -821,6 +826,10 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum ]; API.write('CancelTask', {cancelledTaskReportActionID: optimisticReportActionID, taskReportID}, {optimisticData, successData, failureData}); + + if (shouldDeleteTask) { + Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(parentReport.reportID)); + } } /** From 819fe34eee6af0fad5a7f45d7feee2e83e784ff8 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Thu, 21 Dec 2023 14:06:35 -0800 Subject: [PATCH 4/6] Update Task.js --- src/libs/actions/Task.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 53d47dc9827e..06a2240614b0 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -724,7 +724,6 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum const lastMessageText = ReportActionsUtils.getLastVisibleMessage(taskReportID).lastMessageText; const shouldDeleteTask = !lastMessageText || lastMessageText.length === 0; - const optimisticReportActions = { [parentReportAction.reportActionID]: { pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, From c04a5daec99991f651d4016eea7c16bace9f4108 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Fri, 22 Dec 2023 09:45:06 -0800 Subject: [PATCH 5/6] Review comments / add new method to determine when to delete --- src/libs/ReportActionsUtils.ts | 14 ++++++++++++++ src/libs/actions/Task.js | 11 +++++------ src/pages/home/HeaderView.js | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 4847eee2c8c6..bef9e391f099 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -640,6 +640,19 @@ function isTaskAction(reportAction: OnyxEntry): boolean { ); } +/** + * When we delete certain reports, we want to check whether there are any visible actions left to display. + * If there are no visible actions left (including system messages), we can hide the report from view entirely + */ +function doesReportHaveVisibleActions(reportID: string, actionsToMerge: ReportActions = {}): boolean { + const reportActions = Object.values(OnyxUtils.fastMerge(allReportActions?.[reportID] ?? {}, actionsToMerge)); + const visibleReportActions = Object.values(reportActions ?? {}).filter((action) => shouldReportActionBeVisibleAsLastAction(action)); + + // Exclude the task system message and the created message + const visibleReportActionsWithoutTaskSystemMessage = visibleReportActions.filter((action) => !isTaskAction(action) && !isCreatedAction(action)); + return visibleReportActionsWithoutTaskSystemMessage.length > 0; +} + function getAllReportActions(reportID: string): ReportActions { return allReportActions?.[reportID] ?? {}; } @@ -811,6 +824,7 @@ export { isSentMoneyReportAction, isSplitBillAction, isTaskAction, + doesReportHaveVisibleActions, isThreadParentMessage, isTransactionThread, isWhisperAction, diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 06a2240614b0..d138cc75f8f5 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -712,7 +712,7 @@ function getShareDestination(reportID, reports, personalDetails) { * @param {number} originalStateNum * @param {number} originalStatusNum */ -function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum) { +function deleteTask(taskReportID, taskTitle, originalStateNum, originalStatusNum) { const message = `deleted task: ${taskTitle}`; const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED, message); const optimisticReportActionID = optimisticCancelReportAction.reportActionID; @@ -720,9 +720,8 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); const parentReport = ReportUtils.getParentReport(taskReport); - // Determine if we should remove the task completely if there are no other visible actions on it - const lastMessageText = ReportActionsUtils.getLastVisibleMessage(taskReportID).lastMessageText; - const shouldDeleteTask = !lastMessageText || lastMessageText.length === 0; + // We only want to prevent closing if there are comments that are not + const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(taskReportID); const optimisticReportActions = { [parentReportAction.reportActionID]: { @@ -826,7 +825,7 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum API.write('CancelTask', {cancelledTaskReportActionID: optimisticReportActionID, taskReportID}, {optimisticData, successData, failureData}); - if (shouldDeleteTask) { + if (shouldDeleteTaskReport) { Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(parentReport.reportID)); } } @@ -935,7 +934,7 @@ export { clearOutTaskInfoAndNavigate, getAssignee, getShareDestination, - cancelTask, + deleteTask, dismissModalAndClearOutTaskInfo, getTaskAssigneeAccountID, clearTaskErrors, diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 4bf363d33d70..e57221763b25 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -136,7 +136,7 @@ function HeaderView(props) { threeDotMenuItems.push({ icon: Expensicons.Trashcan, text: translate('common.delete'), - onSelected: Session.checkIfActionIsAllowed(() => Task.cancelTask(props.report.reportID, props.report.reportName, props.report.stateNum, props.report.statusNum)), + onSelected: Session.checkIfActionIsAllowed(() => Task.deleteTask(props.report.reportID, props.report.reportName, props.report.stateNum, props.report.statusNum)), }); } } From 3461f6bf5b4b42f0b3e10f04d0c3c5c562a02460 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Fri, 22 Dec 2023 09:47:12 -0800 Subject: [PATCH 6/6] Update comment --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index d138cc75f8f5..a6d69186a98a 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -720,7 +720,7 @@ function deleteTask(taskReportID, taskTitle, originalStateNum, originalStatusNum const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport); const parentReport = ReportUtils.getParentReport(taskReport); - // We only want to prevent closing if there are comments that are not + // If the task report is the last visible action in the parent report, we should navigate back to the parent report const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(taskReportID); const optimisticReportActions = {