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

Change UI view for Attachments in Chat #4736

Merged
merged 13 commits into from
Aug 23, 2021

Conversation

akshayasalvi
Copy link
Contributor

@akshayasalvi akshayasalvi commented Aug 18, 2021

Details

Fixed Issues

$ #4601

Tests

QA Steps

  1. Go to any chat
  2. Upload any word document (docx) or non-preview document
  3. Verify the new attachment block UI
  4. Also clicking on download should give the same filename as preview

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

website

Mobile Web

mobile-web

Desktop

desktop

iOS

ios

Android

android

@github-actions
Copy link
Contributor

github-actions bot commented Aug 18, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@@ -67,6 +67,8 @@ function AnchorRenderer({tnode, key, style}) {

// An auth token is needed to download Expensify chat attachments
const isAttachment = Boolean(htmlAttribs['data-expensify-source']);
const fileName = isAttachment && tnode.domNode && tnode.domNode.children && tnode.domNode.children[0] && tnode.domNode.children[0].data ? tnode.domNode.children[0].data : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use lodashGet to clean this up a bit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@akshayasalvi
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@akshayasalvi akshayasalvi marked this pull request as ready for review August 18, 2021 18:55
@akshayasalvi akshayasalvi requested a review from a team as a code owner August 18, 2021 18:55
@MelvinBot MelvinBot requested review from thienlnam and removed request for a team August 18, 2021 18:55
href={href}
hrefAttrs={{rel, target}}

props.shouldDownloadFile
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's update this prop to isAttachment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 64 to 68
{props.rightElement && (
<View style={styles.ml2}>
{props.rightElement}
</View>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing down rightElement as props, pass down a prop called shouldShowDownloadIcon to conditionally render the download icon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

href={href}
hrefAttrs={{rel, target}}

props.shouldDownloadFile
Copy link
Contributor

Choose a reason for hiding this comment

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

update prop name to isAttachment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 27 to 28

text: PropTypes.string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this prop above style, and add comment
Also rename from text to fileName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -81,6 +84,7 @@ function AnchorRenderer({tnode, key, style}) {
rel={htmlAttribs.rel || 'noopener noreferrer'}
style={style}
key={key}
text={fileName}
Copy link
Contributor

Choose a reason for hiding this comment

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

like above, change text prop name to fileName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -67,6 +68,8 @@ function AnchorRenderer({tnode, key, style}) {

// An auth token is needed to download Expensify chat attachments
const isAttachment = Boolean(htmlAttribs['data-expensify-source']);
const fileName = isAttachment ? lodashGet(tnode, 'domNode.children[0].data') : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a default param to lodashGet(tnode, 'domNode.children[0].data') of an empty string '' and remove the conditional and just use that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@akshayasalvi
Copy link
Contributor Author

@thienlnam PR updated. Let me know if any other changes.

Comment on lines 18 to 19
/** Flag to differentiate attachments and hyperlink. Base on flag link will be treated as a file download or a regular hyperlink?
* (relevant to native platforms only) */
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the ? and (relevant to native platforms only) since it applies to all platforms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@thienlnam
Copy link
Contributor

Changes look good, just the small name comment. I tested and it works as expected, but the file download name isn't the same name that is shown, it is still the name of a randomly generated string

@akshayasalvi
Copy link
Contributor Author

@thienlnam I have done those changes too but it doesn't work. I am getting a CORS issue when the fileDownload code works and then it ends up opening the URL in the catch block Linking.openURL(url);. If this can be fixed then I can push those changes too.

@akshayasalvi akshayasalvi requested a review from thienlnam August 20, 2021 21:17
Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

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

I've been doing some testing and am not getting the downloaded file to match the file name - are you experiencing the same issue?

@akshayasalvi
Copy link
Contributor Author

Are you checking from localhost? That's what I was mentioning in the previous comment, I get a CORS error. Hence, fetch(url) fails, and the following block is executed.

}).catch(() => {
     // file could not be downloaded, open sourceURL in new tab
     Linking.openURL(url);
});

@thienlnam
Copy link
Contributor

@akshayasalvi Gotcha, yeah that's where I've been testing - going to merge and we'll see if expected behavior still happens on prod

@akshayasalvi
Copy link
Contributor Author

@thienlnam Thanks for approving. We should be able to test this on staging right?

@thienlnam thienlnam merged commit 90bff75 into Expensify:main Aug 23, 2021
@thienlnam
Copy link
Contributor

@akshayasalvi Yup, will be tested on staging before it goes live on production (sorry, should have clarified)

@OSBotify
Copy link
Contributor

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

@isagoico
Copy link

@akshayasalvi Hello! Any QA tests needed for this PR?

@akshayasalvi
Copy link
Contributor Author

@isagoico I've added the QA steps

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @roryabraham in version: 1.0.88-2 🚀

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

@botify
Copy link

botify commented Sep 1, 2021

This has been deployed to production and is now subject to a 7-day regression period.
If no regressions arise, payment will be issued on 2021-09-08. 🎊

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.

5 participants