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

feat: add PDFThumbnail to preview PDF receipt #35255

Merged
merged 13 commits into from
Mar 5, 2024

Conversation

eh2077
Copy link
Contributor

@eh2077 eh2077 commented Jan 26, 2024

Details

Fixed Issues

$ #31432
PROPOSAL: #31432 (comment)

Tests

  1. Go to a chat and click request money
  2. Use scan function and select a PDF file
  3. Verify that you're able to preview the PDF receipt in the confirm page
  4. Click Request button to send money request
  5. Verify that you're able to preview the PDF receipt in chat report and the PDF thumbnail is reloaded after it's successfully uploaded.
  6. Click IOU preview from chat report to open IOU report
  7. Verify that you're able to preview PDF receipt in IOU report
  8. Click the PDF thumbnail from IOU report to open the transaction report
  9. Verify that you're able to preview PDF receipt in transaction report
  10. Click the PDF thumbnail to open PDF preview modal
  11. Verify that you're able to preview PDF pages
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
0-android-offline.mp4
0-android-online.mp4
Android: mWeb Chrome
0-mobile-chrome-offline.mp4
0-mobile-chrome-online.mp4
iOS: Native
0-ios-offline.mp4
0-ios-online.mp4
iOS: mWeb Safari
0-mobile-safari-offline.mp4
0-mobile-safari-online.mp4
MacOS: Chrome / Safari
0-web-offline.mp4
0-web-online.mp4
MacOS: Desktop
0-desktop-offline.mp4
0-desktop-online.mp4

@eh2077 eh2077 requested a review from a team as a code owner January 26, 2024 16:17
@melvin-bot melvin-bot bot requested review from s77rt and removed request for a team January 26, 2024 16:17
Copy link

melvin-bot bot commented Jan 26, 2024

@s77rt Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Copy link
Contributor

@s77rt s77rt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix typescript errors

src/components/PDFThumbnail/WebPDFThumbnail.tsx Outdated Show resolved Hide resolved
src/components/PDFThumbnail/index.tsx Outdated Show resolved Hide resolved
@eh2077 eh2077 force-pushed the 31432-smart-scan-pdf-thumbnail branch from a381041 to 58282ca Compare January 28, 2024 13:03
@eh2077 eh2077 requested a review from s77rt January 28, 2024 13:10
@eh2077
Copy link
Contributor Author

eh2077 commented Jan 28, 2024

Hmm, I'm still unable to build iOS App after rebasing on the main branch. I got following error when run pod install

[!] The following Swift pods cannot yet be integrated as static libraries:

The Swift pod `ExpoModulesCore` depends upon `glog`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.

Maybe it'll be solved after #35249 is merged?

src/components/ReportActionItem/ReportActionItemImage.tsx Outdated Show resolved Hide resolved
src/libs/ReceiptUtils.ts Outdated Show resolved Hide resolved
src/components/PDFThumbnail/types.ts Outdated Show resolved Hide resolved
src/components/PDFThumbnail/index.tsx Outdated Show resolved Hide resolved
src/components/PDFThumbnail/index.tsx Outdated Show resolved Hide resolved
src/components/PDFThumbnail/index.native.tsx Outdated Show resolved Hide resolved
src/components/PDFThumbnail/index.native.tsx Outdated Show resolved Hide resolved
@s77rt
Copy link
Contributor

s77rt commented Jan 28, 2024

On Web the pdf preview have a cursor pointer, let's use the default pointer instead as the preview is not clickable

Screen.Recording.2024-01-28.at.7.51.58.PM.mov

@s77rt
Copy link
Contributor

s77rt commented Jan 28, 2024

The local preview do not match the one returned by the server

Screen.Recording.2024-01-28.at.9.31.20.PM.mov
Screen.Recording.2024-01-28.at.8.15.55.PM.mov

@s77rt
Copy link
Contributor

s77rt commented Jan 28, 2024

Uploading a password protected pdf results in a non-ending prompt unless you type the right pasword

Screen.Recording.2024-01-28.at.9.14.00.PM.mov

@eh2077
Copy link
Contributor Author

eh2077 commented Jan 30, 2024

The local preview do not match the one returned by the server

Oh yes, I also noticed this but it seems hard to implement the same with what backend does. See #31432 (comment) about the backend implementation.

Should we ask the product team to decide if we need to keep the resolution of local PDF thumbnail same as the one returned by backend?

@eh2077 eh2077 force-pushed the 31432-smart-scan-pdf-thumbnail branch 2 times, most recently from be0f6e4 to b000ed8 Compare January 30, 2024 15:02
@eh2077 eh2077 requested a review from s77rt January 30, 2024 15:29
@s77rt
Copy link
Contributor

s77rt commented Jan 31, 2024

@eh2077 Please check #35255 (comment)

For the password bug, I think we should show an error if the user is uploading a password protected file since the BE can't scan it anyway

@eh2077
Copy link
Contributor Author

eh2077 commented Feb 1, 2024

@eh2077 Please check #35255 (comment)

For the password bug, I think we should show an error if the user is uploading a password protected file since the BE can't scan it anyway

Got it and I'll update later

@s77rt
Copy link
Contributor

s77rt commented Feb 5, 2024

@eh2077 Any updates here?

@eh2077
Copy link
Contributor Author

eh2077 commented Feb 6, 2024

