App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2022-08-30] [$250] Right clicking and “Copy Link” on a link produced https://new.expensify.com//r/0/NaN when pasted

Open mvtglobally opened this issue 4 years ago • 51 comments

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


This Issue has been divided in 2 parts, as it evolved while it was being discusses, the solution to both the situations is similar, and it would be easier to keep them in one GH.

1st Situation

Action Performed:

  1. Send any link (e.g. Google.com) to a chat on web.
  2. Right-click on the link to open the context menu.
  3. Check that you see 2 option, Copy link and Copy URL to clipboard

Expected Result:

We should only display the Copy URL to clipboard option

Actual Result:

We show both options and it's confusing

2nd Situation

  1. Add an attachement to a chat on web.
  2. Right-click on the link to open the context menu.
  3. Check that you see several options including Copy link and Copy to clipboard

Expected Result:

We should only Download, Mark as unread, Delete comment

Actual Result:

We show all of the above option, and it's confusing

Workaround:

unknown

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.1.79-9 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: Any additional supporting documentation 2022-06-29_07-21-39 Screen Shot 2022-07-01 at 1 41 25 AM

Expensify/Expensify Issue URL: Issue reported by: @marcaaron Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1656523285065139

View all open jobs on GitHub

mvtglobally avatar Jul 01 '22 05:07 mvtglobally

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

melvin-bot[bot] avatar Jul 01 '22 05:07 melvin-bot[bot]

Oh that one is hilarious. This one feels like it can be an external

sketchydroide avatar Jul 01 '22 12:07 sketchydroide

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

melvin-bot[bot] avatar Jul 01 '22 12:07 melvin-bot[bot]

Proposal:

https://github.com/Expensify/App/blob/f19a4d94870fdc96ea032d90217a03f9f5b46674/src/pages/home/report/ContextMenu/ContextMenuActions.js#L125-L132

Here, we have to use the same onPress function as we are using for copyURLToClipboard

https://github.com/Expensify/App/blob/f19a4d94870fdc96ea032d90217a03f9f5b46674/src/pages/home/report/ContextMenu/ContextMenuActions.js#L67-L70


-        onPress: (closePopover, {reportAction, reportID}) => {
-            Environment.getEnvironmentURL()
-                .then((environmentURL) => {
-                    const reportActionID = parseInt(lodashGet(reportAction, 'reportActionID'), 10);
-                    Clipboard.setString(`${environmentURL}/r/${reportID}/${reportActionID}`);
-                });
-            hideContextMenu(true, ReportActionComposeFocusManager.focus);
-        },

+        onPress: (closePopover, {selection}) => {
+            Clipboard.setString(selection);
+            hideContextMenu(true, ReportActionComposeFocusManager.focus);
+        },

jayeshmangwani avatar Jul 01 '22 13:07 jayeshmangwani

@jayeshmangwani I don't think that is what we are looking for, the Copy link is not the link of the url for that we have Copy URL to clipboard. Copy link is a link of the chat comment itself. the entire line. Like if you want to share that post with someone else

sketchydroide avatar Jul 01 '22 14:07 sketchydroide

also this still needs to get the Help Wanted label first.

sketchydroide avatar Jul 01 '22 14:07 sketchydroide

@sketchydroide I misunderstood this issue, and sure will comment on proposal one the issue has Help Wanted label

jayeshmangwani avatar Jul 01 '22 14:07 jayeshmangwani

Job created in Upwork!

Internal posting - https://www.upwork.com/ab/applicants/1542953762229493760/job-details External positing - https://www.upwork.com/jobs/~01f00611cd1ace1c01

Christinadobrzyn avatar Jul 01 '22 19:07 Christinadobrzyn

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

melvin-bot[bot] avatar Jul 01 '22 19:07 melvin-bot[bot]

Current assignee @sketchydroide is eligible for the Exported assigner, not assigning anyone new.

melvin-bot[bot] avatar Jul 01 '22 19:07 melvin-bot[bot]

@jayeshmangwani I don't think that is what we are looking for, the Copy link is not the link of the url for that we have Copy URL to clipboard. Copy link is a link of the chat comment itself. the entire line. Like if you want to share that post with someone else

In the issue, Copy Link should return a link when pasted, and you write that it is a link to a comment. It's a contradiction! Is this an error in the description of the issue or an incomplete description?

Sans84 avatar Jul 01 '22 20:07 Sans84

It seems yes, issue details are incorrect.

@Christinadobrzyn Could you please fix the steps.

  1. Send any link (e.g. Google.com) to a chat on web.
  2. Right-click on the link to open the context menu.
  3. Select Copy link option.

Expected Result:

The copied link should be the correct link to the comment.

Actual Result:

Right-clicking on “Copy Link” on a link produced new.expensify.com//r/0/NaN when pasted.

parasharrajat avatar Jul 01 '22 20:07 parasharrajat

