Skip to content
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

[HOLD for payment 2023-09-07] [$1000] Web - Requested money - "Delete" button does not work when attempting to delete requested money after adding a PDF attachment to an IOU. #25589

Closed
1 of 6 tasks
izarutskaya opened this issue Aug 21, 2023 · 51 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@izarutskaya
Copy link

izarutskaya commented Aug 21, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Click on the plus sign and select "Request Money". Enter the desired amount, email, and click "Request Money".
  2. Click on the requested money to enter the reply threads. Add a PDF attachment and attempt to delete the requested money.
  3. Observe that the "Delete" button is not functioning after adding the PDF attachment to the IOU.

Expected Result:

After adding a PDF attachment to an IOU, the requested money should be deletable as usual.

Actual Result:

Adding a PDF attachment to an IOU causes the "Delete" button to malfunction when attempting to delete requested money.

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: v1.3.55-7

Reproducible in staging?: Y

Reproducible in production?: Y

If this was caught during regression testing, add the test name, ID and link from TestRail:

Email or phone of affected tester (no customers):

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

screen-capture.-.2023-08-11T043711.755.mp4
20230821_201856.mp4

Expensify/Expensify Issue URL:

Issue reported by: @tewodrosGirmaA

Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1691753680174959

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~011b0f4ca743a481a4
  • Upwork Job ID: 1695129961561923584
  • Last Price Increase: 2023-08-25
  • Automatic offers:
    • namhihi237 | Contributor | 26369431
    • tewodrosGirmaA | Reporter | 26369433
    • dukenv0307 | Contributor | 26388960
@DylanDylann
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

"Delete" button does not work when attempting to delete requested money after adding a PDF attachment to an IOU.

What is the root cause of that problem?

  • Currently, according to this line
    const iouReportLastMessageText = ReportActionsUtils.getLastVisibleMessage(iouReport.reportID, updatedReportAction).lastMessageText;

    when the user sends a pdf file after requesting money, the ReportActionsUtils.getLastVisibleMessage(iouReport.reportID, updatedReportAction) will return {"lastMessageTranslationKey": "common.attachment"}. So the iouReportLastMessageText is undefined.

In

iouReportLastMessageText.length === 0 && !ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && (!transactionThreadID || shouldDeleteTransactionThread);
, accessing iouReportLastMessageText.length leads to error: "cannot read properties of undefined ...", so the remaining part are not run
Finally, we cannot delete request money

What changes do you think we should make in order to solve the problem?

  • We can update the
    const iouReportLastMessageText = ReportActionsUtils.getLastVisibleMessage(iouReport.reportID, updatedReportAction).lastMessageText;

    to
 const iouReportLastMessage = ReportActionsUtils.getLastVisibleMessage(iouReport.reportID, updatedReportAction);
    const iouReportLastMessageText = iouReportLastMessage.lastMessageText || iouReportLastMessage.lastMessageTranslationKey;

What alternative solutions did you explore? (Optional)

N/A

Result

Screencast.from.19-08-2023.14.08.39.webm

@izarutskaya izarutskaya added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 21, 2023
@namhihi237
Copy link
Contributor

namhihi237 commented Aug 21, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

What is the root cause of that problem?

We check should delete the IOU report here

App/src/libs/actions/IOU.js

Lines 1077 to 1079 in 4a7558c

const iouReportLastMessageText = ReportActionsUtils.getLastVisibleMessage(iouReport.reportID, updatedReportAction).lastMessageText;
const shouldDeleteIOUReport =
iouReportLastMessageText.length === 0 && !ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && (!transactionThreadID || shouldDeleteTransactionThread);

In the function getLastVisibleMessage we have a case if the last message is an attachment will return lastMessageTranslationKey
if (isReportMessageAttachment(message)) {
return {
lastMessageTranslationKey: CONST.TRANSLATION_KEYS.ATTACHMENT,
};
}

So we missed checking the last message is an attachment

In addition, the error also appears here, In case we delete the request money but in the thread of this request money the last message is attachment, and the same error occurs.

App/src/libs/actions/IOU.js

Lines 1052 to 1053 in 4a7558c

const shouldDeleteTransactionThread = transactionThreadID ? ReportActionsUtils.getLastVisibleMessage(transactionThreadID).lastMessageText.length === 0 : false;
const shouldShowDeletedRequestMessage = transactionThreadID && !shouldDeleteTransactionThread;

