Skip to content

Commit

Permalink
fix colon added to completed reopened task messages when copy pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanDylann committed Sep 11, 2023
1 parent 1810c8e commit 02f6e74
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
24 changes: 2 additions & 22 deletions src/components/ReportActionItem/TaskAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import Text from '../Text';
import styles from '../../styles/styles';
import CONST from '../../CONST';
import getTaskReportActionMessage from '../../libs/getTaskReportActionMessage';

const propTypes = {
/** Name of the reportAction action */
actionName: PropTypes.string.isRequired,

/** The ID of the associated taskReport */
// eslint-disable-next-line react/no-unused-prop-types -- This is used in the withOnyx HOC
taskReportID: PropTypes.string.isRequired,
Expand All @@ -36,27 +33,10 @@ const defaultProps = {
taskReport: {},
};
function TaskAction(props) {
const taskReportName = props.taskReport.reportName || '';

let taskStatusText = '';
switch (props.actionName) {
case CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED:
taskStatusText = props.translate('task.messages.completed');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED:
taskStatusText = props.translate('task.messages.canceled');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKREOPENED:
taskStatusText = props.translate('task.messages.reopened');
break;
default:
taskStatusText = props.translate('task.task');
}

return (
<>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{`${taskStatusText} ${taskReportName}`}</Text>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{getTaskReportActionMessage(props.reportAction, props.translate)}</Text>
</View>
</>
);
Expand Down
29 changes: 29 additions & 0 deletions src/libs/getTaskReportActionMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import CONST from '../CONST';
import * as ReportUtils from './ReportUtils';
/**
* @param {Object} reportAction
* @param {Function} translate
* @returns {string}
*/
function getTaskReportActionMessage(reportAction, translate) {
const taskReport = ReportUtils.getReport(reportAction.originalMessage.taskReportID.toString());
const taskReportName = taskReport.reportName || '';

let taskStatusText = '';
switch (reportAction.actionName) {
case CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED:
taskStatusText = translate('task.messages.completed');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED:
taskStatusText = translate('task.messages.canceled');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKREOPENED:
taskStatusText = translate('task.messages.reopened');
break;
default:
taskStatusText = translate('task.task');
}
return `${taskStatusText} ${taskReportName}`;
}

export default getTaskReportActionMessage;
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function BaseReportActionContextMenu(props) {
close: () => setShouldKeepOpen(false),
openContextMenu: () => setShouldKeepOpen(true),
interceptAnonymousUser,
translate: props.translate,
};

if (contextAction.renderContent) {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import QuickEmojiReactions from '../../../../components/Reactions/QuickEmojiReac
import MiniQuickEmojiReactions from '../../../../components/Reactions/MiniQuickEmojiReactions';
import Navigation from '../../../../libs/Navigation/Navigation';
import ROUTES from '../../../../ROUTES';
import getTaskReportActionMessage from '../../../../libs/getTaskReportActionMessage';

/**
* Gets the HTML version of the message in an action.
Expand Down Expand Up @@ -182,12 +183,11 @@ export default [
// 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}) => {
onPress: (closePopover, {reportAction, selection, translate}) => {
const isTaskAction = ReportActionsUtils.isTaskAction(reportAction);
const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction);
const message = _.last(lodashGet(reportAction, 'message', [{}]));
const originalMessage = _.get(reportAction, 'originalMessage', {});
const messageHtml = isTaskAction ? lodashGet(originalMessage, 'html', '') : lodashGet(message, 'html', '');
const messageHtml = isTaskAction ? getTaskReportActionMessage(reportAction, translate) : lodashGet(message, 'html', '');

const isAttachment = _.has(reportAction, 'isAttachment') ? reportAction.isAttachment : ReportUtils.isReportMessageAttachment(message);
if (!isAttachment) {
Expand Down
7 changes: 1 addition & 6 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,7 @@ function ReportActionItem(props) {
props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED ||
props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKREOPENED
) {
children = (
<TaskAction
taskReportID={props.action.originalMessage.taskReportID.toString()}
actionName={props.action.actionName}
/>
);
children = <TaskAction reportAction={props.action} />;
} else if (ReportActionsUtils.isCreatedTaskReportAction(props.action)) {
children = (
<TaskPreview
Expand Down

0 comments on commit 02f6e74

Please sign in to comment.