feat: add PDFThumbnail to preview PDF receipt
Details
Fixed Issues
$ https://github.com/Expensify/App/issues/31432 PROPOSAL: https://github.com/Expensify/App/issues/31432#issuecomment-1820184229
Tests
- Go to a chat and click request money
- Use scan function and select a PDF file
- Verify that it's able to preview the PDF receipt in the confirm page
- Click
Requestbutton to send money request - Verify that it's able to preview the PDF receipt in chat report and the PDF thumbnail is reloaded after it's successfully uploaded.
- Click IOU preview from chat report to open IOU report
- Verify that it's able to preview PDF receipt in IOU report
- Click the PDF thumbnail from IOU report to open the transaction report
- Verify that it's able to preview PDF receipt in transaction report
- Click the PDF thumbnail to open PDF preview modal
- Verify that it's able to preview PDF pages
- [x] Verify that no errors appear in the JS console
Offline tests
QA Steps
Same as tests
- [x] Verify that no errors appear in the JS console
PR Author Checklist
- [x] I linked the correct issue in the
### Fixed Issuessection above - [x] I wrote clear testing steps that cover the changes made in this PR
- [x] I added steps for local testing in the
Testssection - [x] I added steps for the expected offline behavior in the
Offline stepssection - [x] I added steps for Staging and/or Production testing in the
QA stepssection - [x] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
- [x] 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)
- [x] 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).
- [x] I added steps for local testing in the
- [x] I included screenshots or videos for tests on all platforms
- [x] I ran the tests on all platforms & verified they passed on:
- [x] Android: Native
- [x] Android: mWeb Chrome
- [x] iOS: Native
- [x] iOS: mWeb Safari
- [x] MacOS: Chrome / Safari
- [x] MacOS: Desktop
- [x] 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)
- [x] I followed proper code patterns (see Reviewing the code)
- [x] 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.
toggleReportand notonIconClick) - [x] I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g.
myBool && <MyComponent />. - [x] I verified that comments were added to code that is not self explanatory
- [x] 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.
- [x] I verified any copy / text shown in the product is localized by adding it to
src/languages/*files and using the translation method- [x] 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:
- [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
- [x] 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 Copylabel for a copy review on the original GH to get the correct copy. - [x] 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.
- [x] I verified the JSDocs style guidelines (in
STYLE.md) were followed
- [x] 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.
- [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- [x] I followed the guidelines as stated in the Review Guidelines
- [x] 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 usingAvatarare working as expected) - [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
- [x] 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
- [x] I verified that if a function's arguments changed that all usages have also been updated correctly
- [x] If any new file was added I verified that:
- [x] 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
- [x] If a new CSS style is added I verified that:
- [x] A similar style doesn't already exist
- [x] The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
- [x] 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.
- [x] 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
Avataris modified, I verified thatAvataris working as expected in all cases) - [x] 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.
- [x] 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.
- [x] If the PR modifies the form input styles:
- [x] I verified that all the inputs inside a form are aligned with each other.
- [x] I added
Designlabel so the design team can review the changes.
- [x] If a new page is added, I verified it's using the
ScrollViewcomponent to make it scrollable when more elements are added to the page. - [x] If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.
Screenshots/Videos
Android: Native
https://github.com/Expensify/App/assets/117511920/0bdfbe46-f375-4253-911f-c83c2cd86140
https://github.com/Expensify/App/assets/117511920/7cc72966-fdea-49cd-ba0d-3367812fec09
Android: mWeb Chrome
https://github.com/Expensify/App/assets/117511920/69f4d015-30e7-476d-a29e-ca5acf02658d
https://github.com/Expensify/App/assets/117511920/2f6236df-4eeb-40ea-8c86-7ee23acb2417
iOS: Native
iOS: mWeb Safari
https://github.com/Expensify/App/assets/117511920/389f4bdc-f67d-4f7c-b7fc-7374efd79b65
https://github.com/Expensify/App/assets/117511920/10cc147a-a4ce-4959-a1d8-82c67ce31bec
MacOS: Chrome / Safari
https://github.com/Expensify/App/assets/117511920/4612c7f3-1ded-4972-b58c-a3643180b4ce
https://github.com/Expensify/App/assets/117511920/b0d0e6c7-ad40-44fe-8f0a-636bf2f67a1a
MacOS: Desktop
https://github.com/Expensify/App/assets/117511920/811fb98b-7223-4432-b424-12710099db02
https://github.com/Expensify/App/assets/117511920/23f0d749-ddbf-4464-8ef2-3661ad9d1a83
@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]
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 https://github.com/Expensify/App/pull/35249 is merged?
On Web the pdf preview have a cursor pointer, let's use the default pointer instead as the preview is not clickable
https://github.com/Expensify/App/assets/16493223/97465eb9-fc3e-427d-9ba0-42715d19fd2b
The local preview do not match the one returned by the server
https://github.com/Expensify/App/assets/16493223/e084b2cd-9e4d-4bb4-a97d-ddb997b98c84
https://github.com/Expensify/App/assets/16493223/92c69be3-1c9a-4bb3-b402-127db5938f62
Uploading a password protected pdf results in a non-ending prompt unless you type the right pasword
https://github.com/Expensify/App/assets/16493223/022b1852-7608-4ba6-bce1-9c9c84e25fb5
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 https://github.com/Expensify/App/issues/31432#issuecomment-1839330922 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 Please check https://github.com/Expensify/App/pull/35255#discussion_r1471656045
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 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
@eh2077 Any updates here?
@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.
@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
@eh2077 Any updates here?
@s77rt Sorry for the delay. I'm working on fixing the endless prompt. I'll push an update early tmr.
@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
https://github.com/Expensify/App/assets/117511920/11ee91de-7ebe-4565-9e0a-0f11489c2bda
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?
@eh2077 Please do not force push. This messes up the review process. Can you try undo that force push?
If the pdf uploaded is protected, it shows the FullScreenLoadingIndicator
That may confuse the user, can we show instead the generic pdf thumbnail?
@eh2077 Please do not force push. This messes up the review process. Can you try undo that force push?
Ah, sorry but it can't be restored. Don't worry I did usual manual merging in subsequent conflicts.
If the pdf uploaded is protected, it shows the FullScreenLoadingIndicator
That may confuse the user, can we show instead the generic pdf thumbnail?
Yes, indeed it's a bit confusing. I tried to use ConfirmModal to show the alert message and return back the previous step. Does the following demo look good to you?
https://github.com/Expensify/App/assets/117511920/4ede2ca5-45d1-492e-8b6d-fab87f1fddfa
Nice! I'm very excited to get this over the line. On the error handling why are we navigating to the confirmation page?
For comparison here's how the validation works for a file type not supported (i.e mp4), for which I would think we would have exactly the same experience:
https://github.com/Expensify/App/assets/16232057/a81b2b17-af23-42a0-b286-d3dba4d251ce
On the error handling why are we navigating to the confirmation page?
@trjExpensify Good question! Hmm the tricky part here is that we need to load PDF to know if it's protected. And the PDF thumbnail component is in the confirmation page. Validating file type is easier as it doesn't need to read the file.
I'll wait input from @s77rt to see if they have better ideas.
Indeed we would have to read the file to determine if it's password-protected. I think this new behaviour https://github.com/Expensify/App/pull/35255#issuecomment-1944087612 is still better than main as we won't allow the user to upload a file that would just error out
Okay, got it. That's helpful context! Should we stop that background spinner and use the "empty state" thumbnail default once we've read it? That's what makes the background look a little janky because it's continuing to spin.
Should we stop that background spinner and use the "empty state" thumbnail default once we've read it? That's what makes the background look a little janky because it's continuing to spin.
I'm working on a fix to solve this.
@s77rt I'll push an update tmr.
Should we stop that background spinner and use the "empty state" thumbnail default once we've read it? That's what makes the background look a little janky because it's continuing to spin.
@trjExpensify I updated to let the background be empty. Please help to check if following demo looks good to you.
https://github.com/Expensify/App/assets/117511920/f87ca1bb-d40f-4f0c-b8cd-395149975aba
Click to see native App demo
https://github.com/Expensify/App/assets/117511920/ae5bde02-8be5-4b23-91cd-8626729192f5
And also kindly help to review the title and error message of the alert popup :)
- Title:
Attachment errorwhich is an existing translation key https://github.com/Expensify/App/blob/bea6aafa5e1b4a80462c3da1f3c56325d3a3977d/src/languages/en.ts#L325 - Error message:
Password protected PDF receipt is not supported.which is a new one to be added and need corresponding Spanish translation.
@s77rt PR is updated and this time I managed to solve conflicts without force push. I found that I really like rebasing-and-force-pushing a PR. I think it has benefits to maintain a clean commit history and resolve merge conflicts earlier but I have to admit that it's sometimes not friendly in collaboration like you mentioned.
@trjExpensify I updated to let the background be empty. Please help to check if following demo looks good to you.
Great, thanks!
Reviewer Checklist
- [X] I have verified the author checklist is complete (all boxes are checked off).
- [X] I verified the correct issue is linked in the
### Fixed Issuessection above - [X] I verified testing steps are clear and they cover the changes made in this PR
- [X] I verified the steps for local testing are in the
Testssection - [X] I verified the steps for Staging and/or Production testing are in the
QA stepssection - [X] I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
- [X] 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)
- [X] I verified the steps for local testing are in the
- [X] I checked that screenshots or videos are included for tests on all platforms
- [X] I included screenshots or videos for tests on all platforms
- [X] I verified tests pass on all platforms & I tested again on:
- [X] Android: Native
- [X] Android: mWeb Chrome
- [X] iOS: Native
- [X] iOS: mWeb Safari
- [X] MacOS: Chrome / Safari
- [X] MacOS: Desktop
- [X] If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
- [X] I verified proper code patterns were followed (see Reviewing the code)
- [X] 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.
toggleReportand notonIconClick). - [X] I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g.
myBool && <MyComponent />. - [X] I verified that comments were added to code that is not self explanatory
- [X] 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.
- [X] I verified any copy / text shown in the product is localized by adding it to
src/languages/*files and using the translation method - [X] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
- [X] 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 Copylabel for a copy review on the original GH to get the correct copy. - [X] 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.
- [X] I verified the JSDocs style guidelines (in
STYLE.md) were followed
- [X] 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.
- [X] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- [X] I verified that this PR follows the guidelines as stated in the Review Guidelines
- [X] I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like
Avatar, I verified the components usingAvatarhave been tested & I retested again) - [X] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
- [X] 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
- [X] If a new component is created I verified that:
- [X] A similar component doesn't exist in the codebase
- [X] All props are defined accurately and each prop has a
/** comment above it */ - [X] The file is named correctly
- [X] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- [X] The only data being stored in the state is data necessary for rendering and nothing else
- [X] For Class Components, any internal methods passed to components event handlers are bound to
thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor) - [X] Any internal methods bound to
thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick) - [X] All JSX used for rendering exists in the render method
- [X] The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
- [X] If any new file was added I verified that:
- [X] 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
- [X] If a new CSS style is added I verified that:
- [X] A similar style doesn't already exist
- [X] The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
- [X] 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.
- [X] 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
Avataris modified, I verified thatAvataris working as expected in all cases) - [X] 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.
- [X] 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.
- [X] If the PR modifies the form input styles:
- [X] I verified that all the inputs inside a form are aligned with each other.
- [X] I added
Designlabel so the design team can review the changes.
- [X] If a new page is added, I verified it's using the
ScrollViewcomponent to make it scrollable when more elements are added to the page. - [X] If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps. - [X] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
Screenshots/Videos
Android: Native
https://github.com/Expensify/App/assets/16493223/90c6ecbd-90e0-42a8-a60e-3efbb5c54a5c
Android: mWeb Chrome
https://github.com/Expensify/App/assets/16493223/be6b34fb-e37e-4d5d-842a-dbbfb996a420
iOS: Native
https://github.com/Expensify/App/assets/16493223/604f7628-4279-4327-ba7c-8bc65651388d
iOS: mWeb Safari
https://github.com/Expensify/App/assets/16493223/c0dcc28d-bed7-4190-a316-2bc3ce1c62f6
MacOS: Chrome / Safari
https://github.com/Expensify/App/assets/16493223/46c4b18e-ad68-4707-81ba-7901cbcd22b3
MacOS: Desktop
https://github.com/Expensify/App/assets/16493223/189a493b-dc8d-4d06-ae00-9d123e2c1bed
I suggest U hold this pr on https://github.com/Expensify/App/pull/34843. We are wrapping up on switching from using static receipt thumbnails to Ereceipt thumbnails and once it is merged U will only need to do some tweak here 👍
@FitseTLT Yeah, sure! We can hold this PR a bit as we're waiting for the translation.
I think we should go in parallel I don't see a reason to hold the PR