App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Search - Receipt thumbnail becomes gray & blank after changing receipt from JPG to PDF file

Open IuliiaHerets opened this issue 1 year ago • 38 comments

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: v9.0.20-0 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to FAB > Submit expense > Manual.
  3. Submit a manual expense with JPG receipt.
  4. Go to Search.
  5. Click on the expense in Step 3.
  6. Click on the receipt.
  7. Replace the receipt with a PDF file.
  8. Close the RHP.

Expected Result:

The receipt thumbnail in search expense list will update to show the pdf receipt.

Actual Result:

The receipt thumbnail in search expense list shows blank gray thumbnail after changing to a pdf receipt.

Workaround:

Unknown

Platforms:

  • [x] Android: Native
  • [x] Android: mWeb Chrome
  • [x] iOS: Native
  • [x] iOS: mWeb Safari
  • [x] MacOS: Chrome / Safari
  • [x] MacOS: Desktop

Screenshots/Videos

https://github.com/user-attachments/assets/818f63a1-e729-4239-9c20-7a6342182420

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0130e8b27688b14ba0
  • Upwork Job ID: 1823720055329371979
  • Last Price Increase: 2024-09-04
Issue OwnerCurrent Issue Owner: @Pujan92

IuliiaHerets avatar Aug 14 '24 07:08 IuliiaHerets

Triggered auto assignment to @joekaufmanexpensify (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.

melvin-bot[bot] avatar Aug 14 '24 07:08 melvin-bot[bot]

We think that this bug might be related to #wave-collect - Release 1

IuliiaHerets avatar Aug 14 '24 07:08 IuliiaHerets

@joekaufmanexpensify FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

IuliiaHerets avatar Aug 14 '24 07:08 IuliiaHerets

Job added to Upwork: https://www.upwork.com/jobs/~0130e8b27688b14ba0

melvin-bot[bot] avatar Aug 14 '24 13:08 melvin-bot[bot]

cc @luacmartins

joekaufmanexpensify avatar Aug 14 '24 13:08 joekaufmanexpensify

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

melvin-bot[bot] avatar Aug 14 '24 13:08 melvin-bot[bot]

Waiting for proposals

joekaufmanexpensify avatar Aug 15 '24 13:08 joekaufmanexpensify

Proposal

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

Search - Receipt thumbnail becomes gray & blank after changing receipt from JPG to PDF file

What is the root cause of that problem?

When we change the receipt to pdf file, the PDFThumbnail file doesn't handle the thumbnail image properly and seems not working, in other file like DistanceEReceipt file we use the image thumbnail for PDF provided by the BE, by invoking the ReceiptUtils.getThumbnailAndImageURIs function https://github.com/Expensify/App/blob/6a9a97690cd97f7f608ff9dd125ac1a7d7da3137/src/components/DistanceEReceipt.tsx#L30 https://github.com/Expensify/App/blob/6a9a97690cd97f7f608ff9dd125ac1a7d7da3137/src/components/DistanceEReceipt.tsx#L33 But in our case we not we use the PDF file link url https://github.com/Expensify/App/blob/6a9a97690cd97f7f608ff9dd125ac1a7d7da3137/src/components/SelectionList/Search/TransactionListItemRow.tsx#L93

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

We can use the same way used in other file i.e DistanceEReceipt But in our case the BE for Search API doesn't return filename inside the receipt object which will be used to check if the file pdf we will get from BE for the thumbnail inside ReceiptUtils.getThumbnailAndImageURIs function.

So inside the ReceiptUtils.getThumbnailAndImageURIs function we can retrieve the filename receiptFilename from the url

What alternative solutions did you explore? (Optional)

Inside the TransactionListItemRow file we can retrieve the new transaction value from the Onyx by using the current transaction id i.e transaction_id, because the current transaction value from BE (Search API) that being pass to this function doesn't return with filename value inside receipt object

NJ-2020 avatar Aug 15 '24 14:08 NJ-2020

PDFThumbnail file doesn't handle the thumbnail image properly and seems not working

Why is this the case?

luacmartins avatar Aug 15 '24 16:08 luacmartins

@luacmartins I don't know, when i see on other page like report page it showing white background seems not working

NJ-2020 avatar Aug 15 '24 22:08 NJ-2020

Proposal

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

Search - Receipt thumbnail becomes gray & blank after changing receipt from JPG to PDF file

What is the root cause of that problem?

The component that renders the thumbnail is Image from React Native, which doesn't support displaying PDF files.

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

We'll need to modify this source prop to send the correct uri using the getThumbnailAndImageURIs() function. https://github.com/Expensify/App/blob/75f1729fc255df1792e37f9ad3e1b44d40d77f5b/src/components/SelectionList/Search/TransactionListItemRow.tsx#L93

We can apply the following logic, to check whether the file is PDF or not and pass the correct uri.

const filename = getFileName(transactionItem?.receipt?.source ?? '');
const receiptURIs = getThumbnailAndImageURIs(transactionItem, null, filename);
const isReceiptPDF = Str.isPDF(filename);
const source = tryResolveUrlFromApiRoot(isReceiptPDF ? receiptURIs.thumbnail ?? '' : receiptURIs.image ?? '');

AlfredoAlc avatar Aug 17 '24 02:08 AlfredoAlc

@Pujan92 do you expect to be able to review the new proposal today?

joekaufmanexpensify avatar Aug 19 '24 14:08 joekaufmanexpensify

@Pujan92, @luacmartins, @joekaufmanexpensify Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] avatar Aug 19 '24 18:08 melvin-bot[bot]

