-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ea5d71
commit df3c6e9
Showing
9 changed files
with
249 additions
and
208 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import getReportActionContextMenuStyles from '../../../../styles/getReportActionContextMenuStyles'; | ||
import ContextMenuItem from '../../../../components/ContextMenuItem'; | ||
import {propTypes, defaultProps} from './ReportActionContextMenuPropsTypes'; | ||
import withLocalize from '../../../../components/withLocalize'; | ||
import ContextMenuActions from './ContextMenuActions'; | ||
|
||
class BaseReportActionContextMenu extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.wrapperStyle = getReportActionContextMenuStyles(this.props.isMini); | ||
} | ||
|
||
render() { | ||
return this.props.isVisible && ( | ||
<View style={this.wrapperStyle}> | ||
{ContextMenuActions.map(contextAction => contextAction.shouldShow(this.props.reportAction) && ( | ||
<ContextMenuItem | ||
icon={contextAction.icon} | ||
text={this.props.translate(contextAction.textTranslateKey)} | ||
successIcon={contextAction.successIcon} | ||
successText={contextAction.successTextTranslateKey | ||
? this.props.translate(contextAction.successTextTranslateKey) | ||
: undefined} | ||
isMini={this.props.isMini} | ||
key={contextAction.textTranslateKey} | ||
onPress={() => contextAction.onPress(!this.props.isMini, { | ||
reportAction: this.props.reportAction, | ||
reportID: this.props.reportID, | ||
draftMessage: this.props.draftMessage, | ||
selection: this.props.selection, | ||
})} | ||
/> | ||
))} | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
BaseReportActionContextMenu.propTypes = propTypes; | ||
BaseReportActionContextMenu.defaultProps = defaultProps; | ||
|
||
export default withLocalize(BaseReportActionContextMenu); |
116 changes: 116 additions & 0 deletions
116
src/pages/home/report/ContextMenu/ContextMenuActions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import _ from 'underscore'; | ||
import lodashGet from 'lodash/get'; | ||
import Str from 'expensify-common/lib/str'; | ||
import { | ||
Clipboard as ClipboardIcon, LinkCopy, Mail, Pencil, Trashcan, Checkmark, | ||
} from '../../../../components/Icon/Expensicons'; | ||
import { | ||
setNewMarkerPosition, updateLastReadActionID, saveReportActionDraft, | ||
} from '../../../../libs/actions/Report'; | ||
import Clipboard from '../../../../libs/Clipboard'; | ||
import {isReportMessageAttachment, canEditReportAction, canDeleteReportAction} from '../../../../libs/reportUtils'; | ||
import ReportActionComposeFocusManager from '../../../../libs/ReportActionComposeFocusManager'; | ||
import {hideContextMenu, showDeleteConfirmModal} from './ReportActionContextMenu'; | ||
|
||
/** | ||
* Gets the markdown version of the message in an action. | ||
* @param {Object} reportAction | ||
* @return {String} | ||
*/ | ||
function getActionText(reportAction) { | ||
const message = _.last(lodashGet(reportAction, 'message', null)); | ||
return lodashGet(message, 'html', ''); | ||
} | ||
|
||
// A list of all the context actions in this menu. | ||
export default [ | ||
// Copy to clipboard | ||
{ | ||
textTranslateKey: 'contextMenuItem.copyToClipboard', | ||
icon: ClipboardIcon, | ||
successTextTranslateKey: 'contextMenuItem.copied', | ||
successIcon: Checkmark, | ||
shouldShow: () => true, | ||
|
||
// If return value is true, we switch the `text` and `icon` on | ||
// `ContextMenuItem` with `successText` and `successIcon` which will fallback to | ||
// the `text` and `icon` | ||
onPress: (closePopover, {reportAction, selection}) => { | ||
const message = _.last(lodashGet(reportAction, 'message', null)); | ||
const html = lodashGet(message, 'html', ''); | ||
const text = Str.htmlDecode(selection || lodashGet(message, 'text', '')); | ||
const isAttachment = _.has(reportAction, 'isAttachment') | ||
? reportAction.isAttachment | ||
: isReportMessageAttachment(text); | ||
if (!isAttachment) { | ||
Clipboard.setString(text); | ||
} else { | ||
Clipboard.setString(html); | ||
} | ||
if (closePopover) { | ||
hideContextMenu(true, ReportActionComposeFocusManager.focus); | ||
} | ||
}, | ||
}, | ||
|
||
{ | ||
textTranslateKey: 'reportActionContextMenu.copyLink', | ||
icon: LinkCopy, | ||
shouldShow: () => false, | ||
onPress: () => {}, | ||
}, | ||
|
||
{ | ||
textTranslateKey: 'reportActionContextMenu.markAsUnread', | ||
icon: Mail, | ||
successIcon: Checkmark, | ||
shouldShow: () => true, | ||
onPress: (closePopover, {reportAction, reportID}) => { | ||
updateLastReadActionID(reportID, reportAction.sequenceNumber); | ||
setNewMarkerPosition(reportID, reportAction.sequenceNumber); | ||
if (closePopover) { | ||
hideContextMenu(true, ReportActionComposeFocusManager.focus); | ||
} | ||
}, | ||
}, | ||
|
||
{ | ||
textTranslateKey: 'reportActionContextMenu.editComment', | ||
icon: Pencil, | ||
shouldShow: reportAction => canEditReportAction(reportAction), | ||
onPress: (closePopover, {reportID, reportAction, draftMessage}) => { | ||
const editAction = () => saveReportActionDraft( | ||
reportID, | ||
reportAction.reportActionID, | ||
_.isEmpty(draftMessage) ? getActionText(reportAction) : '', | ||
); | ||
|
||
if (closePopover) { | ||
// Hide popover, then call editAction | ||
hideContextMenu(false, editAction); | ||
return; | ||
} | ||
|
||
// No popover to hide, call editAction immediately | ||
editAction(); | ||
}, | ||
}, | ||
{ | ||
textTranslateKey: 'reportActionContextMenu.deleteComment', | ||
icon: Trashcan, | ||
shouldShow: reportAction => canDeleteReportAction(reportAction), | ||
onPress: (closePopover, {reportID, reportAction}) => { | ||
if (closePopover) { | ||
// Hide popover, then call showDeleteConfirmModal | ||
hideContextMenu( | ||
false, | ||
() => showDeleteConfirmModal(reportID, reportAction), | ||
); | ||
return; | ||
} | ||
|
||
// No popover to hide, call showDeleteConfirmModal immediately | ||
showDeleteConfirmModal(reportID, reportAction); | ||
}, | ||
}, | ||
]; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.