Skip to content

Commit

Permalink
Merge pull request #8195 from mateusbra/copyEmailUrl
Browse files Browse the repository at this point in the history
Copy email url
  • Loading branch information
marcochavezf authored Mar 23, 2022
2 parents 116398b + 6018858 commit 9beba91
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'underscore';
import React from 'react';
import {Pressable, StyleSheet} from 'react-native';
import lodashGet from 'lodash/get';
import Str from 'expensify-common/lib/str';
import Text from '../../Text';
import {propTypes, defaultProps} from '../anchorForCommentsOnlyPropTypes';
import PressableWithSecondaryInteraction from '../../PressableWithSecondaryInteraction';
Expand Down Expand Up @@ -44,12 +45,12 @@ class BaseAnchorForCommentsOnly extends React.Component {
if (this.state.isDownloading) {
return;
}
this.processDownload(this.props.href, this.props.fileName);
this.processDownload(this.props.href, this.props.displayName);
}}
>
<AttachmentView
sourceURL={this.props.href}
file={{name: this.props.fileName}}
file={{name: this.props.displayName}}
shouldShowDownloadIcon
shouldShowLoadingSpinnerIcon={this.state.isDownloading}
/>
Expand All @@ -61,7 +62,7 @@ class BaseAnchorForCommentsOnly extends React.Component {
onSecondaryInteraction={
(event) => {
ReportActionContextMenu.showContextMenu(
ContextMenuActions.CONTEXT_MENU_TYPES.LINK,
Str.isValidEmail(this.props.displayName) ? ContextMenuActions.CONTEXT_MENU_TYPES.EMAIL : ContextMenuActions.CONTEXT_MENU_TYPES.LINK,
event,
this.props.href,
lodashGet(linkRef, 'current'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'underscore';
import React from 'react';
import lodashGet from 'lodash/get';
import {Linking, StyleSheet, Pressable} from 'react-native';
import Str from 'expensify-common/lib/str';
import {propTypes, defaultProps} from '../anchorForCommentsOnlyPropTypes';
import fileDownload from '../../../libs/fileDownload';
import Text from '../../Text';
Expand Down Expand Up @@ -47,12 +48,12 @@ class BaseAnchorForCommentsOnly extends React.Component {
if (this.state.isDownloading) {
return;
}
this.processDownload(this.props.href, this.props.fileName);
this.processDownload(this.props.href, this.props.displayName);
}}
>
<AttachmentView
sourceURL={this.props.href}
file={{name: this.props.fileName}}
file={{name: this.props.displayName}}
shouldShowDownloadIcon
shouldShowLoadingSpinnerIcon={this.state.isDownloading}
/>
Expand All @@ -64,7 +65,7 @@ class BaseAnchorForCommentsOnly extends React.Component {
onSecondaryInteraction={
(event) => {
ReportActionContextMenu.showContextMenu(
ContextMenuActions.CONTEXT_MENU_TYPES.LINK,
Str.isValidEmail(this.props.displayName) ? ContextMenuActions.CONTEXT_MENU_TYPES.EMAIL : ContextMenuActions.CONTEXT_MENU_TYPES.LINK,
event,
this.props.href,
lodashGet(linkRef, 'current'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const propTypes = {
/** Any children to display */
children: PropTypes.node,

/** Display label in case of attachments */
fileName: PropTypes.string,
/** Filename in case of attachments, anchor text in case of URLs or emails. */
displayName: PropTypes.string,

/** Any additional styles to apply */
// eslint-disable-next-line react/forbid-prop-types
Expand All @@ -37,7 +37,7 @@ const defaultProps = {
isAttachment: false,
children: null,
style: {},
fileName: '',
displayName: '',
};

export {propTypes, defaultProps};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AnchorRenderer = (props) => {

// An auth token is needed to download Expensify chat attachments
const isAttachment = Boolean(htmlAttribs['data-expensify-source']);
const fileName = lodashGet(props.tnode, 'domNode.children[0].data', '');
const displayName = lodashGet(props.tnode, 'domNode.children[0].data', '');
const parentStyle = lodashGet(props.tnode, 'parent.styles.nativeTextRet', {});
const attrHref = htmlAttribs.href || '';
const internalExpensifyPath = (attrHref.startsWith(CONST.NEW_EXPENSIFY_URL) && attrHref.replace(CONST.NEW_EXPENSIFY_URL, ''))
Expand Down Expand Up @@ -64,7 +64,7 @@ const AnchorRenderer = (props) => {
rel={htmlAttribs.rel || 'noopener noreferrer'}
style={{...props.style, ...parentStyle}}
key={props.key}
fileName={fileName}
displayName={displayName}
>
<TNodeChildrenRenderer tnode={props.tnode} />
</AnchorForCommentsOnly>
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export default {
copied: 'Copied!',
copyLink: 'Copy link',
copyURLToClipboard: 'Copy URL to clipboard',
copyEmailToClipboard: 'Copy email to clipboard',
markAsUnread: 'Mark as unread',
editComment: 'Edit comment',
deleteComment: 'Delete comment',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export default {
copied: '¡Copiado!',
copyLink: 'Copiar enlace',
copyURLToClipboard: 'Copiar URL al portapapeles',
copyEmailToClipboard: 'Copiar email al portapapeles',
markAsUnread: 'Marcar como no leído',
editComment: 'Editar commentario',
deleteComment: 'Eliminar comentario',
Expand Down
12 changes: 12 additions & 0 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function getActionText(reportAction) {
const CONTEXT_MENU_TYPES = {
LINK: 'LINK',
REPORT_ACTION: 'REPORT_ACTION',
EMAIL: 'EMAIL',
};

// A list of all the context actions in this menu.
Expand All @@ -37,6 +38,17 @@ export default [
hideContextMenu(true, ReportActionComposeFocusManager.focus);
},
},
{
textTranslateKey: 'reportActionContextMenu.copyEmailToClipboard',
icon: Expensicons.Clipboard,
successTextTranslateKey: 'reportActionContextMenu.copied',
successIcon: Expensicons.Checkmark,
shouldShow: type => type === CONTEXT_MENU_TYPES.EMAIL,
onPress: (closePopover, {selection}) => {
Clipboard.setString(selection.replace('mailto:', ''));
hideContextMenu(true, ReportActionComposeFocusManager.focus);
},
},
{
textTranslateKey: 'reportActionContextMenu.copyToClipboard',
icon: Expensicons.Clipboard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class PopoverReportActionContextMenu extends React.Component {
/**
* Show the ReportActionContextMenu modal popover.
*
* @param {string} type - context menu type [LINK, REPORT_ACTION]
* @param {string} type - context menu type [EMAIL, LINK, REPORT_ACTION]
* @param {Object} [event] - A press event.
* @param {string} [selection] - A copy text.
* @param {Element} contextMenuAnchor - popoverAnchor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const contextMenuRef = React.createRef();
/**
* Show the ReportActionContextMenu modal popover.
*
* @param {string} type - the context menu type to display [LINK, REPORT_ACTION]
* @param {string} type - the context menu type to display [EMAIL, LINK, REPORT_ACTION]
* @param {Object} [event] - A press event.
* @param {string} [selection] - A copy text.
* @param {Element} contextMenuAnchor - popoverAnchor
Expand Down

0 comments on commit 9beba91

Please sign in to comment.