-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Andrew 3313 link context menu #3931
Andrew 3313 link context menu #3931
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
Still working on testing, just creating this PR as a placeholder |
Okay, @Drewfergusson, just ping me when this is ready for review. |
Also, just FYI for the future, you can always create a draft PR if your PR is not yet ready for review. 👍 |
I have read the CLA Document and I hereby sign the CLA |
@roryabraham @puneetlath this PR is ready for review. Testing evidence is attached. |
Sorry for the delay @Drewfergusson, I was out-of-office last week and should be able to review this soon. However, it seems that there is now a merge conflict you'll need to resolve. |
To add more to the context, I think we should hold here as there is ongoing changes of refactoring the ContextMenu. #4194. |
I'm glad @parasharrajat commented because, yes I did resolve another merge conflict and I saw @parasharrajat was moving the context menu for more general use. @roryabraham, as he said, I may have to wait until he is finished. |
@Drewfergusson #4194 is merged, so feel free to resolve conflicts and start working on this again when you're ready. |
@roryabraham merge conflicts resolved and did a quick sanity test on web and iOS to ensure the features are still working. Please review when you have a chance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work so far!
src/components/AnchorForCommentsOnly/BaseAnchorForCommentsOnly/index.native.js
Outdated
Show resolved
Hide resolved
src/components/AnchorForCommentsOnly/BaseAnchorForCommentsOnly/index.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meant to hit "request changes" 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am probably late to the party but We migrated our ContextMenu code to the Singleton component. and the same should be followed here. Although changes are awesome, you are using nested ReportActionContext which is something that we have moved away from.
@roryabraham Do you think a refactor is needed? It's going to be small changes you just have to call methods from the ReportActionContextMenu to show and hide the menu.
import {Clipboard as ClipboardIcon, Checkmark} from '../Icon/Expensicons'; | ||
|
||
|
||
export default function anchorContextMenuOptions(href, translate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to add this action to ContextMenuAction and manage the list of actions on the context menu by manipulating the array on the main PopoverReportActionContextmenu
.
this action's definition will never change. Will it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the list of context actions will need to be dynamic depending on the context. So by default it will be the existing menu, but if we longPress on a link, we'll show "Copy URL to Clipboard".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So yeah I think we're on the same page here 🙃
side note: ContextMenuActions.js
should be renamed contextMenuActions.js
because it doesn't export a React component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. My idea was to use the shouldShow
flag on actions and manage the actions on the context menu. So we just need to pass the keys to actions. Something like that.
> | ||
{children} | ||
</Text> | ||
<PressableWithContextMenu contextMenuItems={anchorContextMenuOptions(href, translate)}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just Wrap this Anchor in PressableWithSecondaryInteraction
and Call the methods from ReportActionContextMenu.js
.
@Drewfergusson another concern here is performance. We recently merged a PR that elevated the existing Since this PR adds a new popover menu for each link in a chat, I'm pretty sure it will cause a substantial performance regression. To avoid this, I think we need to continue to reuse the single
|
hehe @parasharrajat I was too slow to send my last comment before you got a review in 😏 |
Actually, I was just leaving a trail for you to catch up. So eventually you had to write all that stuff. 😉. @roryabraham. |
Hey @parasharrajat, just took a look at your changes. The single context menu is a huge improvement ✨ . I will work to implement copying links by controlling this menu. The popover currently does seem tightly coupled to report actions (it requires you to pass in a reportAction object or it breaks everything). So I will have to make it function for other use cases. I will work to push a PR soon. @roryabraham |
@Drewfergusson I think you can pass the default values for extra keys. Using your logic, you can pass in the actions. in your case, Copy the link to clipboard, and Open link. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall approach looks great! It's a much simpler PR than before, which is good. Went ahead and requested a few changes with the current implementation.
src/components/AnchorForCommentsOnly/BaseAnchorForCommentsOnly/index.native.js
Outdated
Show resolved
Hide resolved
src/components/AnchorForCommentsOnly/BaseAnchorForCommentsOnly/index.native.js
Outdated
Show resolved
Hide resolved
linkRef.current, | ||
); | ||
} | ||
} | ||
onPress={() => (shouldDownloadFile ? fileDownload(href) : Linking.openURL(href))} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, It should have an action on the contextMenu as well. Open Link
which can follow what you are doing now.
Not sure if the click to open feature is yet planned. cc: @roryabraham.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roryabraham can you clarify @parasharrajat 's comment here? Doesn't seem like a bad idea to add Open Link to the context menu however in my testing a single/normal press opens the link. Not sure the exact scenario where they would get a download instead of going to the link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed this. Yeah, I don't think we really need Open Link
in the context menu, but since you've already added it we can leave it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ask in #expensify-open-source
src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js
Outdated
Show resolved
Hide resolved
@roryabraham @parasharrajat I have updated the code based on your feedback. I even went ahead and added the 'Open Link' option to the context menu as suggested by @parasharrajat. It's working on desktop and iOS simulator. If you approve the code I will add all other test evidence. Would love to get this one across the finish line :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good now. Just a few minor code style changes and lint errors that need to be resolved.
src/components/AnchorForCommentsOnly/BaseAnchorForCommentsOnly/index.js
Outdated
Show resolved
Hide resolved
src/components/AnchorForCommentsOnly/BaseAnchorForCommentsOnly/index.js
Outdated
Show resolved
Hide resolved
src/components/AnchorForCommentsOnly/BaseAnchorForCommentsOnly/index.native.js
Outdated
Show resolved
Hide resolved
src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js
Outdated
Show resolved
Hide resolved
@roryabraham changes made and testing evidence/screenshots attached. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few more things:
- We can get rid of this context action. It never shows and is useless.
- I figured out why the mini
ReportActionContextMenu
isn't displayed. Here's how to fix it (inBaseReportActionContextMenu
):
@roryabraham I removed the copy link option (as well as the associated translations and imports). I also applied your fix to the mini context menu. I confirmed it's working. Good catch, I didn't even notice that feature until you pointed it out. |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by @roryabraham in version: 1.0.85-10 🚀
|
@Drewfergusson Hello! We're only able to see the |
Hi @isagoico, we removed the |
This has been deployed to production and is now subject to a 7-day regression period. |
🚀 Deployed to production by @roryabraham in version: 1.0.86-11 🚀
|
This has been deployed to production and is now subject to a 7-day regression period. |
@@ -30,6 +30,7 @@ class PressableWithSecondaryInteraction extends Component { | |||
*/ | |||
executeSecondaryInteractionOnContextMenu(e) { | |||
const selection = window.getSelection().toString(); | |||
e.stopPropagation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, why do we need this line? It seems to be unnecessary. cc @roryabraham @parasharrajat @puneetlath @Drewfergusson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevents event bubbling when this component is nested. We do not want nested and parent component both to trigger the action.
This happens for nested links in the message. When link context menu is triggered, message context menu should not override it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roryabraham
Details
In order to enable a context menu on secondary actions (right-clicking on desktops or long-pressing on mobile), I created a reusable component called PressbaleWithContextMenu that would wrap anything that you wanted to have a context menu. I then applied this to the tags in the RenderHTML component. PressableWithContextMenu can also be used when we go to add actions to images or any other element.
I did copy a lot of functions and logic from the existing ReportActionItem. There wasn't a great way to reuse that code. Since we're now using that same popover logic in more places the logic needed to be in its own isolated component. I could have used mixins or inherited those functions but it would have created a dependency. I think as an optimization the ReportActionItems should implement the reusable PressableWithContextMenu as well.
Fixed Issues
#3313
Tests
QA Steps
Tested On
Screenshots
iOS
mobile-test.mov
Web
Mobile Web
Desktop
Android