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

[$500] Profile - View Profile photo after Uploading new photo shows attachment preview without name for a breif moment #29647

Closed
2 of 6 tasks
m-natarajan opened this issue Oct 16, 2023 · 19 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@m-natarajan
Copy link

m-natarajan commented Oct 16, 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!


Version Number: 1.3.84-1
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
Expensify/Expensify Issue URL:
Issue reported by: @ishpaul777
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1697307312806139

Action Performed:

  1. Navigate to profile photo.
  2. Upload a new profile photo and quickly click on 'View photo" after uploading

Expected Result:

If photo is loading Attachment modal shows loading indicator without showing attachment preview

Actual Result:

View Profile photo after Uploading new photo shows attachment preview without name for a breif moment

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Android: Native
Screen.Recording.2023-10-16.at.4.16.21.AM.mov
Android: mWeb Chrome
Screen.Recording.2023-10-16.at.4.22.06.AM.mov
iOS: Native
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2023-10-16.at.04.17.37.mp4
iOS: mWeb Safari
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2023-10-16.at.04.19.23.mp4
MacOS: Chrome / Safari
Screen.Recording.2023-10-14.at.11.44.49.PM.mov
Profile.-.View.Profile.photo.after.Uploading.new.photo.shows.attachment.mp4
MacOS: Desktop
Screen.Recording.2023-10-14.at.11.42.31.PM.mov

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0123f3f4476583bca2
  • Upwork Job ID: 1713712576697483264
  • Last Price Increase: 2023-10-16
@m-natarajan m-natarajan added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 16, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 16, 2023

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

@melvin-bot melvin-bot bot changed the title Profile - View Profile photo after Uploading new photo shows attachment preview without name for a breif moment [$500] Profile - View Profile photo after Uploading new photo shows attachment preview without name for a breif moment Oct 16, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 16, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0123f3f4476583bca2

@melvin-bot
Copy link

melvin-bot bot commented Oct 16, 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

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

melvin-bot bot commented Oct 16, 2023

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

@tienifr
Copy link
Contributor

tienifr commented Oct 16, 2023

Proposal

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

Profile - View Profile photo after Uploading new photo shows attachment preview without name for a breif moment

What is the root cause of that problem?

We're showing the paperClip icon here if the file is not the image

