From 504eed2b74182dfd805b903d27152671db499381 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 5 Dec 2023 12:40:18 +0700 Subject: [PATCH 1/4] update recently used tag and categoy when editing request --- src/libs/actions/IOU.js | 54 +++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ed43569c360a..8a387c23e661 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -752,6 +752,30 @@ function editDistanceMoneyRequest(transactionID, transactionThreadReportID, tran }, }); + // Update recently used categories if the category is changed + if (_.has(transactionChanges, 'category')) { + const optimisticPolicyRecentlyUsedCategories = Policy.buildOptimisticPolicyRecentlyUsedCategories(iouReport.policyID, transactionChanges.category); + if (!_.isEmpty(optimisticPolicyRecentlyUsedCategories)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`, + value: optimisticPolicyRecentlyUsedCategories, + }); + } + } + + // Update recently used categories if the tag is changed + if (_.has(transactionChanges, 'tag')) { + const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, tag); + if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, + value: optimisticPolicyRecentlyUsedTags, + }); + } + } + // Clear out the error fields and loading states on success successData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -1809,8 +1833,6 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans updatedChatReport.lastMessageHtml = messageText; } - const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, transactionChanges.tag); - const isScanning = TransactionUtils.hasReceipt(updatedTransaction) && TransactionUtils.isReceiptBeingScanned(updatedTransaction); // STEP 4: Compose the optimistic data @@ -1870,12 +1892,28 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans : []), ]; - if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, - value: optimisticPolicyRecentlyUsedTags, - }); + // Update recently used categories if the category is changed + if (_.has(transactionChanges, 'category')) { + const optimisticPolicyRecentlyUsedCategories = Policy.buildOptimisticPolicyRecentlyUsedCategories(iouReport.policyID, transactionChanges.category); + if (!_.isEmpty(optimisticPolicyRecentlyUsedCategories)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`, + value: optimisticPolicyRecentlyUsedCategories, + }); + } + } + + // Update recently used categories if the tag is changed + if (_.has(transactionChanges, 'tag')) { + const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, tag); + if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, + value: optimisticPolicyRecentlyUsedTags, + }); + } } const successData = [ From 5910285a87b82e1779cfae69aa58262e56adbc1e Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 5 Dec 2023 13:08:52 +0700 Subject: [PATCH 2/4] fix lint --- src/libs/actions/IOU.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 8a387c23e661..95ab37e5d9e4 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -766,7 +766,7 @@ function editDistanceMoneyRequest(transactionID, transactionThreadReportID, tran // Update recently used categories if the tag is changed if (_.has(transactionChanges, 'tag')) { - const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, tag); + const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, transactionChanges.tag); if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -1906,7 +1906,7 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans // Update recently used categories if the tag is changed if (_.has(transactionChanges, 'tag')) { - const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, tag); + const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, transactionChanges.tag); if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, From 60c702718354480514c5bbcd4693a6b5b6b819d0 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 9 Dec 2023 16:24:37 +0700 Subject: [PATCH 3/4] using SET method --- src/libs/actions/IOU.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 95ab37e5d9e4..e7ab19afac3b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -184,7 +184,7 @@ function buildOnyxDataForMoneyRequest( if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, value: optimisticPolicyRecentlyUsedTags, }); @@ -769,7 +769,7 @@ function editDistanceMoneyRequest(transactionID, transactionThreadReportID, tran const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, transactionChanges.tag); if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, value: optimisticPolicyRecentlyUsedTags, }); @@ -1909,7 +1909,7 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, transactionChanges.tag); if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, value: optimisticPolicyRecentlyUsedTags, }); From 53dc13a362242e46d4486e93b55e08c7da21440a Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 13 Dec 2023 13:33:53 +0700 Subject: [PATCH 4/4] update using MERGE method for tag --- src/libs/actions/IOU.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index e7ab19afac3b..95ab37e5d9e4 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -184,7 +184,7 @@ function buildOnyxDataForMoneyRequest( if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { optimisticData.push({ - onyxMethod: Onyx.METHOD.SET, + onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, value: optimisticPolicyRecentlyUsedTags, }); @@ -769,7 +769,7 @@ function editDistanceMoneyRequest(transactionID, transactionThreadReportID, tran const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, transactionChanges.tag); if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { optimisticData.push({ - onyxMethod: Onyx.METHOD.SET, + onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, value: optimisticPolicyRecentlyUsedTags, }); @@ -1909,7 +1909,7 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(iouReport.policyID, transactionChanges.tag); if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { optimisticData.push({ - onyxMethod: Onyx.METHOD.SET, + onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, value: optimisticPolicyRecentlyUsedTags, });