@s77rt My updates are as follows
For the password protected issue, I tried to find a method from react-pdf lib to check if it's protected by checking the local file path (starts with file:// or blob://. But I didn't find such method. It seem we have to load the PDF and use the onPassword callback to know a PDF is protected or not. If onPassword is triggered, we need to return to previous step of the receipt scanning flow. If we want to show a popup box alert to let user know protected PDF is not allowed, is there an existing component we can reuse to show the alert? Also note that this issue exists before this feature. So I'm not sure if it can be taken as out of scope here.

For thumbnail resolution/size not consistent issue, I tried to tune the size of PDF by passing width or height property to the PDF thumbnail component. But it seems not easy to achieve what we want in this way. The PDF is rendered as canvas while the image thumbnail is rendered by <img>.

Kindly let me know your thoughts on them.

@s77rt
Copy link
Contributor

s77rt commented Feb 6, 2024

@eh2077 Regarding the password issue, previously the uploaded file would just fail but now it's creating an endless prompt which is something that we should fix. The least we can do is to prevent this prompt and let the uploaded file just fail as on main

@s77rt
Copy link
Contributor

s77rt commented Feb 11, 2024

@eh2077 Any updates here?

@eh2077
Copy link
Contributor Author

eh2077 commented Feb 12, 2024

@s77rt Sorry for the delay. I'm working on fixing the endless prompt. I'll push an update early tmr.

@eh2077 eh2077 force-pushed the 31432-smart-scan-pdf-thumbnail branch from b000ed8 to 7c2425d Compare February 13, 2024 08:22
@eh2077
Copy link
Contributor Author

eh2077 commented Feb 13, 2024

@s77rt I did a forced push in this PR to solve conflicts and avoid missing changes from main branch. I fixed the endless password prompt issue of web platform (native platforms don't have this issue) by passing an empty onPassword={() => {}} callback to the Document component. See below video

Screen.Recording.2024-02-13.at.4.20.38.PM.mov

If the pdf uploaded is protected, it shows the FullScreenLoadingIndicator and then an error returned by backend. Though it's still not exactly same as the production, I think it's acceptable. We can try solve this in a separate issue with a holistic and more UX friendly solution. Do you agree?

@s77rt
Copy link
Contributor

s77rt commented Feb 13, 2024

@eh2077 Please do not force push. This messes up the review process. Can you try undo that force push?

@s77rt
Copy link
Contributor

s77rt commented Feb 13, 2024

If the pdf uploaded is protected, it shows the FullScreenLoadingIndicator

That may confuse the user, can we show instead the generic pdf thumbnail?

@eh2077
Copy link
Contributor Author

eh2077 commented Feb 29, 2024

@eh2077 Please fix the unnecessary pointer cursor #35255 (comment)

@s77rt The pointer issue is fixed.

@eh2077
Copy link
Contributor Author

eh2077 commented Feb 29, 2024

@eh2077 Where did we land on the different thumbnails #35255 (comment)?

For thumbnail resolution/size not consistent issue, I tried to tune the size of PDF by passing width or height property to the PDF thumbnail component. But it seems not easy to achieve what we want in this way. The PDF is rendered as <canvas> while the image thumbnail is rendered by <img>. It's tricky to eliminate the resolution difference between <img> and <canvas>. I hope that this flaw will be considered acceptable. What do you think?

cc @trjExpensify

@eh2077 eh2077 requested a review from s77rt February 29, 2024 15:06
@trjExpensify
Copy link
Contributor

I don't want to hold getting thumbnails of PDFs out on that for sure. I think it's also being looked into here tbh: #35041 (comment)

src/components/PDFThumbnail/types.ts Outdated Show resolved Hide resolved
src/components/PDFThumbnail/index.tsx Outdated Show resolved Hide resolved
@eh2077 eh2077 requested a review from s77rt March 1, 2024 00:28
src/components/PDFThumbnail/index.tsx Outdated Show resolved Hide resolved
src/components/PDFThumbnail/index.tsx Outdated Show resolved Hide resolved
@s77rt
Copy link
Contributor

s77rt commented Mar 1, 2024

@eh2077 In tests steps change Verify that it's able to to Verify that you are able to

@eh2077 eh2077 requested a review from s77rt March 4, 2024 13:41
@melvin-bot melvin-bot bot requested a review from luacmartins March 4, 2024 16:43
@s77rt
Copy link
Contributor

s77rt commented Mar 4, 2024

@eh2077 Thank you!

src/languages/es.ts Outdated Show resolved Hide resolved
@luacmartins
Copy link
Contributor

Just one small translation change

Co-authored-by: Carlos Martins <luacmartins@gmail.com>
@luacmartins luacmartins merged commit 6cb4b24 into Expensify:main Mar 5, 2024
15 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Mar 5, 2024

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Mar 6, 2024

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.4.48-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@deetergp
Copy link
Contributor

deetergp commented Mar 7, 2024

I think this might have caused this regression.

@OSBotify
Copy link
Contributor

OSBotify commented Mar 7, 2024

🚀 Deployed to production by https://github.com/roryabraham in version: 1.4.48-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

const thumbnail = useMemo(
() => (
<Document
loading={<FullScreenLoadingIndicator />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming for this issue #39356 , since we are not passing the error prop to the Document, the Document will display the message 'Failed to load PDF file.' text in case of an error. This, however, causes a UI issue in the dark theme of our app. we should have passed a custom error component here to avoid UI issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants