From 9ec59c133c85024a171a8c70ce337b55c271c6d6 Mon Sep 17 00:00:00 2001 From: Harshdeep Joshi <88710727+Harshdeepjoshi@users.noreply.github.com> Date: Mon, 18 Jul 2022 19:46:23 +0530 Subject: [PATCH 1/5] Update ContextMenuActions.js --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 575e2ff1686d..3dc6d72cb6ee 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -89,7 +89,7 @@ export default [ successIcon: Expensicons.Checkmark, shouldShow: (type, reportAction) => (type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU - && !ReportUtils.isReportMessageAttachment(lodashGet(reportAction, ['message', 0, 'text'], ''))), + && !ReportUtils.isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {}))), // If return value is true, we switch the `text` and `icon` on // `ContextMenuItem` with `successText` and `successIcon` which will fallback to @@ -121,7 +121,7 @@ export default [ { textTranslateKey: 'reportActionContextMenu.copyLink', icon: Expensicons.LinkCopy, - shouldShow: () => true, + shouldShow: (type, reportAction) => type === CONTEXT_MENU_TYPES.REPORT_ACTION && !ReportUtils.isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {})), onPress: (closePopover, {reportAction, reportID}) => { Environment.getEnvironmentURL() .then((environmentURL) => { From dd516419c2733e910338c0e823bc581f5b7dc8bd Mon Sep 17 00:00:00 2001 From: Harshdeep Joshi <88710727+Harshdeepjoshi@users.noreply.github.com> Date: Tue, 26 Jul 2022 03:40:00 +0530 Subject: [PATCH 2/5] Disable Copy link context menu for attachment suggestion 1 Co-authored-by: Rajat Parashar --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 3dc6d72cb6ee..0110b4f8ebf6 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -89,7 +89,7 @@ export default [ successIcon: Expensicons.Checkmark, shouldShow: (type, reportAction) => (type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU - && !ReportUtils.isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {}))), + && !ReportUtils.isReportMessageAttachment(_.last(lodashGet(reportAction, ['message'], [{}])))), // If return value is true, we switch the `text` and `icon` on // `ContextMenuItem` with `successText` and `successIcon` which will fallback to From 93f10a2848dbe3289e023540e790cb17cbee952f Mon Sep 17 00:00:00 2001 From: Harshdeep Joshi <88710727+Harshdeepjoshi@users.noreply.github.com> Date: Tue, 26 Jul 2022 03:40:33 +0530 Subject: [PATCH 3/5] Disable Copy link context menu for attachments and url suggestion 2 Co-authored-by: Rajat Parashar --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 0110b4f8ebf6..875b0dc776d2 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -121,7 +121,7 @@ export default [ { textTranslateKey: 'reportActionContextMenu.copyLink', icon: Expensicons.LinkCopy, - shouldShow: (type, reportAction) => type === CONTEXT_MENU_TYPES.REPORT_ACTION && !ReportUtils.isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {})), + shouldShow: (type, reportAction) => type === CONTEXT_MENU_TYPES.REPORT_ACTION && !ReportUtils.isReportMessageAttachment(_.last(lodashGet(reportAction, ['message'], [{}]))), onPress: (closePopover, {reportAction, reportID}) => { Environment.getEnvironmentURL() .then((environmentURL) => { From ebb51ffdcad59822cbf2c875326e9e6e455249da Mon Sep 17 00:00:00 2001 From: Harshdeepjoshi Date: Wed, 3 Aug 2022 02:08:25 +0530 Subject: [PATCH 4/5] disable copy link only on image target. --- .../home/report/ContextMenu/BaseReportActionContextMenu.js | 6 +++++- src/pages/home/report/ContextMenu/ContextMenuActions.js | 7 ++++++- .../report/ContextMenu/PopoverReportActionContextMenu.js | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index ea0b478aaf63..fb3488c60964 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -16,6 +16,9 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../../../compo const propTypes = { /** String representing the context menu type [LINK, REPORT_ACTION] which controls context menu choices */ type: PropTypes.string, + + /** Target node which is the target of ContentMenu */ + anchor: PropTypes.node, ...genericReportActionContextMenuPropTypes, ...withLocalizePropTypes, ...windowDimensionsPropTypes, @@ -23,6 +26,7 @@ const propTypes = { const defaultProps = { type: CONTEXT_MENU_TYPES.REPORT_ACTION, + anchor: null, ...GenericReportActionContextMenuDefaultProps, }; class BaseReportActionContextMenu extends React.Component { @@ -32,7 +36,7 @@ class BaseReportActionContextMenu extends React.Component { } render() { - const shouldShowFilter = contextAction => contextAction.shouldShow(this.props.type, this.props.reportAction); + const shouldShowFilter = contextAction => contextAction.shouldShow(this.props.type, this.props.reportAction, this.props.anchor); return this.props.isVisible && ( diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 875b0dc776d2..aa6e9f800dbe 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -121,7 +121,11 @@ export default [ { textTranslateKey: 'reportActionContextMenu.copyLink', icon: Expensicons.LinkCopy, - shouldShow: (type, reportAction) => type === CONTEXT_MENU_TYPES.REPORT_ACTION && !ReportUtils.isReportMessageAttachment(_.last(lodashGet(reportAction, ['message'], [{}]))), + shouldShow: (type, reportAction, menuTarget) => { + const isAttachment = ReportUtils.isReportMessageAttachment(_.last(lodashGet(reportAction, ['message'], [{}]))); + const isAttachmentTarget = lodashGet(menuTarget, 'tagName') === 'IMG' && isAttachment; + return type === CONTEXT_MENU_TYPES.REPORT_ACTION && !isAttachmentTarget; + }, onPress: (closePopover, {reportAction, reportID}) => { Environment.getEnvironmentURL() .then((environmentURL) => { @@ -140,6 +144,7 @@ export default [ shouldShow: type => type === CONTEXT_MENU_TYPES.REPORT_ACTION, onPress: (closePopover, {reportAction, reportID}) => { Report.markCommentAsUnread(reportID, reportAction.sequenceNumber); + Report.setNewMarkerPosition(reportID, reportAction.sequenceNumber); if (closePopover) { hideContextMenu(true, ReportActionComposeFocusManager.focus); } diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js index b77599ad9bea..e75d5d908bcb 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js @@ -124,6 +124,7 @@ class PopoverReportActionContextMenu extends React.Component { ) { const nativeEvent = event.nativeEvent || {}; this.contextMenuAnchor = contextMenuAnchor; + this.contextMenuTargetNode = nativeEvent.target; // Singleton behaviour of ContextMenu creates race conditions when user requests multiple contextMenus. // But it is possible that every new request registers new callbacks thus instanceID is used to corelate those callbacks @@ -222,6 +223,7 @@ class PopoverReportActionContextMenu extends React.Component { selection={this.state.selection} reportID={this.state.reportID} reportAction={this.state.reportAction} + anchor={this.contextMenuTargetNode} /> ); } @@ -293,6 +295,7 @@ class PopoverReportActionContextMenu extends React.Component { reportID={this.state.reportID} reportAction={this.state.reportAction} draftMessage={this.state.reportActionDraftMessage} + anchor={this.contextMenuTargetNode} /> Date: Wed, 3 Aug 2022 15:29:57 +0530 Subject: [PATCH 5/5] Coments added and remove extra code --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 9a545752be3b..29c43e37bcd5 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -127,6 +127,8 @@ export default [ icon: Expensicons.LinkCopy, shouldShow: (type, reportAction, betas, menuTarget) => { const isAttachment = ReportUtils.isReportMessageAttachment(_.last(lodashGet(reportAction, ['message'], [{}]))); + + // Only hide the copylink menu item when context menu is opened over img element. const isAttachmentTarget = lodashGet(menuTarget, 'tagName') === 'IMG' && isAttachment; return Permissions.canUseCommentLinking(betas) && type === CONTEXT_MENU_TYPES.REPORT_ACTION && !isAttachmentTarget; }, @@ -148,7 +150,6 @@ export default [ shouldShow: type => type === CONTEXT_MENU_TYPES.REPORT_ACTION, onPress: (closePopover, {reportAction, reportID}) => { Report.markCommentAsUnread(reportID, reportAction.sequenceNumber); - Report.setNewMarkerPosition(reportID, reportAction.sequenceNumber); if (closePopover) { hideContextMenu(true, ReportActionComposeFocusManager.focus); }