And here we haven't updated lastMessageText properly in optimisticData either:

lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport.chatReportID, {[reportPreviewAction.reportActionID]: null}).lastMessageText,

What changes do you think we should make in order to solve the problem?

We should add the conditions if the last message is an attachment:

  1. We should update in here
  const lastMessageThead = ReportActionsUtils.getLastVisibleMessage(transactionThreadID);
  const iouThreadLastMessageText = lastMessageThead.lastMessageText || lastMessageThead.lastMessageTranslationKey;

  const shouldDeleteTransactionThread = transactionThreadID ? iouThreadLastMessageText.length === 0 : false;
  1. And here
    const { lastMessageText = '', lastMessageTranslationKey = '' } = ReportActionsUtils.getLastVisibleMessage(iouReport.reportID, updatedReportAction);
    const iouReportLastMessageText = lastMessageText || lastMessageTranslationKey;
  1. Update optimisticData

What alternative solutions did you explore? (Optional)

N/A

@c3024
Copy link
Contributor

c3024 commented Aug 21, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Cannot delete IOUs which have attachment as last message in their thread

What is the root cause of that problem?

Here we are finding shouldDeleteTransactionThread by checking if length of lastVisibleMessage is zero

const shouldDeleteTransactionThread = transactionThreadID ? ReportActionsUtils.getLastVisibleMessage(transactionThreadID).lastMessageText.length === 0 : false;

But if the last message is an attachment getLastVisibleMessage of ReportActionsUtils this here
if (isReportMessageAttachment(message)) {
return {
lastMessageTranslationKey: CONST.TRANSLATION_KEYS.ATTACHMENT,
};
}

returns only an object containing lastMessageTranslationKey only, so the lastMessageText being non-existent in this object, it is undefined and finding its length throws console error.

What changes do you think we should make in order to solve the problem?

We can replace the above line shouldDeleteTransactionThread with

const lastVisibleMessage = ReportActionsUtils.getLastVisibleMessage(transactionThreadID);
const shouldDeleteTransactionThread = transactionThreadID ? !lastVisibleMessage.lastMessageTranslationKey && !lastVisibleMessage.lastMessageText : false;

or simply

const shouldDeleteTransactionThread = transactionThreadID && !lastVisibleMessage.lastMessageTranslationKey && !lastVisibleMessage.lastMessageText;

What alternative solutions did you explore? (Optional)

Result
deleteMoneyRequestWithAnAttachmentAsLastMessage.mov

@esh-g
Copy link
Contributor

esh-g commented Aug 21, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Money request cannot be deleted when an attachment is sent after it in the transaction report. This occurs not only for PDFs, but for all attachments as well.

What is the root cause of that problem?

While deleting the IOU, we are checking if there are any other messages in the IOU report and if there are none, we delete the IOU report as well. This can be seen here:

App/src/libs/actions/IOU.js

Lines 836 to 839 in d53bbf0

const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(iouReport.reportID, updatedReportAction);
const iouReportLastMessageText = ReportActionsUtils.getLastVisibleMessage(iouReport.reportID, updatedReportAction).lastMessageText;
const shouldDeleteIOUReport =
iouReportLastMessageText.length === 0 && !ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && (!transactionThreadID || shouldDeleteTransactionThread);

But while getting the value of iouReportLastMessageText, we get undefined and then we try to access it's length which causes this error.

We are getting iouReportLastMessageText as undefined because the property .lastMessageText is undefined for output of the function ReportActionsUtils.getLastVisibleMessage() which we are accessing on line 837.

Now, this property is undefined because there are actually two properties that the function getLastVisibleMessage() can return. It can either return lastMessageText (in case of normal text report action) or lastMessageTranslationKey (in case of an attachment report action).

So, in this case, since a pdf is an attachment, there is no lastMessageText property on the resultant object of the function but there is there is the property lastMessageTranslationKey which is set to common.attachment.

What changes do you think we should make in order to solve the problem?

Instead of just checking that lastMessageText.length === 0 we should also check that lastMessageTranslationKey.length === 0 while setting their default values as empty strings so that there is no error when we access the .length property. An example of this can be seen in Report.js:

const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportActionsUtils.getLastVisibleMessage(reportID);

  1. Therefore we should replace line 837 with:
