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

Disable image preview for invalid images #23103

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

youssef-lr
Copy link
Contributor

@youssef-lr youssef-lr commented Jul 18, 2023

Details

cc @MariaHCD

Fixed Issues

$ #19728

Tests

  • Verify that no errors appear in the JS console
  1. Change the extension of a non-image file to .jpg, for example a txt document.
  2. Upload the invalid image.
  3. Make sure the image gets uploaded properly without a preview
Screenshot 2023-07-18 at 17 25 39 Screenshot 2023-07-18 at 17 25 33

Offline tests

QA Steps

  • Verify that no errors appear in the JS console
  1. Change the extension of a non-image file to .jpg, for example a txt document.
  2. Upload the invalid image.
  3. Make sure the image gets uploaded properly without a preview
Screenshot 2023-07-18 at 17 25 39 Screenshot 2023-07-18 at 17 25 33

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 / Chrome
    • iOS / native
    • iOS / 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 a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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
  • 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(themeColors.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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web Screenshot 2023-07-18 at 17 25 39 Screenshot 2023-07-18 at 17 25 33
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android

@youssef-lr youssef-lr requested a review from a team as a code owner July 18, 2023 16:26
@youssef-lr youssef-lr self-assigned this Jul 18, 2023
@melvin-bot melvin-bot bot requested review from aimane-chnaif and removed request for a team July 18, 2023 16:26
@melvin-bot
Copy link

melvin-bot bot commented Jul 18, 2023

@aimane-chnaif 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]

@aimane-chnaif
Copy link
Contributor

@youssef-lr @MariaHCD just to confirm that we agreed to keep current file type checking logic from only file name in frontend, correct?

@youssef-lr
Copy link
Contributor Author

youssef-lr commented Jul 19, 2023

just to confirm that we agreed to keep current file type checking logic from only file name in frontend, correct?

Yes. There isn't a reliable way in the browser to detect the filetype other than reading first bytes from a file to detect the magic number, see this SO, and see this library which accomplishes this. The browser only decides filetypes based on the file extension so it's kind of useless.

Copy link
Contributor

@aimane-chnaif aimane-chnaif left a comment

Choose a reason for hiding this comment

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

Web looks good but not able to test native as it shows nothing in report action. Should native be fixed here or separately?

@aimane-chnaif
Copy link
Contributor

@youssef-lr bump on native fix

@huzaifa-99
Copy link
Contributor

huzaifa-99 commented Jul 28, 2023

Was just trying this out and after sending a corrupt image, a link preview for https://www.expensify.com/ will be added (If it doesn't come on the first image, upload the corrupt image multiple times)

Screen.Recording.2023-07-28.at.3.11.37.PM.mp4

This is the image i tried

cc: @aimane-chnaif @youssef-lr

@youssef-lr
Copy link
Contributor Author

@huzaifa-99 that makes sense and isn't a bug, it the image is invalid the URL preview will appear because it is treated like a link. @aimane-chnaif checking the native issue now.

@youssef-lr
Copy link
Contributor Author

Just pushed a fix @aimane-chnaif

@aimane-chnaif
Copy link
Contributor

reviewing today

@youssef-lr
Copy link
Contributor Author

bump @aimane-chnaif :)

@aimane-chnaif
Copy link
Contributor

@youssef-lr please fix conflict

@youssef-lr
Copy link
Contributor Author

On it, looks like AttachmentsView has been moved

