From ee421cf67d2cbfc273499f490b4e1e75ab76ead7 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 8 Jan 2025 12:23:13 +0100 Subject: [PATCH 1/4] Remove Task.ts from the ignored list --- .eslintrc.changed.js | 1 - src/libs/actions/Task.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.eslintrc.changed.js b/.eslintrc.changed.js index 55472b10ea86..16c60f6edae1 100644 --- a/.eslintrc.changed.js +++ b/.eslintrc.changed.js @@ -13,7 +13,6 @@ module.exports = { files: [ 'src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', - 'src/libs/actions/Task.ts', 'src/libs/OptionsListUtils.ts', 'src/libs/TransactionUtils/index.ts', 'src/pages/home/ReportScreen.tsx', diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 2b4b8fe73ccc..bd41d234618d 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -619,8 +619,8 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as const reportName = report.reportName?.trim(); let assigneeChatReportOnyxData; - const assigneeChatReportID = assigneeChatReport ? assigneeChatReport.reportID : '-1'; - const assigneeChatReportMetadata = ReportUtils.getReportMetadata(assigneeChatReport?.reportID); + const assigneeChatReportID = assigneeChatReport?.reportID; + const assigneeChatReportMetadata = ReportUtils.getReportMetadata(assigneeChatReportID); const parentReport = getParentReport(report); const taskOwnerAccountID = getTaskOwnerAccountID(report); const optimisticReport: OptimisticReport = { From 775a841c11f2b705c8e322b5ddc092a7d7eb7dd9 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 8 Jan 2025 14:45:57 +0100 Subject: [PATCH 2/4] Align default IDs usage for the Task.ts file --- src/libs/ReportUtils.ts | 2 +- src/libs/actions/Task.ts | 55 +++++++++++++++------------------------- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 54e7e6a330a7..09e3671b0df9 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8044,7 +8044,7 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ * @param lastVisibleActionCreated Last visible action created of the child report * @param type The type of action in the child report */ -function getOptimisticDataForParentReportAction(reportID: string, lastVisibleActionCreated: string, type: string): Array { +function getOptimisticDataForParentReportAction(reportID: string | undefined, lastVisibleActionCreated: string, type: string): Array { const report = getReportOrDraftReport(reportID); if (!report || isEmptyObject(report)) { diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index bd41d234618d..0659d5df2cd7 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -125,7 +125,7 @@ function createTaskAndNavigate( ) { const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserAccountID, assigneeAccountID, parentReportID, title, description, policyID); - const assigneeChatReportID = assigneeChatReport?.reportID ?? '-1'; + const assigneeChatReportID = assigneeChatReport?.reportID; const taskReportID = optimisticTaskReport.reportID; let assigneeChatReportOnyxData; @@ -220,7 +220,7 @@ function createTaskAndNavigate( }, ]; - if (assigneeChatReport) { + if (assigneeChatReport && assigneeChatReportID) { assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData( currentUserAccountID, assigneeAccountID, @@ -712,7 +712,7 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as // If we make a change to the assignee, we want to add a comment to the assignee's chat // Check if the assignee actually changed - if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== sessionAccountID && assigneeChatReport) { + if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== sessionAccountID && assigneeChatReport && assigneeChatReport && assigneeChatReportID) { optimisticReport.participants = { ...(optimisticReport.participants ?? {}), [assigneeAccountID]: { @@ -724,8 +724,9 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as currentUserAccountID, assigneeAccountID, report.reportID, - assigneeChatReportID ?? '-1', - report.parentReportID ?? '-1', + assigneeChatReportID, + // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style + report.parentReportID as string, reportName ?? '', assigneeChatReport, ); @@ -784,7 +785,7 @@ function setDescriptionValue(description: string) { /** * Sets the shareDestination value for the task */ -function setShareDestinationValue(shareDestination: string) { +function setShareDestinationValue(shareDestination: string | undefined) { // This is only needed for creation of a new task and so it should only be stored locally Onyx.merge(ONYXKEYS.TASK, {shareDestination}); } @@ -844,7 +845,7 @@ function setAssigneeValue( // If there is no share destination set, automatically set it to the assignee chat report // This allows for a much quicker process when creating a new task and is likely the desired share destination most times if (!shareToReportID && !skipShareDestination) { - setShareDestinationValue(selfDMReportID ?? '-1'); + setShareDestinationValue(selfDMReportID); } } else { // Check for the chatReport by participants IDs @@ -871,7 +872,7 @@ function setAssigneeValue( // If there is no share destination set, automatically set it to the assignee chat report // This allows for a much quicker process when creating a new task and is likely the desired share destination most times if (!shareToReportID && !skipShareDestination) { - setShareDestinationValue(report?.reportID ?? '-1'); + setShareDestinationValue(report?.reportID); } } @@ -1002,7 +1003,7 @@ function getNavigationUrlOnTaskDelete(report: OnyxEntry): stri return undefined; } - const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(report.reportID ?? '-1'); + const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(report.reportID); if (!shouldDeleteTaskReport) { return undefined; } @@ -1030,14 +1031,14 @@ function deleteTask(report: OnyxEntry) { return; } const message = `deleted task: ${report.reportName}`; - const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(report.reportID ?? '-1', CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message); + const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(report.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message); const optimisticReportActionID = optimisticCancelReportAction.reportActionID; const parentReportAction = getParentReportAction(report); const parentReport = getParentReport(report); const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report); // 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(report.reportID ?? '-1', canUserPerformWriteAction); + const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(report.reportID, canUserPerformWriteAction); const optimisticReportAction: Partial = { pendingAction: shouldDeleteTaskReport ? CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, previousMessage: parentReportAction?.message, @@ -1054,9 +1055,7 @@ function deleteTask(report: OnyxEntry) { errors: undefined, linkMetadata: [], }; - const optimisticReportActions = { - [parentReportAction?.reportActionID ?? '-1']: optimisticReportAction, - }; + const optimisticReportActions = parentReportAction?.reportActionID ? {[parentReportAction?.reportActionID]: optimisticReportAction} : {}; const hasOutstandingChildTask = getOutstandingChildTask(report); const optimisticData: OnyxUpdate[] = [ @@ -1075,13 +1074,9 @@ function deleteTask(report: OnyxEntry) { key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport?.reportID}`, value: { lastMessageText: - ReportActionsUtils.getLastVisibleMessage(parentReport?.reportID ?? '-1', canUserPerformWriteAction, optimisticReportActions as OnyxTypes.ReportActions).lastMessageText ?? - '', - lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction( - parentReport?.reportID ?? '-1', - canUserPerformWriteAction, - optimisticReportActions as OnyxTypes.ReportActions, - )?.created, + ReportActionsUtils.getLastVisibleMessage(parentReport?.reportID, canUserPerformWriteAction, optimisticReportActions as OnyxTypes.ReportActions).lastMessageText ?? '', + lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(parentReport?.reportID, canUserPerformWriteAction, optimisticReportActions as OnyxTypes.ReportActions) + ?.created, hasOutstandingChildTask, }, }, @@ -1103,7 +1098,7 @@ function deleteTask(report: OnyxEntry) { const childVisibleActionCount = parentReportAction?.childVisibleActionCount ?? 0; if (childVisibleActionCount === 0) { const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction( - parentReport?.reportID ?? '-1', + parentReport?.reportID, parentReport?.lastVisibleActionCreated ?? '', CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, ); @@ -1128,11 +1123,7 @@ function deleteTask(report: OnyxEntry) { { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`, - value: { - [parentReportAction?.reportActionID ?? '-1']: { - pendingAction: null, - }, - }, + value: parentReportAction?.reportActionID ? {[parentReportAction.reportActionID]: {pendingAction: null}} : {}, }, ]; @@ -1162,11 +1153,7 @@ function deleteTask(report: OnyxEntry) { { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`, - value: { - [parentReportAction?.reportActionID ?? '-1']: { - pendingAction: null, - }, - }, + value: parentReportAction?.reportActionID ? {[parentReportAction?.reportActionID]: {pendingAction: null}} : {}, }, ]; @@ -1270,9 +1257,7 @@ function clearTaskErrors(reportID: string) { // Delete the task preview in the parent report if (report?.pendingFields?.createChat === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, { - [report.parentReportActionID ?? -1]: null, - }); + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, report.parentReportActionID ? {[report.parentReportActionID]: null} : {}); Report.navigateToConciergeChatAndDeleteReport(reportID); return; From 456270bff797fae38d2763aaa799fae566c53cbf Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 8 Jan 2025 14:49:03 +0100 Subject: [PATCH 3/4] Remove TransactionUtils from ignored files --- .eslintrc.changed.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.eslintrc.changed.js b/.eslintrc.changed.js index 16c60f6edae1..2ea8c1802879 100644 --- a/.eslintrc.changed.js +++ b/.eslintrc.changed.js @@ -14,7 +14,6 @@ module.exports = { 'src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', 'src/libs/OptionsListUtils.ts', - 'src/libs/TransactionUtils/index.ts', 'src/pages/home/ReportScreen.tsx', 'src/pages/workspace/WorkspaceInitialPage.tsx', 'src/pages/home/report/PureReportActionItem.tsx', From af1311a65774cb336401c4acdd7c34d580934ac9 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Fri, 10 Jan 2025 11:29:33 +0100 Subject: [PATCH 4/4] Remove type assertion --- src/libs/ReportUtils.ts | 4 ++-- src/libs/actions/Task.ts | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 09e3671b0df9..09edfcfcdcee 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4595,7 +4595,7 @@ function buildOptimisticTaskCommentReportAction( taskTitle: string, taskAssigneeAccountID: number, text: string, - parentReportID: string, + parentReportID: string | undefined, actorAccountID?: number, createdOffset = 0, ): OptimisticReportAction { @@ -7514,7 +7514,7 @@ function getTaskAssigneeChatOnyxData( assigneeAccountID: number, taskReportID: string, assigneeChatReportID: string, - parentReportID: string, + parentReportID: string | undefined, title: string, assigneeChatReport: OnyxEntry, ): OnyxDataTaskAssigneeChat { diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 0659d5df2cd7..75cb4d5527ac 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -725,8 +725,7 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as assigneeAccountID, report.reportID, assigneeChatReportID, - // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style - report.parentReportID as string, + report.parentReportID, reportName ?? '', assigneeChatReport, );