const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportActionsUtils.getLastVisibleMessage(iouReport.reportID, updatedReportAction);
  1. Then also modify the condition for shouldDeleteIOUReport to the following:
const shouldDeleteIOUReport =
        (lastMessageTranslationKey.length === 0 && lastMessageText.length === 0) && !ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && (!transactionThreadID || shouldDeleteTransactionThread);
  1. Since iouReportLastMessageText has been renamed to just lastMessageText, we also need to change the following line:
    updatedIOUReport.lastMessageText = iouReportLastMessageText;

    to have the renamed last message like this:
updatedIOUReport.lastMessageText = lastMessageText;

Additional Suggestion

This solution may also be applied to the logic checking shouldDeleteTransactionThread here:

const shouldDeleteTransactionThread = transactionThreadID ? ReportActionsUtils.getLastVisibleMessage(transactionThreadID).lastMessageText.length === 0 : false;

Since here too, we are just accessing the lastMessageText and not lastMessageTranslationKey.

What alternative solutions did you explore? (Optional)

We can also refactor the function ReportActionsUtils.getLastVisibleMessage() to just return two fixed properties like lastMessageText: "Some Text" and isAttachment: false to avoid the confusion of managing two possibly undefined properties.

@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

Triggered auto assignment to @dylanexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@tewodrosGirmaA
Copy link

Hello@izarutskaya, could you kindly update my GitHub username? My username is not @Tewodros Girma, it is @tewodrosGirmaA

@dylanexpensify
Copy link
Contributor

dylanexpensify commented Aug 22, 2023

reviewing tomorrow! Got caught up with higher priorities today!

@dylanexpensify
Copy link
Contributor

actioning today!

@dylanexpensify dylanexpensify added the External Added to denote the issue can be worked on by a contributor label Aug 25, 2023
@melvin-bot melvin-bot bot changed the title Web - Requested money - "Delete" button does not work when attempting to delete requested money after adding a PDF attachment to an IOU. [$1000] Web - Requested money - "Delete" button does not work when attempting to delete requested money after adding a PDF attachment to an IOU. Aug 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 25, 2023

Job added to Upwork: https://www.upwork.com/jobs/~011b0f4ca743a481a4

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 25, 2023

Current assignee @dylanexpensify is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Aug 25, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @burczu (External)

@melvin-bot melvin-bot bot added the Overdue label Aug 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 28, 2023

@burczu, @dylanexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@burczu
Copy link
Contributor

burczu commented Aug 28, 2023

not overdue - reviewing it now

@melvin-bot melvin-bot bot removed the Overdue label Aug 28, 2023
@burczu
Copy link
Contributor

burczu commented Aug 28, 2023

I think we should go with the proposal from @namhihi237, because it fixes the issue, and additionally fixes the same problem in the thread.

However, the proposal from @DylanDylann also fixes the issue (but without fixing the same in threads) and was posted before @namhihi237's one (the @namhihi237 proposal actually contains @DylanDylann's proposal). So I think we could consider splitting the prize for this issue.

The proposal from @c3024 is pretty much the same as the one from @DylanDylann, and the proposal from @esh-g is actually the same as the one from @namhihi237.

🎀 👀 🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Aug 28, 2023

Triggered auto assignment to @flodnv, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@c3024
Copy link
Contributor

c3024 commented Aug 28, 2023

@DylanDylann and @namhihi237 initially only dealt with messaging in the IOU report only. My solution dealt with messaging inside the thread of transaction only. @namhihi237 edited their proposal later to include the case of transaction thread.
So solution addressing the transaction thread is given first by me.
So, if bounty were to split, I may be considered as I was the first to propose to fix the bug in transaction thread. @burczu

@burczu
Copy link
Contributor

burczu commented Aug 28, 2023

Hmmm... it's hard to say who was first - it seems like the proposal from @c3024 and the update from @namhihi237 was at same time:

Screenshot 2023-08-28 at 13 34 47

Screenshot 2023-08-28 at 13 34 57

@c3024
Copy link
Contributor

c3024 commented Aug 28, 2023

Their initial proposal did not contain the shouldDeleteTransactionThread. It was added in the edit. The time shown is of the initial comment.

@burczu
Copy link
Contributor

burczu commented Aug 28, 2023

@flodnv What do you think about it?

@flodnv
Copy link
Contributor

