[$250] Search - Expense from the list does not disappear after deletion
If you havenβt already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 9.0.72-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Yes, reproducible on both If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/5309274 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team
Action Performed:
- Open HybridApp
- Log in to the HT account
- Send 2 manual expenses to any user
- Go to Search -> Expenses -> All
- Delete one of the created expenses from step 3
- Tap again on the deleted expense
Expected Result:
After deleting an expense, it should immediately disappear from the list without refreshing the page
Actual Result:
Expense from the list does not disappear after deletion
Workaround:
Unknown
Platforms:
- [x] Android: Standalone
- [x] Android: HybridApp
- [x] Android: mWeb Chrome
- [x] iOS: Standalone
- [x] iOS: HybridApp
- [x] iOS: mWeb Safari
- [x] MacOS: Chrome / Safari
- [x] MacOS: Desktop
Screenshots/Videos
https://github.com/user-attachments/assets/917c7a77-9d7d-4aaf-8cfa-25d030038739
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~021865183017070238528
- Upwork Job ID: 1865183017070238528
- Last Price Increase: 2024-12-06
Issue Owner
Current Issue Owner: @rayane-djouah
Triggered auto assignment to @mallenexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Expense from the list does not disappear after deletion
What is the root cause of that problem?
In useSearchHighlightAndScroll, we only update Search data if new transaction is added, not when a transaction is deleted:
https://github.com/Expensify/App/blob/b9107bf59cbb3982d958abbae357e3b903ed4c63/src/hooks/useSearchHighlightAndScroll.ts#L42
What changes do you think we should make in order to solve the problem?
Change condition to update Search data if number of transaction is different:
https://github.com/Expensify/App/blob/b9107bf59cbb3982d958abbae357e3b903ed4c63/src/hooks/useSearchHighlightAndScroll.ts#L42
if (transactionsLength && typeof previousTransactionsLength === 'number' && transactionsLength !== previousTransactionsLength) {
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
What alternative solutions did you explore? (Optional)
Edited by proposal-police: This proposal was edited at 2024-12-06 15:01:26 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Search - Expense from the list does not disappear after deletion
What is the root cause of that problem?
We only send search request if there is an increase in transaction length, i.e. the currentTransaction length is greater than the previous transaction length https://github.com/Expensify/App/blob/b9107bf59cbb3982d958abbae357e3b903ed4c63/src/hooks/useSearchHighlightAndScroll.ts#L42 but here we are deleting the expense that will decrease the transactions length we have
What changes do you think we should make in order to solve the problem?
The conditions that depend on transaction length are incorrect in both https://github.com/Expensify/App/blob/b9107bf59cbb3982d958abbae357e3b903ed4c63/src/hooks/useSearchHighlightAndScroll.ts#L42 https://github.com/Expensify/App/blob/b9107bf59cbb3982d958abbae357e3b903ed4c63/src/hooks/useSearchHighlightAndScroll.ts#L37 because transaction length equality can even mean there is a change that needs a search request to be sent. For instance, if a user creates a new expense but deletes another expense which could result in the transaction lengths to be equal but still there is a change that requires a fetch. We should instead depend on a condition where the previous and current transaction IDs list are not equal (of course with deep comparison between the values they hold) https://github.com/Expensify/App/blob/b9107bf59cbb3982d958abbae357e3b903ed4c63/src/hooks/useSearchHighlightAndScroll.ts#L76-L80
const previousTransactionIDs = previousTransactions && Object.keys(previousTransactions);
const transactionIDs = transactions && Object.keys(transactions);
and replace this with it https://github.com/Expensify/App/blob/b9107bf59cbb3982d958abbae357e3b903ed4c63/src/hooks/useSearchHighlightAndScroll.ts#L42
if(!isEqual(transactionIDs, previousTransactionIDs))
we can optionally add more condition of the existence of previous transaction ids and current transactionIDs to exclude the case where the values are undefined on first render π and remove the condition here https://github.com/Expensify/App/blob/b9107bf59cbb3982d958abbae357e3b903ed4c63/src/hooks/useSearchHighlightAndScroll.ts#L37
if (searchTriggeredRef.current) {
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
We can render the Search page (or optionally test only useSearchHighlightAndScroll) and change the transaction list from onyx by replacing a transaction with another one and mock our SearchActions.search and assert that it has been called π
What alternative solutions did you explore? (Optional)
Job added to Upwork: https://www.upwork.com/jobs/~021865183017070238528
Triggered auto assignment to Contributor-plus team member for initial proposal review - @rayane-djouah (External)
@rayane-djouah can you attempt reproduction and, if you're able to, review the above proposals? I tried to test and staging.new.expensify.com froze for me :/
Reproducible
https://github.com/user-attachments/assets/55d39fad-ec3d-45bc-88c5-8aa6eaf8abef
For instance, if a user creates a new expense but deletes another expense which could result in the transaction lengths to be equal but still there is a change that requires a fetch.
@FitseTLT Is the user currently able to create a new expense and delete another one at the same time?
@luacmartins would you like to be assigned to this one as CME since it's related to the search project?
For instance, if a user creates a new expense but deletes another expense which could result in the transaction lengths to be equal but still there is a change that requires a fetch.
@FitseTLT Is the user currently able to create a new expense and delete another one at the same time?
@rayane-djouah We are not only tracking the creation/deletion of transactions created by the current user, for instance, another user member of the current user's workspace can create an expense and delete another one and when the update of transaction reaches the current user's onyx the transaction length will be equal that's what I am indicating.
π£ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? πΈ
Will review today
@luacmartins, @mallenexpensify, @rayane-djouah Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
@luacmartins - Some thoughts:
- https://github.com/Expensify/App/pull/49192 added the logic to trigger the search command and highlight the newly added expense when adding a new expense from the search page, as requested in, as requested in https://github.com/Expensify/App/issues/48716
- Triggering the search command when deleting expenses from the search page wasn't considered in the initial design.
- @daledah's proposal correctly identifies the cause and addresses the deletion issue (by checking if the number of transactions has decreased), but it doesn't handle cases where a transaction is replaced in Onyx (since the transaction count remains the same).
- @FitseTLT proposal covers the case where a transaction is replaced in Onyx by performing a deep comparison of the previous and current transaction IDs.
- @FitseTLT also suggested adding unit tests.
- Since
useSearchHighlightAndScrollinitially focused only on highlighting and scrolling for newly added transactions, we may need to rename it or add comments to clarify that it now also handles transaction deletions.
I think we can go with @FitseTLT proposal
:ribbon::eyes::ribbon: C+ reviewed
Current assignee @luacmartins is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.
I agree. Thanks for the detailed summary!
π£ @rayane-djouah π An offer has been automatically sent to your Upwork account for the Reviewer role π Thanks for contributing to the Expensify app!
π£ @FitseTLT π An offer has been automatically sent to your Upwork account for the Contributor role π Thanks for contributing to the Expensify app!
Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review π§βπ» Keep in mind: Code of Conduct | Contributing π
@luacmartins @mallenexpensify @FitseTLT @rayane-djouah this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
Ok, I have PRs to update the responses from DeleteMoneyRequest and DeleteMoneyRequestOnSearch. Below is the sample response:
When deleting the last transaction on a report (no snapshot key is sent, since live updates should automatically update the snapshot)
When deleting a single transaction on a report with multiple expenses (snapshot key is returned to update isOneTransactionReport, etc)
@rayane-djouah @FitseTLT Does that update look correct to you?
@luacmartins I am a bit confused here. Currently useSearchHighlightAndScroll hook checks for a change in transactions_ key and send search request accordingly. Now the problem we are facing is transactions_ key is not being correctly updated on deleting the last transaction in a report I was hoping to get that transactions_ key update fixed on this case so that the normal operation of the hook will work for this case too.
I am not sure how the BE code works but I don't think fixing the response of DeleteRequest API only suffice but also the data it pushes too for other users that didn't delete the money request. Like User A deleted a request in workspace that is owned by UserB and now the update doesn't reach for both users.
@FitseTLT yes, the data is being pushed to other users, but for some reason we're not returning it in the http response to the caller. So my PRs are adding all the onyxData updates to the http response. Does that make sense?
@FitseTLT yes, the data is being pushed to other users, but for some reason we're not returning it in the http response to the caller. So my PRs are adding all the onyxData updates to the http response. Does that make sense?
Yep. But if you want to test you can do with branch of the PR because the BE change should solve it without any more FE change :+1:
@FitseTLT doesn't seem to work. Check out the video below:
https://github.com/user-attachments/assets/19d19cd5-4656-44a9-ad99-5896b7b094d2
@luacmartins Did you apply any BE changes? Because now it is working I remember invoice deletion was not updated too but it is working now.
https://github.com/user-attachments/assets/ccaf49c5-4adc-4927-8877-f7cc5d283c82
https://github.com/user-attachments/assets/c45fde0e-6ad6-48fa-9bac-b91c301a260d
No BE changes that I'm aware of.
No BE changes that I'm aware of.
Ok but now the BE is correctly updating transactions_ list so it seems fixed. I will work on the rest of the tasks left but let u know if any BE change is needed. Maybe some other BE PR might have fixed it Thx π
This issue has not been updated in over 15 days. @luacmartins, @mallenexpensify, @FitseTLT, @rayane-djouah eroding to Monthly issue.
P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!
PR under review
PR is merged