From 0301d8193e8f35b133fd4d313752b765ff0b1344 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 27 Sep 2024 00:39:45 +0300 Subject: [PATCH 1/4] update parent report actions on hold and unhold --- src/libs/actions/IOU.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index bc553ea86d70..7b529911ca03 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7864,6 +7864,8 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea const newViolation = {name: CONST.VIOLATIONS.HOLD, type: CONST.VIOLATION_TYPES.VIOLATION}; const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] ?? []; const updatedViolations = [...transactionViolations, newViolation]; + const parentReportActionOptimistic = ReportUtils.getOptimisticDataForParentReportAction(reportID, createdReportActionComment.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -7873,6 +7875,13 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea [createdReportActionComment.reportActionID]: createdReportActionComment as ReportAction, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + lastVisibleActionCreated: createdReportActionComment.created, + }, + }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, @@ -7890,6 +7899,12 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea }, ]; + parentReportActionOptimistic.forEach((parentActionData) => { + if (parentActionData) { + optimisticData.push(parentActionData); + } + }); + const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -7960,6 +7975,7 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea function unholdRequest(transactionID: string, reportID: string, searchHash?: number) { const createdReportAction = ReportUtils.buildOptimisticUnHoldReportAction(); const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; + const parentReportActionOptimistic = ReportUtils.getOptimisticDataForParentReportAction(reportID, createdReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); const optimisticData: OnyxUpdate[] = [ { @@ -7969,6 +7985,13 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num [createdReportAction.reportActionID]: createdReportAction as ReportAction, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + lastVisibleActionCreated: createdReportAction.created, + }, + }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, @@ -7986,6 +8009,12 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num }, ]; + parentReportActionOptimistic.forEach((parentActionData) => { + if (parentActionData) { + optimisticData.push(parentActionData); + } + }); + const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, From bcec9996baffe1f95b246198f9621cadbf3bf0f5 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 27 Sep 2024 17:48:02 +0300 Subject: [PATCH 2/4] remove parent action optimistic data for unhold --- src/libs/actions/IOU.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 7b529911ca03..ac21d65bc302 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7975,7 +7975,6 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea function unholdRequest(transactionID: string, reportID: string, searchHash?: number) { const createdReportAction = ReportUtils.buildOptimisticUnHoldReportAction(); const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; - const parentReportActionOptimistic = ReportUtils.getOptimisticDataForParentReportAction(reportID, createdReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); const optimisticData: OnyxUpdate[] = [ { @@ -8009,12 +8008,6 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num }, ]; - parentReportActionOptimistic.forEach((parentActionData) => { - if (parentActionData) { - optimisticData.push(parentActionData); - } - }); - const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, From 5e613e616fa7711681d7436f1bd187f44593dc79 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 27 Sep 2024 23:16:24 +0300 Subject: [PATCH 3/4] changed to early return --- src/libs/actions/IOU.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ac21d65bc302..670c523dbb2b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7900,9 +7900,10 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea ]; parentReportActionOptimistic.forEach((parentActionData) => { - if (parentActionData) { - optimisticData.push(parentActionData); + if (!parentActionData) { + return; } + optimisticData.push(parentActionData); }); const successData: OnyxUpdate[] = [ From c31d837efa3a2895dd4b7fa9494c08665f78a6c6 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 2 Oct 2024 14:31:29 +0300 Subject: [PATCH 4/4] remove unrelated changes --- src/libs/actions/IOU.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 077369704d33..96f71d2aecae 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7854,13 +7854,6 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea [createdReportActionComment.reportActionID]: createdReportActionComment as ReportAction, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - lastVisibleActionCreated: createdReportActionComment.created, - }, - }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, @@ -7964,13 +7957,6 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num [createdReportAction.reportActionID]: createdReportAction as ReportAction, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - lastVisibleActionCreated: createdReportAction.created, - }, - }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,