flodnv commented Aug 29, 2023

Thank you for your proposal @dukenv0307. Indeed, after discussing it, @burczu and I agree that it is the most thoughtful approach, and might very well avoid similar bugs in the future. We will be assigning you to submit a PR.

@namhihi237 @DylanDylann @c3024 Even though when proposals aren't accepted, compensation is not issued and remains at the sole discretion of Expensify, we do appreciate your efforts here that ultimately led to the best solution. As such, we will be issuing a $100 payment to each of you to thank you for your time. Please note that this is a one-off recognition and does not set a precedent for such situations in future (or past) issues.

@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

📣 @dukenv0307 🎉 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 📖

@c3024
Copy link
Contributor

c3024 commented Aug 29, 2023

@dukenv0307 proposal appears to be a work around. Notwithstanding the backend reply or what is returned here in the getLastVisibleMessage function, attachment checking should be done with lastMessageTranslationKey only.

Anywhere we use getLastVisibleAction we need to check first for lastMessageTranslatioKey before lastMessageText

Also the backend returns a simple [Attachment] for th lastMessageText and the proposal is using the key and translating it to local language. So for Spanish, backend returning lastMessageText in English differs from the lastMessageText used here.
This would also cause inconsistencies.

I think implementing this solution can cause more inconsistencies.

Just adding a lastMessageText field to the returning object from the check of attachment in getLastVisibleMessage function instead of fixing the correct use of lastMessageTranslation key in IOU appears to be a bad idea.

@dukenv0307
Copy link
Contributor

@c3024 Thanks for your comment. I just checked all the places where we use the getLastVisibleMessage function and I see that it is safe to return lastMessageText. Besides, we have another method to get the correct last message text so don't worry about localization

@c3024
Copy link
Contributor

c3024 commented Aug 29, 2023

With this change I think there would be little (or no) purpose left for lastMessageTranslationKey then I guess.

@dukenv0307
Copy link
Contributor

@c3024 Oh no, lastMessageTranslationKey is used for many purposes. You can search lastMessageTranslationKey in the code base and see how we just used it before

@dylanexpensify
Copy link
Contributor

@DylanDylann @c3024 @namhihi237 please apply here for payout!

@c3024
Copy link
Contributor

c3024 commented Aug 29, 2023

Applied. Thanks for the gesture @flodnv @dylanexpensify

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Aug 30, 2023
@dukenv0307
Copy link
Contributor

@burczu The PR is now ready for review: #26194

@melvin-bot
Copy link

melvin-bot bot commented Aug 30, 2023

🎯 ⚡️ Woah @burczu / @dukenv0307, great job pushing this forwards! ⚡️

The pull request got merged within 3 working days of assignment, so this job is eligible for a 50% #urgency bonus 🎉

  • when @dukenv0307 got assigned: 2023-08-29 12:01:12 Z
  • when the PR got merged: 2023-08-30 15:10:37 UTC

On to the next one 🚀

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Aug 31, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Web - Requested money - "Delete" button does not work when attempting to delete requested money after adding a PDF attachment to an IOU. [HOLD for payment 2023-09-07] [$1000] Web - Requested money - "Delete" button does not work when attempting to delete requested money after adding a PDF attachment to an IOU. Aug 31, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Aug 31, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 31, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot
Copy link

melvin-bot bot commented Aug 31, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.60-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-09-07. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Aug 31, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@burczu] The PR that introduced the bug has been identified. Link to the PR:
  • [@burczu] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@burczu] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@burczu] Determine if we should create a regression test for this bug.
  • [@burczu] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@dylanexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@burczu
Copy link
Contributor

burczu commented Sep 5, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@burczu] The PR that introduced the bug has been identified. Link to the PR: not found
  • [@burczu] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: not found
  • [@burczu] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: not found
  • [@burczu] Determine if we should create a regression test for this bug.
  • [@burczu] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@dylanexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added the Overdue label Sep 13, 2023
@dylanexpensify
Copy link
Contributor

paying out now!

@melvin-bot melvin-bot bot removed the Overdue label Sep 13, 2023
@dylanexpensify
Copy link
Contributor

@dukenv0307 @tewodrosGirmaA payments sent!
@DylanDylann @c3024 @namhihi237 offers sent!

@dylanexpensify
Copy link
Contributor

done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

10 participants