Bump @Pujan92 when you have a sec

joekaufmanexpensify avatar Aug 20 '24 12:08 joekaufmanexpensify

Sorry for the delay @joekaufmanexpensify, I will review it tomorrow.

Pujan92 avatar Aug 20 '24 18:08 Pujan92

@NJ-2020 @AlfredoAlc

I see the pdf thumbnail image correctly when I revisit the page, I think TransactionListItem isn't rerendering when the pdf gets uploaded. Could you plz confirm and update your proposal accordingly if that is the case?

https://github.com/user-attachments/assets/974af70d-3471-42b3-94b4-9a60130241fb

Pujan92 avatar Aug 21 '24 07:08 Pujan92

As an fyi, going to be OOO from tomorrow - Monday. Not adding another BZ since should be nothing BZ-related till then. Please ask in slack if something comes up!

joekaufmanexpensify avatar Aug 21 '24 13:08 joekaufmanexpensify

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

melvin-bot[bot] avatar Aug 21 '24 16:08 melvin-bot[bot]

@Pujan92 Yes, when the receipt gets uploaded the file for that transaction gets updated with the new file which is a pdf. Pdf files are not rendered correctly from that Image component.

In that page we get the data via a snapshot, so when you revisit that page it gets a new snapshot which internally seems to apply a similar logic(as the proposal) to pdf files, and returns the transaction with a valid uri for the thumbnail.

AlfredoAlc avatar Aug 21 '24 17:08 AlfredoAlc

@Pujan92 The PDFThumbnail seems not working, it showing white background

https://github.com/user-attachments/assets/565f9e84-5991-4708-bc3e-5978878affaf

I think you can try to slow down your network to see the issue And also we got thumbnail preview image from the BE and the PDFThumbnail will be replaced by the image thumbnail from BE

NJ-2020 avatar Aug 22 '24 03:08 NJ-2020

In that page we get the data via a snapshot, so when you revisit that page it gets a new snapshot which internally seems to apply a similar logic(as the proposal) to pdf files, and returns the transaction with a valid uri for the thumbnail.

Thanks @AlfredoAlc, I got your point.

@luacmartins Doesn't this need to be updated correctly from backend in the pusher event for the snapshot? I mean when we revisit the search the snapshot provides the image file for the transaction, shouldn't it do the same if we upload any new file?

Pujan92 avatar Aug 25 '24 14:08 Pujan92

We have live Onyx updates for Search, which means that if we get an Onyx update for a transaction that exists within the snapshot_ key, it should be updated accordingly. @Pujan92 do we get any Onyx update for the new receipt URL?

luacmartins avatar Aug 26 '24 19:08 luacmartins

@luacmartins, I noticed below some cases.

  1. If we try to add a new receipt in Search expenses, we don't get a new receipt URL

  2. If we replace the existing receipt with the pdf, we receive an onyx update with the receipt details(Here we receive source as a pdf file contrary to the initial snapshot data where for pdf also it provides jpg as source). Attached video helps to understand.

https://github.com/user-attachments/assets/9219c923-1836-4624-8034-0e1ebe1a83fc

Pujan92 avatar Aug 28 '24 10:08 Pujan92

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

melvin-bot[bot] avatar Aug 28 '24 16:08 melvin-bot[bot]

@Pujan92 @luacmartins @joekaufmanexpensify 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!

melvin-bot[bot] avatar Aug 28 '24 18:08 melvin-bot[bot]

Pending input from @luacmartins on the above cases

joekaufmanexpensify avatar Aug 29 '24 13:08 joekaufmanexpensify

@Pujan92 so the new update returns a pdf url instead of jpg one, is that right? I'm not sure we can change the type of the returned Onyx update (it might lead to bugs elsewhere in App). Can we just update the URL to match the jpg thumbnail format?

luacmartins avatar Aug 29 '24 16:08 luacmartins

@Pujan92 so the new update returns a pdf url instead of jpg one, is that right?

Yes, that's the difference between the initial and updated snapshot.

I'm not sure we can change the type of the returned Onyx update (it might lead to bugs elsewhere in App). Can we just update the URL to match the jpg thumbnail format?

I believe, for the initial snapshot it seems transformed somewhere because in the below images you can see the transactions_ key has the receipt as pdf source whereas snapshot -> transactions_ has the jpg source.

Screenshot 2024-08-31 at 20 37 42 Screenshot 2024-08-31 at 20 37 06

Can we just update the URL to match the jpg thumbnail format?

Do you mean to just replace pdf extension with the jpg format? We can do that but I think better if this is first checked on the backend side whether we can update snapshot with correct transformed URL the way we gets for initial snapshot.

Pujan92 avatar Aug 31 '24 15:08 Pujan92

@Pujan92 the snapshot url is initially a jpg because the backend returns the thumbnail version of the receipt, which is always jpg.

Do you mean to just replace pdf extension with the jpg format? We can do that but I think better if this is first checked on the backend side whether we can update snapshot with correct transformed URL the way we gets for initial snapshot.

Yes, it seems like we just replace that here when returning thumbnails. It seems like we can do that same in this case, without the additional error/local file logic in that method.

luacmartins avatar Sep 03 '24 16:09 luacmartins

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

melvin-bot[bot] avatar Sep 03 '24 18:09 melvin-bot[bot]