App icon indicating copy to clipboard operation
App copied to clipboard

[Pay Aug 18 if no regressions] Copy to clipboard - Unable to copy images or links

Open isagoico opened this issue 5 years ago • 31 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Expected Result:

  • User should be able to copy images and link URLs when using the copy to clipboard feature.
  • Right-clicking or long-pressing on a link should open the ReportActionContextMenu, but the Copy to Clipboard menu item should instead say Copy URL to Clipboard. Pressing that menu item, the link url should be copied to the clipboard.
  • Right-clicking or long-pressing on an image should open the ReportActionContextMenu, but the Copy to Clipboard menu should instead say Copy Image to Clipboard. Pressing that menu item, the image should be copied to the clipboard.

Actual Result:

When copying and pasting an image, the HTML coding is displayed instead of the link or image.

Action Performed:

  1. Log in to e.cash and navigate to a conversation
  2. Click on add attachment
  3. Upload a picture
  4. RIght click the message with the image
  5. Click on copy to clipboard
  6. Paste the image on a text input

Workaround:

No way of copying an image by using copy to clipboard.

Platform:

Where is this issue occurring?

Web ✔️ iOS ✔️ Android ✔️ Desktop App ✔️ Mobile Web ✔️

Version Number: 1.0.60-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos:

image

Expensify/Expensify Issue URL:

View all open jobs on Upwork


From @iwiznia https://expensify.slack.com/archives/C01GTK53T8Q/p1622579145427200

we sequester the right click button to show the actions menu, but that makes it impossible to copy a link that's in a comment or being able to copy an image pasted.

Upwork job: https://www.upwork.com/jobs/~015ed0068d5788ef5a

isagoico avatar Jun 02 '21 22:06 isagoico

Triggered auto assignment to @TomatoToaster (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Jun 02 '21 22:06 MelvinBot

Cool I think this makes sense to be done externally.

TomatoToaster avatar Jun 02 '21 23:06 TomatoToaster

Triggered auto assignment to @puneetlath (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Jun 02 '21 23:06 MelvinBot

Looks like this is fixed for links, but still needs to be addressed for images. Created an Upwork job for it.

puneetlath avatar Jun 08 '21 20:06 puneetlath

Sorry, but I don't see it's fixed for any type.

iwiznia avatar Jun 08 '21 20:06 iwiznia

For Images, we have to use the native Modules for Mobile devices but previously we left that part intentionally. So are we ready to go that path @roryabraham?

For links, I suggest a different context menu than the current one. It would have two items a) Copy Link b) Open Link.

parasharrajat avatar Jun 08 '21 20:06 parasharrajat

Hm, it's working for me on desktop on staging for links. image

puneetlath avatar Jun 08 '21 20:06 puneetlath

I think that's not what the issue meant.

Try this is a message with link https://google.com Now try to copy the link only.

parasharrajat avatar Jun 08 '21 20:06 parasharrajat

For all attachments (not just images) some html parsing needs to happen. To extract links from html. Here is how what I would do for images for example:

  const el = document.createElement('html');
  el.innerHTML = html;
  const imageUrl = el.querySelector('img').getAttribute('src');

imageUrl is something we'll pass to clipboard.

EDIT: Sorry, I forgot this is react native world. We can use React.createElement instead of document.createElement. EDIT2: Actually, nvm. We'll probably need to use some other lib to parse html in react native https://www.npmjs.com/package/react-native-html-parser .

dklymenk avatar Jun 08 '21 20:06 dklymenk

@puneetlath I updated the OP here a bit, can we please update the Upwork job to reflect that?

roryabraham avatar Jun 08 '21 22:06 roryabraham

Hm, @roryabraham @iwiznia @parasharrajat I think a few different issues are being conflated here. The original issue reported here was that when you copy a message that contains an image, it puts the raw html on your clipboard instead of just the image. This also was happening with messages that contained links, but isn't anymore (I had already removed @isagoico's screenshot that showed it).

