-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[$250] Expense - First expense in the report is briefly highlighted after deleting expense #61552
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
Comments
Triggered auto assignment to @lschurr ( |
ProposalPlease re-state the problem that we are trying to solve in this issue.When deleting an expense, the first expense is highlighted as if it's new. What is the root cause of that problem?We calculate the new transaction based on this logic. App/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx Lines 128 to 140 in f62ec5e
First, we filter out the transaction list from the prev transaction list so we only left with the new transaction that doesn't exist on the prev transaction list. Then, we use reduce to get the transaction with the latest inserted value. The problem here is, we set the reduce initial value to the first transaction. When the filtered transaction list is empty (which happens when we delete an expense), then it will return the first transaction as the new transaction. What changes do you think we should make in order to solve the problem?We have 3 options. First, we can ignore calculating the new transaction ID when the length of the transaction list is smaller than the prev transaction list. App/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx Lines 128 to 131 in f62ec5e
OR Return early if the filtered transaction list is empty.
OR We can use for loop to find the maximum value, so when it's empty, the loop simply won't run and we will return an empty value. What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?N/A |
Job added to Upwork: https://www.upwork.com/jobs/~021920157419604664740 |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @rushatgabhane ( |
🚨 Edited by proposal-police: This proposal was edited at 2025-05-08 05:59:51 UTC. ProposalPlease re-state the problem that we are trying to solve in this issue.The first expense in the report is briefly highlighted after deleting expense. What is the root cause of that problem?The bug occurs when a transaction is deleted (so the current list is shorter than the previous list). So the filtered list becomes empty. After that, we use the reduce operation with the initial value is the first transaction, so the reduce operation still returns the first transaction from the original list (transactions.at(0)). This incorrectly marks the first transaction as "new" even though it's not new at all App/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx Lines 128 to 140 in f62ec5e
What changes do you think we should make in order to solve the problem?Before coming up with a solution, I noticed that the previous logic doesn't perform well when using both (filter, reduce) I suggest updating to a new logic with one loop combined with using Set structure to optimize the performance and also solve the bug in this issue
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?We can wrap it into a function and add UTs for it to prevent this bug from happening again from new changes in the future What alternative solutions did you explore? (Optional)Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job. |
Proposal [Updated after policy clarification]🧩 ProblemWhen an expense is deleted, the 💥 Root Causeconst newTransactionID = useMemo(() => {
if (!prevTransactions || transactions.length === prevTransactions.length) {
return CONST.EMPTY_ARRAY as unknown as string[];
}
return transactions
.filter(transaction => !prevTransactions.some(prev => prev.transactionID === transaction.transactionID))
.reduce((latest, t) => {
const inserted = t?.inserted ?? 0;
const latestInserted = latest?.inserted ?? 0;
return inserted > latestInserted ? t : latest;
}, transactions.at(0))?.transactionID;
}, [prevTransactions, transactions]); This logic fails when the ✅ ProposalI suggest two logically sound and efficient variants that fix this issue. Either could be used depending on whether clarity or performance is the preferred priority. 🔹 Variant A: Clear
|
there is no such policy. please post your proposal as long as yours is different/better from the existing ones |
@bernhardoj's proposal LGTM 🎀 👀 🎀 it fixes the issue using the correct RCA. Other proposals suggest loop optimization but we shouldn't do that unless it is a quantifiable problem |
Triggered auto assignment to @rlinoz, see https://stackoverflow.com/c/expensify/questions/7972 for more details. |
PR is ready cc: @rushatgabhane |
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.1.41-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: Exp
Email or phone of affected tester (no customers): #61243
Issue reported by: Applause Internal Team
Device used: Mac 15.3 / Chrome
App Component: Money Requests
Action Performed:
Precondition:
Expected Result:
The first expense in the report will not be highlighted after deleting expense.
Actual Result:
The first expense in the report is briefly highlighted after deleting expense.
Workaround:
Unknown
Platforms:
Screenshots/Videos
1.mp4
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @rlinozThe text was updated successfully, but these errors were encountered: