Skip to content

Commit

Permalink
Merge pull request Expensify#12732 from jayeshmangwani/prevent_chrono…
Browse files Browse the repository at this point in the history
…s_editing
  • Loading branch information
roryabraham authored Nov 19, 2022
2 parents 1ca61d8 + 408c179 commit cd83501
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,16 @@ function getChatByParticipants(newParticipantList) {
});
}

/**
* Returns true if Chronos is one of the chat participants (1:1)
* @param {Object} report
* @returns {Boolean}
*/
function chatIncludesChronos(report) {
return report.participants
&& _.contains(report.participants, CONST.EMAIL.CHRONOS);
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -1155,4 +1165,5 @@ export {
getChatByParticipants,
getIOUReportActionMessage,
getDisplayNameForParticipant,
chatIncludesChronos,
};
18 changes: 17 additions & 1 deletion src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const propTypes = {

/** Target node which is the target of ContentMenu */
anchor: PropTypes.node,

/** Flag to check if the chat participant is Chronos */
isChronosReport: PropTypes.bool,

/** Whether the provided report is an archived room */
isArchivedRoom: PropTypes.bool,

...genericReportActionContextMenuPropTypes,
...withLocalizePropTypes,
...windowDimensionsPropTypes,
Expand All @@ -28,6 +35,8 @@ const propTypes = {
const defaultProps = {
type: CONTEXT_MENU_TYPES.REPORT_ACTION,
anchor: null,
isChronosReport: false,
isArchivedRoom: false,
...GenericReportActionContextMenuDefaultProps,
};
class BaseReportActionContextMenu extends React.Component {
Expand All @@ -37,7 +46,14 @@ class BaseReportActionContextMenu extends React.Component {
}

render() {
const shouldShowFilter = contextAction => contextAction.shouldShow(this.props.type, this.props.reportAction, this.props.isArchivedRoom, this.props.betas, this.props.anchor);
const shouldShowFilter = contextAction => contextAction.shouldShow(
this.props.type,
this.props.reportAction,
this.props.isArchivedRoom,
this.props.betas,
this.props.anchor,
this.props.isChronosReport,
);

return this.props.isVisible && (
<View style={this.wrapperStyle}>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ export default [
{
textTranslateKey: 'reportActionContextMenu.editComment',
icon: Expensicons.Pencil,
shouldShow: (type, reportAction, isArchivedRoom) => (
type === CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && !isArchivedRoom
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport) => (
type === CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && !isArchivedRoom && !isChronosReport
),
onPress: (closePopover, {reportID, reportAction, draftMessage}) => {
const editAction = () => Report.saveReportActionDraft(
Expand All @@ -187,8 +187,8 @@ export default [
{
textTranslateKey: 'reportActionContextMenu.deleteComment',
icon: Expensicons.Trashcan,
shouldShow: (type, reportAction, isArchivedRoom) => type === CONTEXT_MENU_TYPES.REPORT_ACTION
&& ReportUtils.canDeleteReportAction(reportAction) && !isArchivedRoom,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport) => type === CONTEXT_MENU_TYPES.REPORT_ACTION
&& ReportUtils.canDeleteReportAction(reportAction) && !isArchivedRoom && !isChronosReport,
onPress: (closePopover, {reportID, reportAction}) => {
if (closePopover) {
// Hide popover, then call showDeleteConfirmModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ import {
Dimensions,
} from 'react-native';
import _ from 'underscore';
import PropTypes from 'prop-types';
import * as Report from '../../../../libs/actions/Report';
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize';
import PopoverWithMeasuredContent from '../../../../components/PopoverWithMeasuredContent';
import BaseReportActionContextMenu from './BaseReportActionContextMenu';
import ConfirmModal from '../../../../components/ConfirmModal';

const propTypes = {
/** Flag to check if the chat participant is Chronos */
isChronosReport: PropTypes.bool,

/** Whether the provided report is an archived room */
isArchivedRoom: PropTypes.bool,

...withLocalizePropTypes,
};

const defaultProps = {
isChronosReport: false,
isArchivedRoom: false,
};

class PopoverReportActionContextMenu extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -222,6 +234,7 @@ class PopoverReportActionContextMenu extends React.Component {
reportID={this.state.reportID}
reportAction={this.state.reportAction}
isArchivedRoom={this.props.isArchivedRoom}
isChronosReport={this.props.isChronosReport}
anchor={this.contextMenuTargetNode}
/>
);
Expand Down Expand Up @@ -295,6 +308,7 @@ class PopoverReportActionContextMenu extends React.Component {
reportAction={this.state.reportAction}
draftMessage={this.state.reportActionDraftMessage}
isArchivedRoom={this.props.isArchivedRoom}
isChronosReport={this.props.isChronosReport}
anchor={this.contextMenuTargetNode}
/>
</PopoverWithMeasuredContent>
Expand All @@ -316,5 +330,6 @@ class PopoverReportActionContextMenu extends React.Component {
}

PopoverReportActionContextMenu.propTypes = propTypes;
PopoverReportActionContextMenu.defaultProps = defaultProps;

export default withLocalize(PopoverReportActionContextMenu);
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ class ReportActionCompose extends React.Component {
this.submitForm();
}

// Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty
if (e.key === 'ArrowUp' && this.textInput.selectionStart === 0 && this.state.isCommentEmpty) {
// Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants
if (e.key === 'ArrowUp' && this.textInput.selectionStart === 0 && this.state.isCommentEmpty && !ReportUtils.chatIncludesChronos(this.props.report)) {
e.preventDefault();

const reportActionKey = _.find(
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class ReportActionItem extends Component {
&& !this.props.draftMessage
}
draftMessage={this.props.draftMessage}
isChronosReport={ReportUtils.chatIncludesChronos(this.props.report)}
/>
</View>
)}
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class ReportActionsView extends React.Component {
<PopoverReportActionContextMenu
ref={ReportActionContextMenu.contextMenuRef}
isArchivedRoom={ReportUtils.isArchivedRoom(this.props.report)}
isChronosReport={ReportUtils.chatIncludesChronos(this.props.report)}
/>
</>
)}
Expand Down

0 comments on commit cd83501

Please sign in to comment.