I think we should split up what y'all are saying into separate issues and implement it slightly differently.

  1. When a message contains an image and is copied (either by hovering the message and choosing the "copy to clipboard" option or by right-clicking/long-pressing) copy the image itself. We can do this for messages that contain images since we don't support messages that have images + text. Any image input is only the image. (this issue)
  2. When a url is right-clicked/long-pressed select the text of the url. This will make it so that we only copy the URL since we already support copying only selected text. This would match the behavior I expect when using a typical web page and right clicking a URL. (separate issue)

That's how I'd implement this. And I'd do it in two different issues. What do y'all think?

puneetlath avatar Jun 09 '21 02:06 puneetlath

There's https://github.com/Expensify/Expensify.cash/issues/3317 too

iwiznia avatar Jun 09 '21 17:06 iwiznia

That's how I'd implement this. And I'd do it in two different issues. What do y'all think?

It's a good summation of the problem, but I would approach it slightly different. Those two issues could be separate, but imo they should not be. I'd prefer to see the same contributor work on both these issues (if they want to do 2 PRs, that's fine). My reasoning is that, at a very high level the solution is the same:

When the user right-clicks or long-presses an html element in a chat message, the ReportActionContextMenu should open, and the functionality of the Copy to clipboard action should be tailored to that HTML element.

When a message contains an image and is copied ... copy the image itself. We can do this for messages that contain images since we don't support messages that have images + text.

I'm not a huge fan of this implementation. It would work for now, but in order to complete 2 above, we would need to detect which type of HTML element is rightClick/longPressed to open the ReportActionContextMenu. For example, if an <a> tag is rightClick/longPressed, then we know we should display "Copy URL", and copy the href. Similarly, if an <img> tag is right-clicked, we know we should display "Copy Image", and copy the image to the clipboard.

Any image input is only the image.

Relying on this would be fine, but since we have to implement a more sophisticated solution for links anyways, let's use the same solution for images. Plus then we get the added bonus that it will be easier to support images + text + links together in one message, if we ever want to do that.

roryabraham avatar Jun 09 '21 19:06 roryabraham

Okay I'm good with that. What do you think of what I proposed for links?

When a url is right-clicked/long-pressed select the text of the url. This will make it so that we only copy the URL since we already support copying only selected text. This would match the behavior I expect when using a typical web page and right clicking a URL.

puneetlath avatar Jun 13 '21 23:06 puneetlath

Hmmm I'm not sure I completely understand that proposal.

we already support copying only selected text

Is this true on mobile? I don't think so...

roryabraham avatar Jun 14 '21 17:06 roryabraham

Any new proposals here? @puneetlath Should we increase the offer for this ticket?

roryabraham avatar Jun 23 '21 20:06 roryabraham

@Drewfergusson Would you be interested in working on the portion of this that targets links/URLs? If you can build a general solution to tailor the content of our custom context menu based on the html tag that was interacted with to open the menu, I think that would be a really valuable first step. I think that you're correct that the solution will involve the RenderHTML file.

Then we could move on to a follow-up that focuses on the ability to copy images, and more-or-less copies your solution used to target links in the context menu.

roryabraham avatar Jun 29 '21 16:06 roryabraham

@roryabraham sounds like a plan. I just submitted a proposal on Upwork. Also if you make a separate ticket for creating an image to the clipboard solution link it and I'd like to take a look at it too.

Drewfergusson avatar Jun 29 '21 22:06 Drewfergusson

PROPOSAL

We get the source of the image OR URL from HTML at this point and copy it to the clipboard instead of the HTML https://github.com/Expensify/Expensify.cash/blob/c5552954fd4ebcef0874edc10feaa80456f1de35/src/pages/home/report/ReportActionContextMenu.js#L88-L90

and also show appropriate text in case of the image OR URL at this point https://github.com/Expensify/Expensify.cash/blob/c5552954fd4ebcef0874edc10feaa80456f1de35/src/pages/home/report/ReportActionContextMenu.js#L70

Thanks

I used this package https://www.npmjs.com/package/html-react-parser to parse HTML and HERE is output in case of IMAGE

image

and I think we can use image/URL preview when we have URL in the message as you can see this approach used in slack or another social platform by pasting some URL.

aliabbasmalik8 avatar Jun 30 '21 12:06 aliabbasmalik8