From c1c14acf5e8020ecfa995a6ca0f4b2543115cdda Mon Sep 17 00:00:00 2001 From: tienifr Date: Sat, 10 Jun 2023 15:05:07 +0700 Subject: [PATCH 01/12] fix: unmatched parent report id and report action id --- src/libs/Navigation/Navigation.js | 4 +--- src/libs/ReportUtils.js | 5 ++--- src/pages/home/report/ContextMenu/ContextMenuActions.js | 4 ++-- src/pages/home/report/ReportActionItem.js | 2 +- src/pages/home/report/ReportActionItemParentAction.js | 9 ++++++++- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index d61eb7143de0..237de4aed570 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -175,9 +175,7 @@ function getReportIDFromRoute() { return ''; } - const drawerState = lodashGet(navigationRef.current.getState(), ['routes', 0, 'state']); - const reportRoute = lodashGet(drawerState, ['routes', 0]); - return lodashGet(reportRoute, ['params', 'reportID'], ''); + return lodashGet(navigationRef.current.getCurrentRoute(), ['params', 'reportID'], ''); } /** diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0d26ff733f7d..247da8cf02f5 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -525,11 +525,10 @@ function isThreadParent(reportAction) { * Returns true if reportAction is the first chat preview of a Thread * * @param {Object} reportAction - * @param {String} reportID * @returns {Boolean} */ -function isThreadFirstChat(reportAction, reportID) { - return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === reportID; +function isThreadFirstChat(reportAction) { + return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === Navigation.getReportIDFromRoute(); } /** diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index b5c9d6412a02..1982a5a847d9 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -118,8 +118,8 @@ export default [ icon: Expensicons.ChatBubble, successTextTranslateKey: '', successIcon: null, - shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID) => - type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportUtils.isThreadFirstChat(reportAction, reportID), + shouldShow: (type, reportAction) => + type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportUtils.isThreadFirstChat(reportAction), onPress: (closePopover, {reportAction, reportID}) => { Report.navigateToAndOpenChildReport(lodashGet(reportAction, 'childReportID', '0'), reportAction, reportID); if (closePopover) { diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index e7c704fd8c8e..b1d9e5a0a690 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -320,7 +320,7 @@ function ReportActionItem(props) { const numberOfThreadReplies = _.get(props, ['action', 'childVisibleActionCount'], 0); const hasReplies = numberOfThreadReplies > 0; - const shouldDisplayThreadReplies = hasReplies && props.action.childCommenterCount && !ReportUtils.isThreadFirstChat(props.action, props.report.reportID); + const shouldDisplayThreadReplies = hasReplies && props.action.childCommenterCount && !ReportUtils.isThreadFirstChat(props.action); const oldestFourEmails = lodashGet(props.action, 'childOldestFourEmails', '').split(','); const draftMessageRightAlign = props.draftMessage ? styles.chatItemReactionsDraftRight : {}; diff --git a/src/pages/home/report/ReportActionItemParentAction.js b/src/pages/home/report/ReportActionItemParentAction.js index 9ce119494b56..c513d530e8ad 100644 --- a/src/pages/home/report/ReportActionItemParentAction.js +++ b/src/pages/home/report/ReportActionItemParentAction.js @@ -32,6 +32,9 @@ const propTypes = { /** The report currently being looked at */ report: reportPropTypes, + /** The parent report */ + parentReport: reportPropTypes, + /** The actions from the parent report */ // TO DO: Replace with HOC https://github.com/Expensify/App/issues/18769. parentReportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)), @@ -40,6 +43,7 @@ const propTypes = { }; const defaultProps = { report: {}, + parentReport: {}, parentReportActions: {}, shouldHideThreadDividerLine: false, }; @@ -62,7 +66,7 @@ const ReportActionItemParentAction = (props) => { {parentReportAction && ( `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, }, + parentReport: { + key: ({parentReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, + }, parentReportActions: { key: ({parentReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, canEvict: false, From eb64012c6c9b1d852c2c446cab2f75e3c6dd5da8 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 12 Jun 2023 16:25:47 +0700 Subject: [PATCH 02/12] fix mark unread and copy link --- .../home/report/ContextMenu/ContextMenuActions.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 1982a5a847d9..6c1b79c3052d 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -208,10 +208,11 @@ export default [ const isAttachmentTarget = lodashGet(menuTarget, 'tagName') === 'IMG' && isAttachment; return Permissions.canUseCommentLinking(betas) && type === CONTEXT_MENU_TYPES.REPORT_ACTION && !isAttachmentTarget; }, - onPress: (closePopover, {reportAction, reportID}) => { + onPress: (closePopover, {reportAction}) => { Environment.getEnvironmentURL().then((environmentURL) => { const reportActionID = parseInt(lodashGet(reportAction, 'reportActionID'), 10); - Clipboard.setString(`${environmentURL}/r/${reportID}/${reportActionID}`); + const activeReportID = Navigation.getReportIDFromRoute(); + Clipboard.setString(`${environmentURL}/r/${activeReportID}/${reportActionID}`); }); hideContextMenu(true, ReportActionComposeFocusManager.focus); }, @@ -223,8 +224,9 @@ export default [ icon: Expensicons.Mail, successIcon: Expensicons.Checkmark, shouldShow: (type) => type === CONTEXT_MENU_TYPES.REPORT_ACTION, - onPress: (closePopover, {reportAction, reportID}) => { - Report.markCommentAsUnread(reportID, reportAction.created); + onPress: (closePopover, {reportAction}) => { + const activeReportID = Navigation.getReportIDFromRoute(); + Report.markCommentAsUnread(activeReportID, reportAction.created); if (closePopover) { hideContextMenu(true, ReportActionComposeFocusManager.focus); } From d49e550617ae70a9e3733e503fd62461a4aad875 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 12 Jun 2023 17:20:17 +0700 Subject: [PATCH 03/12] get active report id --- src/libs/ReportUtils.js | 2 +- src/pages/home/report/ContextMenu/ContextMenuActions.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 247da8cf02f5..fe45a438c652 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -528,7 +528,7 @@ function isThreadParent(reportAction) { * @returns {Boolean} */ function isThreadFirstChat(reportAction) { - return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === Navigation.getReportIDFromRoute(); + return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === Navigation.getTopmostReportId(); } /** diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 6c1b79c3052d..a9fb24bdb23f 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -211,7 +211,7 @@ export default [ onPress: (closePopover, {reportAction}) => { Environment.getEnvironmentURL().then((environmentURL) => { const reportActionID = parseInt(lodashGet(reportAction, 'reportActionID'), 10); - const activeReportID = Navigation.getReportIDFromRoute(); + const activeReportID = Navigation.getTopmostReportId(); Clipboard.setString(`${environmentURL}/r/${activeReportID}/${reportActionID}`); }); hideContextMenu(true, ReportActionComposeFocusManager.focus); @@ -225,7 +225,7 @@ export default [ successIcon: Expensicons.Checkmark, shouldShow: (type) => type === CONTEXT_MENU_TYPES.REPORT_ACTION, onPress: (closePopover, {reportAction}) => { - const activeReportID = Navigation.getReportIDFromRoute(); + const activeReportID = Navigation.getTopmostReportId(); Report.markCommentAsUnread(activeReportID, reportAction.created); if (closePopover) { hideContextMenu(true, ReportActionComposeFocusManager.focus); From d993726bf95ae2ad963f454d72c6b075fe0f61a2 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 13 Jun 2023 15:52:06 +0700 Subject: [PATCH 04/12] fix rerender --- src/libs/ReportUtils.js | 5 +++-- src/pages/home/report/ReportActionItem.js | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index fe45a438c652..63760fd46fa1 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -525,10 +525,11 @@ function isThreadParent(reportAction) { * Returns true if reportAction is the first chat preview of a Thread * * @param {Object} reportAction + * @param {String} [reportID] * @returns {Boolean} */ -function isThreadFirstChat(reportAction) { - return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === Navigation.getTopmostReportId(); +function isThreadFirstChat(reportAction, reportID = '') { + return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === (reportID || Navigation.getTopmostReportId()); } /** diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index b1d9e5a0a690..b34e8e1d17ab 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -54,6 +54,7 @@ import TaskPreview from '../../../components/ReportActionItem/TaskPreview'; import TaskAction from '../../../components/ReportActionItem/TaskAction'; import * as Session from '../../../libs/actions/Session'; import {hideContextMenu} from './ContextMenu/ReportActionContextMenu'; +import withCurrentReportId from '../../../components/withCurrentReportId'; const propTypes = { ...windowDimensionsPropTypes, @@ -320,7 +321,7 @@ function ReportActionItem(props) { const numberOfThreadReplies = _.get(props, ['action', 'childVisibleActionCount'], 0); const hasReplies = numberOfThreadReplies > 0; - const shouldDisplayThreadReplies = hasReplies && props.action.childCommenterCount && !ReportUtils.isThreadFirstChat(props.action); + const shouldDisplayThreadReplies = hasReplies && props.action.childCommenterCount && !ReportUtils.isThreadFirstChat(props.action, props.currentReportId); const oldestFourEmails = lodashGet(props.action, 'childOldestFourEmails', '').split(','); const draftMessageRightAlign = props.draftMessage ? styles.chatItemReactionsDraftRight : {}; @@ -502,6 +503,7 @@ export default compose( return lodashGet(drafts, draftKey, ''); }, }), + withCurrentReportId, withOnyx({ preferredSkinTone: { key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, @@ -519,6 +521,7 @@ export default compose( _.isEqual(prevProps.action, nextProps.action) && lodashGet(prevProps.report, 'statusNum') === lodashGet(nextProps.report, 'statusNum') && lodashGet(prevProps.report, 'stateNum') === lodashGet(nextProps.report, 'stateNum') && - prevProps.translate === nextProps.translate, + prevProps.translate === nextProps.translate && + prevProps.currentReportId === nextProps.currentReportId, ), ); From 258c53b50a920c87c4a83aa847a54edc89928147 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 14 Jun 2023 12:19:36 +0700 Subject: [PATCH 05/12] revert getReportIdFromRoute --- src/libs/Navigation/Navigation.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index 237de4aed570..d61eb7143de0 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -175,7 +175,9 @@ function getReportIDFromRoute() { return ''; } - return lodashGet(navigationRef.current.getCurrentRoute(), ['params', 'reportID'], ''); + const drawerState = lodashGet(navigationRef.current.getState(), ['routes', 0, 'state']); + const reportRoute = lodashGet(drawerState, ['routes', 0]); + return lodashGet(reportRoute, ['params', 'reportID'], ''); } /** From 5b948c2b728f31c25177a846e7beef38f2e43ff2 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 15 Jun 2023 17:37:22 +0700 Subject: [PATCH 06/12] isParentReport approach --- src/components/ShowContextMenuContext.js | 4 +++- src/libs/ReportUtils.js | 7 ++++--- .../ContextMenu/BaseReportActionContextMenu.js | 2 ++ .../report/ContextMenu/ContextMenuActions.js | 12 ++++++------ .../PopoverReportActionContextMenu.js | 6 ++++++ .../ContextMenu/ReportActionContextMenu.js | 18 +++++++++++++++++- .../genericReportActionContextMenuPropTypes.js | 4 ++++ src/pages/home/report/ReportActionItem.js | 15 ++++++++++----- .../report/ReportActionItemParentAction.js | 1 + 9 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/components/ShowContextMenuContext.js b/src/components/ShowContextMenuContext.js index df522dec8f10..f7c38f74a3f2 100644 --- a/src/components/ShowContextMenuContext.js +++ b/src/components/ShowContextMenuContext.js @@ -21,8 +21,9 @@ ShowContextMenuContext.displayName = 'ShowContextMenuContext'; * @param {Object} action - ReportAction for ContextMenu * @param {Function} checkIfContextMenuActive Callback to update context menu active state * @param {Boolean} [isArchivedRoom=false] - Is the report an archived room + * @param {Boolean} [isParentReport=false] - Is the report action from parent report */ -function showContextMenuForReport(event, anchor, reportID, action, checkIfContextMenuActive, isArchivedRoom = false) { +function showContextMenuForReport(event, anchor, reportID, action, checkIfContextMenuActive, isArchivedRoom = false, isParentReport = false) { if (!DeviceCapabilities.canUseTouchScreen()) { return; } @@ -37,6 +38,7 @@ function showContextMenuForReport(event, anchor, reportID, action, checkIfContex checkIfContextMenuActive, checkIfContextMenuActive, isArchivedRoom, + isParentReport, ); } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 74c9a501db6d..e02f5882ed17 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -524,12 +524,13 @@ function isThreadParent(reportAction) { /** * Returns true if reportAction is the first chat preview of a Thread * + * @deprecated * @param {Object} reportAction - * @param {String} [reportID] + * @param {String} reportID * @returns {Boolean} */ -function isThreadFirstChat(reportAction, reportID = '') { - return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === (reportID || Navigation.getTopmostReportId()); +function isThreadFirstChat(reportAction, reportID) { + return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === reportID; } /** diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index 2d85a960f66d..4f2565b948b5 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -62,6 +62,7 @@ class BaseReportActionContextMenu extends React.Component { this.props.isChronosReport, this.props.reportID, this.props.isPinnedChat, + this.props.isParentReport, ); /** @@ -93,6 +94,7 @@ class BaseReportActionContextMenu extends React.Component { const payload = { reportAction: this.props.reportAction, reportID: this.props.reportID, + isParentReport: this.props.isParentReport, draftMessage: this.props.draftMessage, selection: this.props.selection, close: () => this.setState({shouldKeepOpen: false}), diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index a9fb24bdb23f..7d22351b196d 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -118,8 +118,8 @@ export default [ icon: Expensicons.ChatBubble, successTextTranslateKey: '', successIcon: null, - shouldShow: (type, reportAction) => - type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportUtils.isThreadFirstChat(reportAction), + shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isParentReport) => + type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !isParentReport, onPress: (closePopover, {reportAction, reportID}) => { Report.navigateToAndOpenChildReport(lodashGet(reportAction, 'childReportID', '0'), reportAction, reportID); if (closePopover) { @@ -208,10 +208,10 @@ export default [ const isAttachmentTarget = lodashGet(menuTarget, 'tagName') === 'IMG' && isAttachment; return Permissions.canUseCommentLinking(betas) && type === CONTEXT_MENU_TYPES.REPORT_ACTION && !isAttachmentTarget; }, - onPress: (closePopover, {reportAction}) => { + onPress: (closePopover, {reportID, reportAction, isParentReport}) => { Environment.getEnvironmentURL().then((environmentURL) => { const reportActionID = parseInt(lodashGet(reportAction, 'reportActionID'), 10); - const activeReportID = Navigation.getTopmostReportId(); + const activeReportID = isParentReport ? reportAction.childReportID : reportID; Clipboard.setString(`${environmentURL}/r/${activeReportID}/${reportActionID}`); }); hideContextMenu(true, ReportActionComposeFocusManager.focus); @@ -224,8 +224,8 @@ export default [ icon: Expensicons.Mail, successIcon: Expensicons.Checkmark, shouldShow: (type) => type === CONTEXT_MENU_TYPES.REPORT_ACTION, - onPress: (closePopover, {reportAction}) => { - const activeReportID = Navigation.getTopmostReportId(); + onPress: (closePopover, {reportID, reportAction, isParentReport}) => { + const activeReportID = isParentReport ? reportAction.childReportID : reportID; Report.markCommentAsUnread(activeReportID, reportAction.created); if (closePopover) { hideContextMenu(true, ReportActionComposeFocusManager.focus); diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js index 6fcaed0ca291..317afef9ced0 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js @@ -40,6 +40,7 @@ class PopoverReportActionContextMenu extends React.Component { isArchivedRoom: false, isChronosReport: false, isPinnedChat: false, + isParentReport: false, }; this.onPopoverShow = () => {}; this.onPopoverHide = () => {}; @@ -128,6 +129,7 @@ class PopoverReportActionContextMenu extends React.Component { * @param {Boolean} isArchivedRoom - Whether the provided report is an archived room * @param {Boolean} isChronosReport - Flag to check if the chat participant is Chronos * @param {Boolean} isPinnedChat - Flag to check if the chat is pinned in the LHN. Used for the Pin/Unpin action + * @param {Boolean} [isParentReport] - Is the report action from parent report */ showContextMenu( type, @@ -142,6 +144,7 @@ class PopoverReportActionContextMenu extends React.Component { isArchivedRoom = false, isChronosReport = false, isPinnedChat = false, + isParentReport = false, ) { const nativeEvent = event.nativeEvent || {}; this.contextMenuAnchor = contextMenuAnchor; @@ -173,6 +176,7 @@ class PopoverReportActionContextMenu extends React.Component { isArchivedRoom, isChronosReport, isPinnedChat, + isParentReport, }); }); } @@ -261,6 +265,7 @@ class PopoverReportActionContextMenu extends React.Component { isArchivedRoom: false, isChronosReport: false, isPinnedChat: false, + isParentReport: false, }); } @@ -308,6 +313,7 @@ class PopoverReportActionContextMenu extends React.Component { isArchivedRoom={this.state.isArchivedRoom} isChronosReport={this.state.isChronosReport} isPinnedChat={this.state.isPinnedChat} + isParentReport={this.state.isParentReport} anchor={this.contextMenuTargetNode} contentRef={this.contentRef} /> diff --git a/src/pages/home/report/ContextMenu/ReportActionContextMenu.js b/src/pages/home/report/ContextMenu/ReportActionContextMenu.js index ea68cae8c710..e1792eacd97b 100644 --- a/src/pages/home/report/ContextMenu/ReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/ReportActionContextMenu.js @@ -17,6 +17,7 @@ const contextMenuRef = React.createRef(); * @param {Boolean} isArchivedRoom - Whether the provided report is an archived room * @param {Boolean} isChronosReport - Flag to check if the chat participant is Chronos * @param {Boolean} isPinnedChat - Flag to check if the chat is pinned in the LHN. Used for the Pin/Unpin action + * @param {Boolean} [isParentReport] - Is the report action from parent report */ function showContextMenu( type, @@ -31,11 +32,26 @@ function showContextMenu( isArchivedRoom = false, isChronosReport = false, isPinnedChat = false, + isParentReport = false, ) { if (!contextMenuRef.current) { return; } - contextMenuRef.current.showContextMenu(type, event, selection, contextMenuAnchor, reportID, reportAction, draftMessage, onShow, onHide, isArchivedRoom, isChronosReport, isPinnedChat); + contextMenuRef.current.showContextMenu( + type, + event, + selection, + contextMenuAnchor, + reportID, + reportAction, + draftMessage, + onShow, + onHide, + isArchivedRoom, + isChronosReport, + isPinnedChat, + isParentReport, + ); } /** diff --git a/src/pages/home/report/ContextMenu/genericReportActionContextMenuPropTypes.js b/src/pages/home/report/ContextMenu/genericReportActionContextMenuPropTypes.js index f62873031c54..596d5bd907f2 100644 --- a/src/pages/home/report/ContextMenu/genericReportActionContextMenuPropTypes.js +++ b/src/pages/home/report/ContextMenu/genericReportActionContextMenuPropTypes.js @@ -8,6 +8,9 @@ const propTypes = { /** The report action this context menu is attached to. */ reportAction: PropTypes.shape(reportActionPropTypes).isRequired, + /** Is the report action from parent report */ + isParentReport: PropTypes.bool, + /** If true, this component will be a small, row-oriented menu that displays icons but not text. If false, this component will be a larger, column-oriented menu that displays icons alongside text in each row. */ isMini: PropTypes.bool, @@ -23,6 +26,7 @@ const propTypes = { }; const defaultProps = { + isParentReport: false, isMini: false, isVisible: false, selection: '', diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index cba855262f6a..1d6fd4143fa4 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -55,7 +55,6 @@ import TaskPreview from '../../../components/ReportActionItem/TaskPreview'; import TaskAction from '../../../components/ReportActionItem/TaskAction'; import * as Session from '../../../libs/actions/Session'; import {hideContextMenu} from './ContextMenu/ReportActionContextMenu'; -import withCurrentReportId from '../../../components/withCurrentReportId'; const propTypes = { ...windowDimensionsPropTypes, @@ -72,6 +71,9 @@ const propTypes = { /** Is this the most recent IOU Action? */ isMostRecentIOUReportAction: PropTypes.bool.isRequired, + /** Is this the action from parent report */ + isParentReport: PropTypes.bool, + /** Should we display the new marker on top of the comment? */ shouldDisplayNewMarker: PropTypes.bool.isRequired, @@ -101,6 +103,7 @@ const defaultProps = { personalDetails: {}, shouldShowSubscriptAvatar: false, hasOutstandingIOU: false, + isParentReport: false, }; function ReportActionItem(props) { @@ -180,9 +183,11 @@ function ReportActionItem(props) { toggleContextMenuFromActiveReportAction, ReportUtils.isArchivedRoom(props.report), ReportUtils.chatIncludesChronos(props.report), + null, + props.isParentReport, ); }, - [props.draftMessage, props.action, props.report, toggleContextMenuFromActiveReportAction], + [props.draftMessage, props.action, props.report, props.isParentReport, toggleContextMenuFromActiveReportAction], ); const toggleReaction = useCallback( @@ -333,7 +338,7 @@ function ReportActionItem(props) { const numberOfThreadReplies = _.get(props, ['action', 'childVisibleActionCount'], 0); const hasReplies = numberOfThreadReplies > 0; - const shouldDisplayThreadReplies = hasReplies && props.action.childCommenterCount && !ReportUtils.isThreadFirstChat(props.action, props.currentReportId); + const shouldDisplayThreadReplies = hasReplies && props.action.childCommenterCount && !props.isParentReport; const oldestFourEmails = lodashGet(props.action, 'childOldestFourEmails', '').split(','); const draftMessageRightAlign = props.draftMessage ? styles.chatItemReactionsDraftRight : {}; @@ -454,6 +459,7 @@ function ReportActionItem(props) { isVisible={hovered && !props.draftMessage && !hasErrors} draftMessage={props.draftMessage} isChronosReport={ReportUtils.chatIncludesChronos(props.report)} + isParentReport={props.isParentReport} /> {parentReportAction && ( Date: Thu, 22 Jun 2023 00:33:06 +0700 Subject: [PATCH 07/12] resolve review --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 2 +- src/pages/home/report/ReportActionItem.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 099248df1b5f..115c2ac1e8e1 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -112,7 +112,7 @@ export default [ icon: Expensicons.ChatBubble, successTextTranslateKey: '', successIcon: null, - shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isParentReport) => + shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isUnreadChat, isParentReport) => type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !isParentReport, onPress: (closePopover, {reportAction, reportID}) => { Report.navigateToAndOpenChildReport(lodashGet(reportAction, 'childReportID', '0'), reportAction, reportID); diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index c7ea21e78ba8..b96bc67bc292 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -187,7 +187,8 @@ function ReportActionItem(props) { toggleContextMenuFromActiveReportAction, ReportUtils.isArchivedRoom(props.report), ReportUtils.chatIncludesChronos(props.report), - null, + undefined, + undefined, props.isParentReport, ); }, From ca3b987f8910818b42c0a6e3c9055b7df70f4d1f Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 23 Jun 2023 11:00:36 +0700 Subject: [PATCH 08/12] revert isParentReport solution --- src/components/ShowContextMenuContext.js | 4 +--- src/libs/ReportUtils.js | 1 - .../ContextMenu/BaseReportActionContextMenu.js | 2 -- .../home/report/ContextMenu/ContextMenuActions.js | 14 ++++++-------- .../ContextMenu/PopoverReportActionContextMenu.js | 6 ------ .../report/ContextMenu/ReportActionContextMenu.js | 3 --- .../genericReportActionContextMenuPropTypes.js | 4 ---- src/pages/home/report/ReportActionItem.js | 15 +++------------ .../home/report/ReportActionItemParentAction.js | 10 +--------- 9 files changed, 11 insertions(+), 48 deletions(-) diff --git a/src/components/ShowContextMenuContext.js b/src/components/ShowContextMenuContext.js index f7c38f74a3f2..df522dec8f10 100644 --- a/src/components/ShowContextMenuContext.js +++ b/src/components/ShowContextMenuContext.js @@ -21,9 +21,8 @@ ShowContextMenuContext.displayName = 'ShowContextMenuContext'; * @param {Object} action - ReportAction for ContextMenu * @param {Function} checkIfContextMenuActive Callback to update context menu active state * @param {Boolean} [isArchivedRoom=false] - Is the report an archived room - * @param {Boolean} [isParentReport=false] - Is the report action from parent report */ -function showContextMenuForReport(event, anchor, reportID, action, checkIfContextMenuActive, isArchivedRoom = false, isParentReport = false) { +function showContextMenuForReport(event, anchor, reportID, action, checkIfContextMenuActive, isArchivedRoom = false) { if (!DeviceCapabilities.canUseTouchScreen()) { return; } @@ -38,7 +37,6 @@ function showContextMenuForReport(event, anchor, reportID, action, checkIfContex checkIfContextMenuActive, checkIfContextMenuActive, isArchivedRoom, - isParentReport, ); } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d0fb7ba1a6e1..64c52c37f2d7 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -553,7 +553,6 @@ function isThreadParent(reportAction) { /** * Returns true if reportAction is the first chat preview of a Thread * - * @deprecated * @param {Object} reportAction * @param {String} reportID * @returns {Boolean} diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index 1410867de180..0a1846cfb324 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -63,7 +63,6 @@ class BaseReportActionContextMenu extends React.Component { this.props.reportID, this.props.isPinnedChat, this.props.isUnreadChat, - this.props.isParentReport, ); /** @@ -95,7 +94,6 @@ class BaseReportActionContextMenu extends React.Component { const payload = { reportAction: this.props.reportAction, reportID: this.props.reportID, - isParentReport: this.props.isParentReport, draftMessage: this.props.draftMessage, selection: this.props.selection, close: () => this.setState({shouldKeepOpen: false}), diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 115c2ac1e8e1..9f01db925abb 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -112,8 +112,8 @@ export default [ icon: Expensicons.ChatBubble, successTextTranslateKey: '', successIcon: null, - shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isUnreadChat, isParentReport) => - type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !isParentReport, + shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID) => + type === CONTEXT_MENU_TYPES.REPORT_ACTION && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportUtils.isThreadFirstChat(reportAction, reportID), onPress: (closePopover, {reportAction, reportID}) => { Report.navigateToAndOpenChildReport(lodashGet(reportAction, 'childReportID', '0'), reportAction, reportID); if (closePopover) { @@ -203,11 +203,10 @@ export default [ const isAttachmentTarget = lodashGet(menuTarget, 'tagName') === 'IMG' && isAttachment; return Permissions.canUseCommentLinking(betas) && type === CONTEXT_MENU_TYPES.REPORT_ACTION && !isAttachmentTarget && !ReportActionUtils.isMessageDeleted(reportAction); }, - onPress: (closePopover, {reportID, reportAction, isParentReport}) => { + onPress: (closePopover, {reportAction, reportID}) => { Environment.getEnvironmentURL().then((environmentURL) => { const reportActionID = parseInt(lodashGet(reportAction, 'reportActionID'), 10); - const activeReportID = isParentReport ? reportAction.childReportID : reportID; - Clipboard.setString(`${environmentURL}/r/${activeReportID}/${reportActionID}`); + Clipboard.setString(`${environmentURL}/r/${reportID}/${reportActionID}`); }); hideContextMenu(true, ReportActionComposeFocusManager.focus); }, @@ -220,9 +219,8 @@ export default [ successIcon: Expensicons.Checkmark, shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isUnreadChat) => type === CONTEXT_MENU_TYPES.REPORT_ACTION || (type === CONTEXT_MENU_TYPES.REPORT && !isUnreadChat), - onPress: (closePopover, {reportAction, reportID, isParentReport}) => { - const activeReportID = isParentReport ? reportAction.childReportID : reportID; - Report.markCommentAsUnread(activeReportID, reportAction.created); + onPress: (closePopover, {reportAction, reportID}) => { + Report.markCommentAsUnread(reportID, reportAction.created); if (closePopover) { hideContextMenu(true, ReportActionComposeFocusManager.focus); } diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js index bce6ab1dc123..40aef91e8d45 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js @@ -41,7 +41,6 @@ class PopoverReportActionContextMenu extends React.Component { isChronosReport: false, isPinnedChat: false, isUnreadChat: false, - isParentReport: false, }; this.onPopoverShow = () => {}; this.onPopoverHide = () => {}; @@ -131,7 +130,6 @@ class PopoverReportActionContextMenu extends React.Component { * @param {Boolean} isChronosReport - Flag to check if the chat participant is Chronos * @param {Boolean} isPinnedChat - Flag to check if the chat is pinned in the LHN. Used for the Pin/Unpin action * @param {Boolean} isUnreadChat - Flag to check if the chat is unread in the LHN. Used for the Mark as Read/Unread action - * @param {Boolean} [isParentReport] - Is the report action from parent report */ showContextMenu( type, @@ -147,7 +145,6 @@ class PopoverReportActionContextMenu extends React.Component { isChronosReport = false, isPinnedChat = false, isUnreadChat = false, - isParentReport = false, ) { const nativeEvent = event.nativeEvent || {}; this.contextMenuAnchor = contextMenuAnchor; @@ -180,7 +177,6 @@ class PopoverReportActionContextMenu extends React.Component { isChronosReport, isPinnedChat, isUnreadChat, - isParentReport, }); }); } @@ -270,7 +266,6 @@ class PopoverReportActionContextMenu extends React.Component { isChronosReport: false, isPinnedChat: false, isUnreadChat: false, - isParentReport: false, }); } @@ -319,7 +314,6 @@ class PopoverReportActionContextMenu extends React.Component { isChronosReport={this.state.isChronosReport} isPinnedChat={this.state.isPinnedChat} isUnreadChat={this.state.isUnreadChat} - isParentReport={this.state.isParentReport} anchor={this.contextMenuTargetNode} contentRef={this.contentRef} /> diff --git a/src/pages/home/report/ContextMenu/ReportActionContextMenu.js b/src/pages/home/report/ContextMenu/ReportActionContextMenu.js index 1c395429c8ae..711a3be109d7 100644 --- a/src/pages/home/report/ContextMenu/ReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/ReportActionContextMenu.js @@ -18,7 +18,6 @@ const contextMenuRef = React.createRef(); * @param {Boolean} isChronosReport - Flag to check if the chat participant is Chronos * @param {Boolean} isPinnedChat - Flag to check if the chat is pinned in the LHN. Used for the Pin/Unpin action * @param {Boolean} isUnreadChat - Flag to check if the chat has unread messages in the LHN. Used for the Mark as Read/Unread action - * @param {Boolean} [isParentReport] - Is the report action from parent report */ function showContextMenu( type, @@ -34,7 +33,6 @@ function showContextMenu( isChronosReport = false, isPinnedChat = false, isUnreadChat = false, - isParentReport = false, ) { if (!contextMenuRef.current) { return; @@ -53,7 +51,6 @@ function showContextMenu( isChronosReport, isPinnedChat, isUnreadChat, - isParentReport, ); } diff --git a/src/pages/home/report/ContextMenu/genericReportActionContextMenuPropTypes.js b/src/pages/home/report/ContextMenu/genericReportActionContextMenuPropTypes.js index 596d5bd907f2..f62873031c54 100644 --- a/src/pages/home/report/ContextMenu/genericReportActionContextMenuPropTypes.js +++ b/src/pages/home/report/ContextMenu/genericReportActionContextMenuPropTypes.js @@ -8,9 +8,6 @@ const propTypes = { /** The report action this context menu is attached to. */ reportAction: PropTypes.shape(reportActionPropTypes).isRequired, - /** Is the report action from parent report */ - isParentReport: PropTypes.bool, - /** If true, this component will be a small, row-oriented menu that displays icons but not text. If false, this component will be a larger, column-oriented menu that displays icons alongside text in each row. */ isMini: PropTypes.bool, @@ -26,7 +23,6 @@ const propTypes = { }; const defaultProps = { - isParentReport: false, isMini: false, isVisible: false, selection: '', diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index b96bc67bc292..d17a12cbc7d6 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -71,9 +71,6 @@ const propTypes = { /** Is this the most recent IOU Action? */ isMostRecentIOUReportAction: PropTypes.bool.isRequired, - /** Is this the action from parent report */ - isParentReport: PropTypes.bool, - /** Should we display the new marker on top of the comment? */ shouldDisplayNewMarker: PropTypes.bool.isRequired, @@ -103,7 +100,6 @@ const defaultProps = { personalDetails: {}, shouldShowSubscriptAvatar: false, hasOutstandingIOU: false, - isParentReport: false, }; function ReportActionItem(props) { @@ -187,12 +183,9 @@ function ReportActionItem(props) { toggleContextMenuFromActiveReportAction, ReportUtils.isArchivedRoom(props.report), ReportUtils.chatIncludesChronos(props.report), - undefined, - undefined, - props.isParentReport, ); }, - [props.draftMessage, props.action, props.report, props.isParentReport, toggleContextMenuFromActiveReportAction], + [props.draftMessage, props.action, props.report, toggleContextMenuFromActiveReportAction], ); const toggleReaction = useCallback( @@ -329,7 +322,7 @@ function ReportActionItem(props) { const numberOfThreadReplies = _.get(props, ['action', 'childVisibleActionCount'], 0); const hasReplies = numberOfThreadReplies > 0; - const shouldDisplayThreadReplies = hasReplies && props.action.childCommenterCount && !props.isParentReport; + const shouldDisplayThreadReplies = hasReplies && props.action.childCommenterCount && !ReportUtils.isThreadFirstChat(props.action, props.report.reportID); const oldestFourAccountIDs = lodashGet(props.action, 'childOldestFourAccountIDs', '').split(','); const draftMessageRightAlign = props.draftMessage ? styles.chatItemReactionsDraftRight : {}; @@ -450,7 +443,6 @@ function ReportActionItem(props) { isVisible={hovered && !props.draftMessage && !hasErrors} draftMessage={props.draftMessage} isChronosReport={ReportUtils.chatIncludesChronos(props.report)} - isParentReport={props.isParentReport} /> {parentReportAction && ( `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, }, - parentReport: { - key: ({parentReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, - }, parentReportActions: { key: ({parentReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, canEvict: false, From 1a35e4a590d06fca1cea954696fc2c55c52be205 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 23 Jun 2023 13:43:25 +0700 Subject: [PATCH 09/12] use original report id --- src/libs/ReportUtils.js | 13 ++++++++++ src/libs/actions/Report.js | 49 +++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index c2e793411ed8..14e89bcd7e59 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2258,6 +2258,18 @@ function getParentReport(report) { return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, {}); } +/** + * Returns the parentReportID if the given report is a thread else returns the current reportID. + * + * @param {String} reportID + * @param {Object} reportAction + * @returns {String} + */ +function getOriginalReportID(reportID, reportAction) { + return isThreadFirstChat(reportAction, reportID) ? + lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, 'parentReportID']) : reportID; +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -2350,4 +2362,5 @@ export { getMoneyRequestAction, getBankAccountRoute, getParentReport, + getOriginalReportID, }; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c5c5aa2250c3..8b9eb44ef91b 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -821,6 +821,7 @@ Onyx.connect({ * @param {Object} reportAction */ function deleteReportComment(reportID, reportAction) { + const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); const reportActionID = reportAction.reportActionID; const deletedMessage = [ { @@ -846,9 +847,9 @@ function deleteReportComment(reportID, reportAction) { lastMessageText: '', lastVisibleActionCreated: '', }; - const lastMessageText = ReportActionsUtils.getLastVisibleMessageText(reportID, optimisticReportActions); + const lastMessageText = ReportActionsUtils.getLastVisibleMessageText(originalReportID, optimisticReportActions); if (lastMessageText.length > 0) { - const lastVisibleActionCreated = ReportActionsUtils.getLastVisibleAction(reportID, optimisticReportActions).created; + const lastVisibleActionCreated = ReportActionsUtils.getLastVisibleAction(originalReportID, optimisticReportActions).created; optimisticReport = { lastMessageText, lastVisibleActionCreated, @@ -860,7 +861,7 @@ function deleteReportComment(reportID, reportAction) { const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: { [reportActionID]: { message: reportAction.message, @@ -874,7 +875,7 @@ function deleteReportComment(reportID, reportAction) { const successData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: { [reportActionID]: { pendingAction: null, @@ -887,19 +888,19 @@ function deleteReportComment(reportID, reportAction) { const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: optimisticReportActions, }, { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`, value: optimisticReport, }, ]; const parameters = { - reportID, - reportActionID: reportAction.reportActionID, + reportID: originalReportID, + reportActionID, }; API.write('DeleteComment', parameters, {optimisticData, successData, failureData}); } @@ -952,6 +953,7 @@ const handleUserDeletedLinksInHtml = (newCommentText, originalHtml) => { */ function editReportComment(reportID, originalReportAction, textForNewComment) { const parser = new ExpensiMark(); + const originalReportID = ReportUtils.getOriginalReportID(reportID, originalReportAction); // Do not autolink if someone explicitly tries to remove a link from message. // https://github.com/Expensify/App/issues/9090 @@ -970,7 +972,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { // Delete the comment if it's empty if (_.isEmpty(htmlForNewComment)) { - deleteReportComment(reportID, originalReportAction); + deleteReportComment(originalReportID, originalReportAction); return; } @@ -999,12 +1001,12 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: optimisticReportActions, }, ]; - const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID, optimisticReportActions); + const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(originalReportID, optimisticReportActions); if (reportActionID === lastVisibleAction.reportActionID) { const lastMessageText = ReportUtils.formatReportLastMessageText(reportComment); const optimisticReport = { @@ -1012,7 +1014,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { }; optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`, value: optimisticReport, }); } @@ -1020,7 +1022,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: { [reportActionID]: { ...originalReportAction, @@ -1033,7 +1035,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { const successData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: { [reportActionID]: { pendingAction: null, @@ -1043,7 +1045,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { ]; const parameters = { - reportID, + reportID: originalReportID, reportComment: htmlForNewComment, reportActionID, }; @@ -1528,6 +1530,7 @@ function hasAccountIDReacted(accountID, users, skinTone) { * @param {number} [skinTone] Optional. */ function addEmojiReaction(reportID, originalReportAction, emoji, skinTone = preferredSkinTone) { + const originalReportID = ReportUtils.getOriginalReportID(reportID, originalReportAction); const message = originalReportAction.message[0]; let reactionObject = message.reactions && _.find(message.reactions, (reaction) => reaction.emoji === emoji.name); const needToInsertReactionObject = !reactionObject; @@ -1559,10 +1562,10 @@ function addEmojiReaction(reportID, originalReportAction, emoji, skinTone = pref }; // Optimistically update the reportAction with the reaction - const optimisticData = getOptimisticDataForReportActionUpdate(originalReportAction, updatedMessage, reportID); + const optimisticData = getOptimisticDataForReportActionUpdate(originalReportAction, updatedMessage, originalReportID); const parameters = { - reportID, + reportID: originalReportID, skinTone, emojiCode: emoji.name, sequenceNumber: originalReportAction.sequenceNumber, @@ -1578,6 +1581,7 @@ function addEmojiReaction(reportID, originalReportAction, emoji, skinTone = pref * @param {{ name: string, code: string, types: string[] }} emoji */ function removeEmojiReaction(reportID, originalReportAction, emoji) { + const originalReportID = ReportUtils.getOriginalReportID(reportID, originalReportAction); const message = originalReportAction.message[0]; const reactionObject = message.reactions && _.find(message.reactions, (reaction) => reaction.emoji === emoji.name); if (!reactionObject) { @@ -1610,10 +1614,10 @@ function removeEmojiReaction(reportID, originalReportAction, emoji) { }; // Optimistically update the reportAction with the reaction - const optimisticData = getOptimisticDataForReportActionUpdate(originalReportAction, updatedMessage, reportID); + const optimisticData = getOptimisticDataForReportActionUpdate(originalReportAction, updatedMessage, originalReportID); const parameters = { - reportID, + reportID: originalReportID, sequenceNumber: originalReportAction.sequenceNumber, reportActionID: originalReportAction.reportActionID, emojiCode: emoji.name, @@ -1739,6 +1743,7 @@ function openLastOpenedPublicRoom(lastOpenedPublicRoomID) { * @param {String} severity */ function flagComment(reportID, reportAction, severity) { + const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); const message = reportAction.message[0]; let updatedDecision; if (severity === CONST.MODERATION.FLAG_SEVERITY_SPAM || severity === CONST.MODERATION.FLAG_SEVERITY_INCONSIDERATE) { @@ -1773,7 +1778,7 @@ function flagComment(reportID, reportAction, severity) { const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: { [reportActionID]: { pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, @@ -1786,7 +1791,7 @@ function flagComment(reportID, reportAction, severity) { const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: { [reportActionID]: { ...reportAction, @@ -1799,7 +1804,7 @@ function flagComment(reportID, reportAction, severity) { const successData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, value: { [reportActionID]: { pendingAction: null, From 15ffd44026ecc370f4164ff311d78f316480fc17 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 23 Jun 2023 13:46:43 +0700 Subject: [PATCH 10/12] remove unnecessary changes --- src/pages/home/report/ReportActionItemMessageEdit.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 56b78a73ae50..c5b092487d70 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -208,18 +208,14 @@ function ReportActionItemMessageEdit(props) { const trimmedNewDraft = draft.trim(); - // If the reportActionID and parentReportActionID are the same then the user is editing the first message of a - // thread and we should pass the parentReportID instead of the reportID of the thread - const reportID = props.report.parentReportActionID === props.action.reportActionID ? props.report.parentReportID : props.reportID; - // When user tries to save the empty message, it will delete it. Prompt the user to confirm deleting. if (!trimmedNewDraft) { - ReportActionContextMenu.showDeleteModal(reportID, props.action, false, deleteDraft, () => InteractionManager.runAfterInteractions(() => textInputRef.current.focus())); + ReportActionContextMenu.showDeleteModal(props.reportID, props.action, false, deleteDraft, () => InteractionManager.runAfterInteractions(() => textInputRef.current.focus())); return; } - Report.editReportComment(reportID, props.action, trimmedNewDraft); + Report.editReportComment(props.reportID, props.action, trimmedNewDraft); deleteDraft(); - }, [props.action, debouncedSaveDraft, deleteDraft, draft, props.reportID, props.report]); + }, [props.action, debouncedSaveDraft, deleteDraft, draft, props.reportID]); /** * @param {String} emoji From 76b5c9eca38a9bd5ee3d708335ea11128aa13543 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 23 Jun 2023 13:52:21 +0700 Subject: [PATCH 11/12] fix lint --- src/libs/ReportUtils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 14e89bcd7e59..7102fc30bb49 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2266,8 +2266,7 @@ function getParentReport(report) { * @returns {String} */ function getOriginalReportID(reportID, reportAction) { - return isThreadFirstChat(reportAction, reportID) ? - lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, 'parentReportID']) : reportID; + return isThreadFirstChat(reportAction, reportID) ? lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, 'parentReportID']) : reportID; } export { From 5b37315863b28edcdd5e16b63c29012a222a575b Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 23 Jun 2023 17:45:16 +0700 Subject: [PATCH 12/12] update comment --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7102fc30bb49..d0ee8800cb2b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2259,7 +2259,7 @@ function getParentReport(report) { } /** - * Returns the parentReportID if the given report is a thread else returns the current reportID. + * Returns ID of the original report from which the given reportAction is first created. * * @param {String} reportID * @param {Object} reportAction