Skip to content
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

added isChronosReport prop to prevent edit and delete action for Chro… #12732

Merged
merged 3 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,16 @@ function getChatByParticipants(newParticipantList) {
});
}

/**
* Returns true if Chronos is one of the chat participants (1:1)
* @param {Object} report
* @returns {Boolean}
*/
function chatIncludesChronos(report) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB but I think a better name would be doesChatIncludeChronos because that makes it a touch more clear that this returns a boolean.

return report.participants
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB code style – no need for a line break here:

    return report.participants && _.contains(report.participants, CONST.EMAIL.CHRONOS);

&& _.contains(report.participants, CONST.EMAIL.CHRONOS);
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -1121,4 +1131,5 @@ export {
getChatByParticipants,
getIOUReportActionMessage,
getDisplayNameForParticipant,
chatIncludesChronos,
};
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you please add isChronosReport and isArchivedRoom in propTypes and defaultProps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobitneupane Added , Thanks

);

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 @@ -224,6 +236,7 @@ class PopoverReportActionContextMenu extends React.Component {
reportID={this.state.reportID}
reportAction={this.state.reportAction}
isArchivedRoom={this.props.isArchivedRoom}
isChronosReport={this.props.isChronosReport}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you please add isChronosReport and isArchivedRoom in propTypes and defaultProps?

anchor={this.contextMenuTargetNode}
/>
);
Expand Down Expand Up @@ -297,6 +310,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 @@ -318,5 +332,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 @@ -425,8 +425,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 @@ -223,6 +223,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