[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
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:
- Send any link (e.g. Google.com) to a chat on web.
- Right-click on the link to open the context menu.
- Check that you see 2 option,
Copy linkandCopy 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
- Add an attachement to a chat on web.
- Right-click on the link to open the context menu.
- Check that you see several options including
Copy linkandCopy 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

Expensify/Expensify Issue URL: Issue reported by: @marcaaron Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1656523285065139
Triggered auto assignment to @sketchydroide (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Oh that one is hilarious. This one feels like it can be an external
Triggered auto assignment to @Christinadobrzyn (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
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 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
also this still needs to get the Help Wanted label first.
@sketchydroide I misunderstood this issue, and sure will comment on proposal one the issue has Help Wanted label
Job created in Upwork!
Internal posting - https://www.upwork.com/ab/applicants/1542953762229493760/job-details External positing - https://www.upwork.com/jobs/~01f00611cd1ace1c01
Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (Exported)
Current assignee @sketchydroide is eligible for the Exported assigner, not assigning anyone new.
@jayeshmangwani I don't think that is what we are looking for, the
Copy linkis not the link of the url for that we haveCopy URL to clipboard.Copy linkis 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?
It seems yes, issue details are incorrect.
@Christinadobrzyn Could you please fix the steps.
- Send any link (e.g. Google.com) to a chat on web.
- Right-click on the link to open the context menu.
- Select
Copy linkoption.
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.
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
- We can obtain
reportIDfrom navigation state using already existing getReportID function and pass it toshowContextMenu
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),
);
- Getting
reportActionis a bit harder, but we don't need the whole action, only it's id (reportActionID). We pass it fromReportActionItemMessagetoReportActionItemFragment
<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}
/>
- And then in ReportActionItemFragment's render method we need to check if html is anchor (if tag is
<a>) and if it is, addreportActionIDto html (the same principle we use to adddata-expensify-preview-modal-disabledparam to images). This is not a final code, we probably will need to implementStr.isAnchormethod, but just to illustrate:
if (props.fragment.html.startsWith('<a')) {
props.fragment.html = props.fragment.html.replace('<a', `<a report-action-id=${props.reportActionID}`)
}
- Now that we've added
reportActionIDto html, we need to parse it inAnchorRendererand pass it toAnchorForCommentsOnly. InAnchorRenderer.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}
>
- And we finally can use reportActionID in
showContextMenumethod
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
Thanks @parasharrajat updated the OP with clearer details as you mentioned here: https://github.com/Expensify/App/issues/9660#issuecomment-1172698634
Discussing here https://expensify.slack.com/archives/C02NK2DQWUX/p1656925799345049
bumping convo here - https://expensify.slack.com/archives/C02NK2DQWUX/p1657128025924389?thread_ts=1656925799.345049&cid=C02NK2DQWUX
Melvin is confused?
Looking for other possible proposals that do not include HTML manipulation.
@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:
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
shouldShowfunction - The
BaseReportActionContextMenucomponent has atypeprop that's passed to theshouldShowfunction for each context action. - So if we don't want to show
Copy linkif you right-click on a link or email, then all we have to do is change this line toshouldShow: type => type === CONTEXT_MENU_TYPES.REPORT_ACTION,