-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/32230: Update recently used tag and category when editing request #32467
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, transactionChanges.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, transactionChanges.tag); | ||
if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { | ||
optimisticData.push({ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`, | ||
value: optimisticPolicyRecentlyUsedTags, | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a way to DRY those LOC @DylanDylann? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hoangzinh We can create new function called
But I don't think It helps to dry code lots. What do you think ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, let's leave it as it is. It's not a big problem for me. Let me complete the checklist and wait opinion from Internal engineer. |
||
} | ||
|
||
const successData = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use the method "SET" here? For POLICY_RECENTLY_USED_CATEGORIES above, it's using method SET, but here it's using method MERGE. I found it's inconsistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hoangzinh I agree with you at this point. But currently we use MERGE method for tag in other places
App/src/libs/actions/IOU.js
Line 187 in 18d4b9b
App/src/libs/actions/IOU.js
Line 1875 in 18d4b9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like MERGE or SET is same if it's an array https://github.com/Expensify/react-native-onyx#should-i-use-merge-or-set-or-both, nvm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hoangzinh Do you mean that we should update to use SET in all places ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, it's stated here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hoangzinh Updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had this exact question!
The only thing though is that I think these all either need to be
SET
or all need toMERGE
perAnd even more fun once you look at
buildOptimisticPolicyRecentlyUsedCategories
returns anarray
andbuildOptimisticPolicyRecentlyUsedTags
returns anobject
So I think for calls to set the recently used categories we should use
SET
everywhere as notedAnd for recently used tags we should use
MERGE
everywhere since those are objects.