@youssef-lr youssef-lr force-pushed the youssef_disable_invalid_image_preview branch from 7af2fe8 to c802b8c Compare August 15, 2023 14:53
@@ -95,7 +96,7 @@ function AttachmentView({
// For this check we use both source and file.name since temporary file source is a blob
// both PDFs and images will appear as images when pasted into the the text field
const isImage = Str.isImage(source);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aimane-chnaif I wonder why this isn't ìsImage = Str.isImage(source) || (file && Str.isImage(file.name)) then next we can just use if (isImage && isValidImage), am I missing something on why this could be intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

cc: @chrispader as this logic was added in #20798

Copy link
Contributor

Choose a reason for hiding this comment

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

I was actually just taking over the original logic from the previous code: https://github.com/margelo/expensify-app-fork/blob/9fa8c89b095d88b4066f209c16d34e3ee261e991/src/components/AttachmentView.js#L105-L106

I think the difference here is that we first check if the source is an image, else if there is a file prop and if that's an image. Not sure if this is intentional though, so i think somebody else has to answer this question. :)

@aimane-chnaif
Copy link
Contributor

@youssef-lr conflicts again

@aimane-chnaif
Copy link
Contributor

@youssef-lr bump

@@ -120,6 +121,7 @@ function AttachmentView({
loadComplete={loadComplete}
isFocused={isFocused}
isImage={isImage}
onError={() => setIsValidImage(false)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Receiving onError callback doesn't always mean that image is invalid.
i.e. when offline:

Screen.Recording.2023-08-27.at.5.50.53.PM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into this

@KALLL
Copy link

KALLL commented Sep 7, 2023

@youssef-lr Is there any update on this issue?

@KALLL
Copy link

KALLL commented Sep 25, 2023

@MariaHCD @youssef-lr @sonialiap @aimane-chnaif Could anyone update us the (beneficiary contributors) the status of this and related issues? Because we're looking for updates on this issue for more than 3 months. @youssef-lr this issue also delaying the #19728 for over 3 months going to be 4 months after 7 days. Any update?

@MariaHCD
Copy link
Contributor

@KALLL Expensifiers are all currently working on higher priority projects and issues so this one is falling off our radar.

@youssef-lr, since your plate is full, let's consider having a contributor take over instead?

@aimane-chnaif
Copy link
Contributor

@youssef-lr kindly bump ^

@aimane-chnaif
Copy link
Contributor

@youssef-lr can we open this for contributors?

@youssef-lr
Copy link
Contributor Author

Working on finishing up this PR now

@youssef-lr
Copy link
Contributor Author

@aimane-chnaif I can't reproduce the onError callback being triggered while being offline and image is valid, can you try again please?

@aimane-chnaif
Copy link
Contributor

@youssef-lr please merge main and fix conflict. I will test again based on latest codebase

@youssef-lr
Copy link
Contributor Author

Hmm I pushed earlier..not sure why these weren't showing up

Screenshot 2023-11-04 at 01 54 18

@@ -79,7 +79,7 @@ function AttachmentView({
isUsedInAttachmentModal,
}) {
const [loadComplete, setLoadComplete] = useState(false);
const [imageError, setImageError] = useState(false);
const [isValidImage, setIsValidImage] = useState(true);

useNetwork({onReconnect: () => setImageError(false)});
Copy link
Contributor

Choose a reason for hiding this comment

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

Lint failing

@aimane-chnaif
Copy link
Contributor

@youssef-lr to reproduce, image should not be locally cached. Test in fresh browser, i.e. incognito

Screen.Recording.2023-11-03.at.11.13.01.PM.mov

Also, another weird thing is that image (i.e. workspace avatar) is treated as file attachment

Screen.Recording.2023-11-03.at.11.12.06.PM.mov

@youssef-lr
Copy link
Contributor Author

Updated @aimane-chnaif, both issues should be fixed now hopefully!

@aimane-chnaif
Copy link
Contributor

Please check video (main vs this branch). Both issues still happening

(isImage: true, isValidImage: false, fallbackSource: undefined)

Screen.Recording.2023-11-05.at.7.54.06.AM.mov

@aimane-chnaif
Copy link
Contributor

I think we should confirm the expected page when preview "not cached image" when offline

  • current behavior: infinite loading
Screen.Recording.2023-11-05.at.8.03.14.AM.mov
  • this branch: file attachment
Screen.Recording.2023-11-05.at.8.02.26.AM.mov

cc: @Expensify/design

@youssef-lr
Copy link
Contributor Author

youssef-lr commented Nov 5, 2023

I mean it makes sense as we're trying to fetch the full size image from the server but we're offline. How about we display an error message like 'unable to load image'?

@aimane-chnaif
Copy link
Contributor

error message like 'unable to load image'?

Kind of agree as it's aligned with PDF preview in offline mode

@youssef-lr
Copy link
Contributor Author

Hmm I have the infinite loading with the changes from this PR, i.e. I don't see the link to the image as you do. One issue I found is that as soon as I disable internet the thumbnail disappears, even though it's already loaded which I think shouldn't happen.

Screen.Recording.2023-11-05.at.16.39.07.mov

@aimane-chnaif
Copy link
Contributor

Please follow step I did. 100% reproducible

  1. Send any attachment in chat
  2. Disable network
  3. Click on attachment
Screen.Recording.2023-11-05.at.1.46.56.PM.mov

@dannymcclain
Copy link
Contributor

I agree that it'd be nice align on the offline behavior—I like the idea of mimicking what we do with PDFs and showing the "Unable to load whatever" while offline. cc @Expensify/design

@youssef-lr
Copy link
Contributor Author

Heads up I'm OOO for a couple of days and I might not reply in a timely manner. I'll still probably finish this PR in a couple of days.

@KALLL
Copy link

KALLL commented Jun 4, 2024

Is there any update on this issue? @youssef-lr @aimane-chnaif or incase it is resolved it should be closed.

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.

7 participants