Proposal: The issue occurs because to generate link we need reportAction and reportID, none of which are passed to showContextMenu method in BaseAnchorForCommentsOnly. Lets fix that

  1. We can obtain reportID from navigation state using already existing getReportID function and pass it to showContextMenu
ReportActionContextMenu.showContextMenu(
    Str.isValidEmail(this.props.displayName) ? ContextMenuActions.CONTEXT_MENU_TYPES.EMAIL : ContextMenuActions.CONTEXT_MENU_TYPES.LINK,
    event,
    this.props.href,
    lodashGet(linkRef, 'current'),
+   getReportID(this.props.navigation.state),
);
  1. Getting reportAction is a bit harder, but we don't need the whole action, only it's id (reportActionID). We pass it from ReportActionItemMessage to ReportActionItemFragment
<ReportActionItemFragment
    key={`actionFragment-${props.action.sequenceNumber}-${index}`}
    fragment={fragment}
    isAttachment={props.action.isAttachment}
    attachmentInfo={props.action.attachmentInfo}
    loading={props.action.loading}
+   reportActionID={props.action.reportActionID}
/>
  1. And then in ReportActionItemFragment's render method we need to check if html is anchor (if tag is <a>) and if it is, add reportActionID to html (the same principle we use to add data-expensify-preview-modal-disabled param to images). This is not a final code, we probably will need to implement Str.isAnchor method, but just to illustrate:
  if (props.fragment.html.startsWith('<a')) {
      props.fragment.html = props.fragment.html.replace('<a', `<a report-action-id=${props.reportActionID}`)
  }
  1. Now that we've added reportActionID to html, we need to parse it in AnchorRenderer and pass it to AnchorForCommentsOnly. In AnchorRenderer.js
+ const reportActionID = htmlAttribs['report-action-id'];
return (
    <AnchorForCommentsOnly
        href={attrHref}
        isAuthTokenRequired={isAttachment}
        target={htmlAttribs.target || '_blank'}
        rel={htmlAttribs.rel || 'noopener noreferrer'}
        style={{...props.style, ...parentStyle}}
        key={props.key}
        displayName={displayName}
+       reportActionID={reportActionID}
    >
  1. And we finally can use reportActionID in showContextMenu method
ReportActionContextMenu.showContextMenu(
    Str.isValidEmail(this.props.displayName) ? ContextMenuActions.CONTEXT_MENU_TYPES.EMAIL : ContextMenuActions.CONTEXT_MENU_TYPES.LINK,
    event,
    this.props.href,
    lodashGet(linkRef, 'current'),
+   getReportID(this.props.navigation.state),
+   {reportActionID: this.props.reportActionID}
);

Result:

https://user-images.githubusercontent.com/9059945/177003781-173e61ae-895d-476f-a984-6d0409994927.mp4

eVoloshchak avatar Jul 02 '22 13:07 eVoloshchak

Thanks @parasharrajat updated the OP with clearer details as you mentioned here: https://github.com/Expensify/App/issues/9660#issuecomment-1172698634

Beamanator avatar Jul 04 '22 07:07 Beamanator

Discussing here https://expensify.slack.com/archives/C02NK2DQWUX/p1656925799345049

parasharrajat avatar Jul 04 '22 09:07 parasharrajat

bumping convo here - https://expensify.slack.com/archives/C02NK2DQWUX/p1657128025924389?thread_ts=1656925799.345049&cid=C02NK2DQWUX

Christinadobrzyn avatar Jul 06 '22 17:07 Christinadobrzyn

Melvin is confused?

sketchydroide avatar Jul 06 '22 19:07 sketchydroide

Looking for other possible proposals that do not include HTML manipulation.

parasharrajat avatar Jul 06 '22 22:07 parasharrajat

@roryabraham any thoughts? And can you advise on how we could disable the option to "Copy link" when we are right-clicking on a hyperlink?

I'm not sure where in the code we'd be able to do that (looked for a bit, but couldn't find the logic that determines why some options show and others do not). That would be an easier solution IMO as it is pretty ambiguous what is even being copied when presented with these options:

Screen Shot 2022-07-06 at 3 25 58 PM

marcaaron avatar Jul 07 '22 01:07 marcaaron

I agree that Copy link vs Copy URL to clipboard is confusing. Reading up in the slack thread, I think @marcaaron made some really good arguments for why we should just display Copy URL to clipboard if you right-click on the link, so 👍 there. I also think that the same logic should apply if you right-click an email link, which has this same bug.

And can you advise on how we could disable the option to "Copy link" when we are right-clicking on a hyperlink?

Yep!

  • all the context menu actions are defined here
  • whether or not each one shows is determined by their shouldShow function
  • The BaseReportActionContextMenu component has a type prop that's passed to the shouldShow function for each context action.
  • So if we don't want to show Copy link if you right-click on a link or email, then all we have to do is change this line to shouldShow: type => type === CONTEXT_MENU_TYPES.REPORT_ACTION,

roryabraham avatar Jul 07 '22 02:07 roryabraham