From a6363ec22e67f95803e7680e1c0088fbca96f608 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 14 Dec 2023 17:07:30 +0700 Subject: [PATCH 1/2] hide thread option in context menu when deleting acion in offline mode --- src/libs/ReportUtils.ts | 9 +++++++++ .../report/ContextMenu/ContextMenuActions.js | 16 +++++++++++++--- src/pages/home/report/ReportActionItem.js | 3 +-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 63037416c923..fa8add8f666f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4314,6 +4314,14 @@ function navigateToPrivateNotes(report: Report, session: Session) { Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID)); } +/** + * Check whether should display thread reply + */ +function shouldDisplayThreadReplies(reportAction: ReportAction, reportID: string): boolean { + const hasReplies = (reportAction.childVisibleActionCount ?? 0) > 0; + return hasReplies && !!reportAction.childCommenterCount && !isThreadFirstChat(reportAction, reportID); +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -4485,6 +4493,7 @@ export { canEditWriteCapability, hasSmartscanError, shouldAutoFocusOnKeyPress, + shouldDisplayThreadReplies, }; export type {OptionData, OptimisticChatReport}; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 5e6f2d46abda..38a2c1e5510e 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -126,12 +126,18 @@ export default [ if (type !== CONTEXT_MENU_TYPES.REPORT_ACTION) { return false; } + const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); + const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID); const isCommentAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT; const isReportPreviewAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; const isIOUAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && !ReportActionsUtils.isSplitBillAction(reportAction); const isModifiedExpenseAction = ReportActionsUtils.isModifiedExpenseAction(reportAction); const isTaskAction = ReportActionsUtils.isTaskAction(reportAction); - return (isCommentAction || isReportPreviewAction || isIOUAction || isModifiedExpenseAction || isTaskAction) && !ReportUtils.isThreadFirstChat(reportAction, reportID); + return ( + (isCommentAction || isReportPreviewAction || isIOUAction || isModifiedExpenseAction || isTaskAction) && + !ReportUtils.isThreadFirstChat(reportAction, reportID) && + (!isDeletedAction || shouldDisplayThreadReplies) + ); }, onPress: (closePopover, {reportAction, reportID}) => { if (closePopover) { @@ -158,11 +164,13 @@ export default [ const isActionCreator = ReportUtils.isActionCreator(reportAction); childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; } + const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); + const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID); const subscribed = childReportNotificationPreference !== 'hidden'; const isCommentAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportUtils.isThreadFirstChat(reportAction, reportID); const isReportPreviewAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; const isIOUAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && !ReportActionsUtils.isSplitBillAction(reportAction); - return !subscribed && (isCommentAction || isReportPreviewAction || isIOUAction); + return !subscribed && (isCommentAction || isReportPreviewAction || isIOUAction) && (!isDeletedAction || shouldDisplayThreadReplies); }, onPress: (closePopover, {reportAction, reportID}) => { let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', ''); @@ -195,6 +203,8 @@ export default [ const isActionCreator = ReportUtils.isActionCreator(reportAction); childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; } + const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); + const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID); const subscribed = childReportNotificationPreference !== 'hidden'; if (type !== CONTEXT_MENU_TYPES.REPORT_ACTION) { return false; @@ -202,7 +212,7 @@ export default [ const isCommentAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportUtils.isThreadFirstChat(reportAction, reportID); const isReportPreviewAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; const isIOUAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && !ReportActionsUtils.isSplitBillAction(reportAction); - return subscribed && (isCommentAction || isReportPreviewAction || isIOUAction); + return subscribed && (isCommentAction || isReportPreviewAction || isIOUAction) && (!isDeletedAction || shouldDisplayThreadReplies); }, onPress: (closePopover, {reportAction, reportID}) => { let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', ''); diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 2e888a5471b8..5fafda690d9f 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -491,9 +491,8 @@ 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 = ReportUtils.shouldDisplayThreadReplies(props.action, props.report.reportID); const oldestFourAccountIDs = _.map(lodashGet(props.action, 'childOldestFourAccountIDs', '').split(','), (accountID) => Number(accountID)); const draftMessageRightAlign = props.draftMessage ? styles.chatItemReactionsDraftRight : {}; From bb85de6f3bb9f70d8428a66fcb4a920eb609dad5 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:29:11 +0700 Subject: [PATCH 2/2] Update src/libs/ReportUtils.ts Co-authored-by: Eugene Voloshchak --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fa8add8f666f..ab60cd650545 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4315,7 +4315,7 @@ function navigateToPrivateNotes(report: Report, session: Session) { } /** - * Check whether should display thread reply + * Checks if thread replies should be displayed */ function shouldDisplayThreadReplies(reportAction: ReportAction, reportID: string): boolean { const hasReplies = (reportAction.childVisibleActionCount ?? 0) > 0;