From 02f6e74e30c3f565d4d2859335d5ea9687cff028 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 11 Sep 2023 09:35:04 +0700 Subject: [PATCH] fix colon added to completed reopened task messages when copy pasting --- src/components/ReportActionItem/TaskAction.js | 24 ++------------- src/libs/getTaskReportActionMessage.js | 29 +++++++++++++++++++ .../BaseReportActionContextMenu.js | 1 + .../report/ContextMenu/ContextMenuActions.js | 6 ++-- src/pages/home/report/ReportActionItem.js | 7 +---- 5 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 src/libs/getTaskReportActionMessage.js diff --git a/src/components/ReportActionItem/TaskAction.js b/src/components/ReportActionItem/TaskAction.js index c0b60ad996db..c5d17605d331 100644 --- a/src/components/ReportActionItem/TaskAction.js +++ b/src/components/ReportActionItem/TaskAction.js @@ -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, @@ -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 ( <> - {`${taskStatusText} ${taskReportName}`} + {getTaskReportActionMessage(props.reportAction, props.translate)} ); diff --git a/src/libs/getTaskReportActionMessage.js b/src/libs/getTaskReportActionMessage.js new file mode 100644 index 000000000000..8c7d168566f6 --- /dev/null +++ b/src/libs/getTaskReportActionMessage.js @@ -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; diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index 362ce23f72ba..d87481e9e5f7 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -92,6 +92,7 @@ function BaseReportActionContextMenu(props) { close: () => setShouldKeepOpen(false), openContextMenu: () => setShouldKeepOpen(true), interceptAnonymousUser, + translate: props.translate, }; if (contextAction.renderContent) { diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index bac79e1863e5..56e02ec5a333 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -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. @@ -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) { diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 22ded971898f..2b79e464fa55 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -296,12 +296,7 @@ function ReportActionItem(props) { props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED || props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKREOPENED ) { - children = ( - - ); + children = ; } else if (ReportActionsUtils.isCreatedTaskReportAction(props.action)) { children = (