const isImage = typeof source === 'number' || Str.isImage(source);
if (isImage || (file && Str.isImage(file.name))) {

we just set the file when the AttachmentModal is mounted.

const [file, setFile] = useState(
props.originalFileName
? {
name: props.originalFileName,
}
: undefined,
);

After uploading the new image, we're updating the originalFileName and avatar

avatar: file.uri,
avatarThumbnail: file.uri,
originalFileName: file.name,

but because the AttachmentModal is already mounted so file is not updated to the new one right after originalFileName get changed

-> When the modal is open file is undefined -> paperClip is shown for a brief moment

Note: Why does this issue happen at the first time users change the avatar?

When users delete the avatar, we don't clear the originalFileName -> file is always the image

value: {
[currentUserAccountID]: {
avatar: defaultAvatar,
fallbackIcon: null,
},

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

we should update the file when the originalFileName get changed in AttachmentModal.js

    useEffect(()=>{
        if(!props.originalFileName) return;
        setFile(props.originalFileName
            ? {
                  name: props.originalFileName,
              }
            : undefined,)
    },[props.originalFileName])

We also need to clear originalFileName here

Result

Screen.Recording.2023-10-16.at.12.19.37.mov

@fedirjh
Copy link
Contributor

fedirjh commented Oct 16, 2023

We're showing the paperClip icon here if the file is not the image

@tienifr I added a console.log after that line, and it displayed the following result: the file.name is empty, but the source is a blob source, which is a valid source. So, technically, we should display the blob source even if the name is empty, right? why do we need the file.name to display the image?

Screenshot 2023-10-16 at 12 16 57 PM

@tienifr
Copy link
Contributor

tienifr commented Oct 16, 2023

@fedirjh Is this the first time you change the avatar? Or can you remove the avatar and logout then login again

@fedirjh
Copy link
Contributor

fedirjh commented Oct 16, 2023

Is this the first time you change the avatar? Or can you remove the avatar and logout then login again

I removed the personal details and, synced personal details then changed the avatar. I was not able to replicate the bug after the first time avatar change.

So this #29647 (comment) was when the bug occurred .

@tienifr
Copy link
Contributor

tienifr commented Oct 16, 2023

@fedirjh The isImage function just check the extension of the source. As you can see the source above doesn't have any extensions -> it returns false

https://github.com/Expensify/expensify-common/blob/bdbdf44825658500ba581d3e86237d7b8996cc2e/lib/str.js#L1088

@fedirjh
Copy link
Contributor

fedirjh commented Oct 16, 2023

@tienifr Ok, so we require file.name to be set for blob URLs? this is a weird behavior. Why the filename is empty?

@fedirjh
Copy link
Contributor

fedirjh commented Oct 16, 2023

@tienifr This is a regression from #22145, So the server does not return originalFileName, and initially the filename is set to an empty string.

@tienifr Is it possible to remove originalFileName from the profile picker?

@tienifr
Copy link
Contributor

tienifr commented Oct 16, 2023

@fedirjh I am afraid that without filename we can not detect the uploaded file is image or pdf,...

@fedirjh
Copy link
Contributor

fedirjh commented Oct 16, 2023

I am afraid that without filename we can not detect the uploaded file is image or pdf,...

Don't we validate images inside the profile picker?

@tienifr I get this error when I try to upload a pdf

Screenshot 2023-10-16 at 5 54 30 PM

@tienifr
Copy link
Contributor

tienifr commented Oct 16, 2023

@fedirjh I mean the temporary file is a blob and it can be the image or pdf so we need the file name to detect. We already mentioned that in

// 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 text field.
// We also check for numeric source since this is how static images (used for preview) are represented in RN.
const isImage = typeof source === 'number' || Str.isImage(source);
if (isImage || (file && Str.isImage(file.name))) {

and

// Check both source and file.name since PDFs dragged into the text field
// will appear with a source that is a blob

@fedirjh
Copy link
Contributor

fedirjh commented Oct 16, 2023

I mean the temporary file is a blob and it can be the image or pdf so we need the file name to detect.

@tienifr Have you tried to upload a PDF to a profile pic? that's not possible for me and got an error, We have validation to prevent sending invalid files for profile pic unless I am missing something ?

We already mentioned that in

It's possible to send pdf files inside the report so we need that validation there.

One solution is that we hardcode the originalFileName for both the profile and workspace avatar, something like profileAvatar and workspaceAvatar or we can use IDs to generate names.

@tienifr
Copy link
Contributor

tienifr commented Oct 16, 2023

@fedirjh I think we can't remove originalFileName as we still use it to detect file type, and I'm not really a big fan of hardcode the originalFileName for both the profile and workspace avatar. What do you think about my proposal above? When the originalFileName get changed, we should update the file too.

The file is updated only in validateAndDisplayFileToUpload, onNavigate.

Currently originalFileName is just used for Avatar picker, and in these components we did not use validateAndDisplayFileToUpload and onNavigate (there's no report). That why the file is never updated (except users reload page). I believe it's not correct and can lead some errors (at least this one)

@fedirjh
Copy link
Contributor

fedirjh commented Oct 16, 2023

Hey @tienifr this issue seems to be a duplicate of #29647, I will post in the other issue.

@fedirjh
Copy link
Contributor

fedirjh commented Oct 16, 2023

I think we can't remove originalFileName as we still use it to detect file type, and I'm not really a big fan of hardcode the originalFileName for both the profile and workspace avatar.

I understand your point; the code becomes less and less readable.

What do you think about my proposal above? When the originalFileName get changed, we should update the file too.

We can proceed with it, but it appears to be a patch on top of a poorly implemented solution, which will make the code less readable and less maintainable.

Currently originalFileName is just used for Avatar picker, and in these components we did not use validateAndDisplayFileToUpload and onNavigate (there's no report). That why the file is never updated (except users reload page). I believe it's not correct and can lead some errors (at least this one)

Yes, I agree with that. I think the best solution is to remove originalFileName and implement a new prop, isImage, for the AttachmentModal. FWIW, in the profile pic attachment view, we already know that we have to display an image as it's already validated during upload, so having its name to detect the type doesn't make sense to me in the current implementation.

@melvin-bot melvin-bot bot added the Overdue label Oct 19, 2023
@fedirjh
Copy link
Contributor

fedirjh commented Oct 19, 2023

cc @anmurali Let's close this issue : #28036 (comment)

@melvin-bot melvin-bot bot removed the Overdue label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
None yet
Development

No branches or pull requests

5 participants