From 47c03d9adf1945d9a08f225c132ab1dc06de498b Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 30 Oct 2024 17:56:55 +0800 Subject: [PATCH 01/10] fix reply in thread shown for thread parent --- src/libs/ReportUtils.ts | 4 ++-- .../report/ContextMenu/BaseReportActionContextMenu.tsx | 6 ++++++ src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 8 ++++---- .../ContextMenu/PopoverReportActionContextMenu.tsx | 4 ++++ .../home/report/ContextMenu/ReportActionContextMenu.ts | 3 +++ src/pages/home/report/ReportActionItem.tsx | 9 ++++++++- src/pages/home/report/ReportActionItemParentAction.tsx | 1 + 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c7badea7082e..b75464608b95 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7736,7 +7736,7 @@ function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry * - The action is a whisper action and it's neither a report preview nor IOU action * - The action is the thread's first chat */ -function shouldDisableThread(reportAction: OnyxInputOrEntry, reportID: string): boolean { +function shouldDisableThread(reportAction: OnyxInputOrEntry, reportID: string, isThreadFirstChatParam: boolean): boolean { const isSplitBillAction = ReportActionsUtils.isSplitBillAction(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction); @@ -7751,7 +7751,7 @@ function shouldDisableThread(reportAction: OnyxInputOrEntry, repor (isDeletedAction && !reportAction?.childVisibleActionCount) || (isArchivedReport && !reportAction?.childVisibleActionCount) || (isWhisperAction && !isReportPreviewAction && !isIOUAction) || - isThreadFirstChat(reportAction, reportID) + isThreadFirstChatParam ); } diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 2e92669aa8c5..b6ab066848b7 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -76,6 +76,9 @@ type BaseReportActionContextMenuProps = { /** Flag to check if the chat is unread in the LHN. Used for the Mark as Read/Unread action */ isUnreadChat?: boolean; + /** True if this is the first chat preview of a thread */ + isThreadFirstChat?: boolean; + /** Content Ref */ contentRef?: RefObject; @@ -101,6 +104,7 @@ function BaseReportActionContextMenu({ isVisible = false, isPinnedChat = false, isUnreadChat = false, + isThreadFirstChat = false, selection = '', draftMessage = '', reportActionID, @@ -194,6 +198,7 @@ function BaseReportActionContextMenu({ reportID, isPinnedChat, isUnreadChat, + isThreadFirstChat, isOffline: !!isOffline, isMini, isProduction, @@ -284,6 +289,7 @@ function BaseReportActionContextMenu({ true, () => {}, true, + isThreadFirstChat, ); }; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 6f3a1e8e565a..fd7d2a4ed556 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -64,6 +64,7 @@ type ShouldShow = (args: { reportID: string; isPinnedChat: boolean; isUnreadChat: boolean; + isThreadFirstChat: boolean; isOffline: boolean; isMini: boolean; isProduction: boolean; @@ -178,11 +179,11 @@ const ContextMenuActions: ContextMenuAction[] = [ isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.replyInThread', icon: Expensicons.ChatBubbleReply, - shouldShow: ({type, reportAction, reportID}) => { + shouldShow: ({type, reportAction, reportID, isThreadFirstChat}) => { if (type !== CONST.CONTEXT_MENU_TYPES.REPORT_ACTION) { return false; } - return !ReportUtils.shouldDisableThread(reportAction, reportID); + return !ReportUtils.shouldDisableThread(reportAction, reportID, isThreadFirstChat); }, onPress: (closePopover, {reportAction, reportID}) => { const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); @@ -301,12 +302,11 @@ const ContextMenuActions: ContextMenuAction[] = [ isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.joinThread', icon: Expensicons.Bell, - shouldShow: ({reportAction, isArchivedRoom, reportID}) => { + shouldShow: ({reportAction, isArchivedRoom, reportID, isThreadFirstChat}) => { const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID); const subscribed = childReportNotificationPreference !== 'hidden'; - const isThreadFirstChat = ReportUtils.isThreadFirstChat(reportAction, reportID); const isWhisperAction = ReportActionsUtils.isWhisperAction(reportAction) || ReportActionsUtils.isActionableTrackExpense(reportAction); const isExpenseReportAction = ReportActionsUtils.isMoneyRequestAction(reportAction) || ReportActionsUtils.isReportPreviewAction(reportAction); return !subscribed && !isWhisperAction && !isExpenseReportAction && !isThreadFirstChat && (shouldDisplayThreadReplies || (!isDeletedAction && !isArchivedRoom)); diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx index f387f09d3880..a23a0a1be47d 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx @@ -62,6 +62,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef([]); const [shoudSwitchPositionIfOverflow, setShoudSwitchPositionIfOverflow] = useState(false); @@ -172,6 +173,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef {}, isOverflowMenu = false, + isThreadFirstChatParam = false, ) => { const {pageX = 0, pageY = 0} = extractPointerEvent(event); contextMenuAnchorRef.current = contextMenuAnchor; @@ -220,6 +222,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef void, isOverflowMenu?: boolean, + isThreadFirstChat?: boolean, ) => void; type ReportActionContextMenu = { @@ -119,6 +120,7 @@ function showContextMenu( shouldCloseOnTarget = false, setIsEmojiPickerActive = () => {}, isOverflowMenu = false, + isThreadFirstChat = false, ) { if (!contextMenuRef.current) { return; @@ -143,6 +145,7 @@ function showContextMenu( shouldCloseOnTarget, setIsEmojiPickerActive, isOverflowMenu, + isThreadFirstChat, ); }; diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 0af9bd61120d..4a1e0feba28a 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -132,6 +132,9 @@ type ReportActionItemProps = { /** If this is the first visible report action */ isFirstVisibleReportAction: boolean; + /** True if this is the first chat preview of a thread */ + isThreadFirstChat?: boolean; + /** IF the thread divider line will be used */ shouldUseThreadDividerLine?: boolean; @@ -155,6 +158,7 @@ function ReportActionItem({ shouldShowSubscriptAvatar = false, onPress = undefined, isFirstVisibleReportAction = false, + isThreadFirstChat = false, shouldUseThreadDividerLine = false, hideThreadReplies = false, shouldDisplayContextMenu = true, @@ -358,9 +362,11 @@ function ReportActionItem({ disabledActions, false, setIsEmojiPickerActive as () => void, + undefined, + isThreadFirstChat, ); }, - [draftMessage, action, reportID, toggleContextMenuFromActiveReportAction, originalReportID, shouldDisplayContextMenu, disabledActions, isArchivedRoom, isChronosReport], + [draftMessage, action, reportID, toggleContextMenuFromActiveReportAction, originalReportID, shouldDisplayContextMenu, disabledActions, isArchivedRoom, isChronosReport, isThreadFirstChat], ); // Handles manual scrolling to the bottom of the chat when the last message is an actionable whisper and it's resolved. @@ -975,6 +981,7 @@ function ReportActionItem({ displayAsGroup={displayAsGroup} disabledActions={disabledActions} isVisible={hovered && draftMessage === undefined && !hasErrors} + isThreadFirstChat={isThreadFirstChat} draftMessage={draftMessage} isChronosReport={isChronosReport} checkIfContextMenuActive={toggleContextMenuFromActiveReportAction} diff --git a/src/pages/home/report/ReportActionItemParentAction.tsx b/src/pages/home/report/ReportActionItemParentAction.tsx index 4612a2f84f66..fdd27f8d6da0 100644 --- a/src/pages/home/report/ReportActionItemParentAction.tsx +++ b/src/pages/home/report/ReportActionItemParentAction.tsx @@ -153,6 +153,7 @@ function ReportActionItemParentAction({ isFirstVisibleReportAction={isFirstVisibleReportAction} shouldUseThreadDividerLine={shouldUseThreadDividerLine} hideThreadReplies + isThreadFirstChat /> )} From 6035ef42e5dd2ee891100c9fb94e0d5d45255e0e Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 30 Oct 2024 18:06:36 +0800 Subject: [PATCH 02/10] remove unnecessary isThreadFirstChat --- src/libs/ReportUtils.ts | 9 ++++----- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 4 ++-- src/pages/home/report/ReportActionItem.tsx | 5 +---- src/pages/home/report/ReportActionItemParentAction.tsx | 1 - 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b75464608b95..cf76a020c713 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1813,10 +1813,9 @@ function canDeleteReportAction(reportAction: OnyxInputOrEntry, rep return false; } - const linkedReport = isThreadFirstChat(reportAction, reportID) ? getReportOrDraftReport(report?.parentReportID) : report; if (isActionOwner) { - if (!isEmptyObject(linkedReport) && (isMoneyRequestReport(linkedReport) || isInvoiceReport(linkedReport))) { - return canDeleteTransaction(linkedReport); + if (!isEmptyObject(report) && (isMoneyRequestReport(report) || isInvoiceReport(report))) { + return canDeleteTransaction(report); } return true; } @@ -7678,9 +7677,9 @@ function hasOnlyHeldExpenses(iouReportID: string): boolean { /** * Checks if thread replies should be displayed */ -function shouldDisplayThreadReplies(reportAction: OnyxInputOrEntry, reportID: string): boolean { +function shouldDisplayThreadReplies(reportAction: OnyxInputOrEntry, isThreadFirstChatParam: boolean): boolean { const hasReplies = (reportAction?.childVisibleActionCount ?? 0) > 0; - return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChat(reportAction, reportID); + return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChatParam; } /** diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index fd7d2a4ed556..96ddb32de3de 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -302,10 +302,10 @@ const ContextMenuActions: ContextMenuAction[] = [ isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.joinThread', icon: Expensicons.Bell, - shouldShow: ({reportAction, isArchivedRoom, reportID, isThreadFirstChat}) => { + shouldShow: ({reportAction, isArchivedRoom, isThreadFirstChat}) => { const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); - const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID); + const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, isThreadFirstChat); const subscribed = childReportNotificationPreference !== 'hidden'; const isWhisperAction = ReportActionsUtils.isWhisperAction(reportAction) || ReportActionsUtils.isActionableTrackExpense(reportAction); const isExpenseReportAction = ReportActionsUtils.isMoneyRequestAction(reportAction) || ReportActionsUtils.isReportPreviewAction(reportAction); diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 4a1e0feba28a..0dcc5d8078d3 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -138,8 +138,6 @@ type ReportActionItemProps = { /** IF the thread divider line will be used */ shouldUseThreadDividerLine?: boolean; - hideThreadReplies?: boolean; - /** Whether context menu should be displayed */ shouldDisplayContextMenu?: boolean; }; @@ -160,7 +158,6 @@ function ReportActionItem({ isFirstVisibleReportAction = false, isThreadFirstChat = false, shouldUseThreadDividerLine = false, - hideThreadReplies = false, shouldDisplayContextMenu = true, parentReportActionForTransactionThread, }: ReportActionItemProps) { @@ -796,7 +793,7 @@ function ReportActionItem({ } const numberOfThreadReplies = action.childVisibleActionCount ?? 0; - const shouldDisplayThreadReplies = !hideThreadReplies && ReportUtils.shouldDisplayThreadReplies(action, reportID); + const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(action, isThreadFirstChat); const oldestFourAccountIDs = action.childOldestFourAccountIDs ?.split(',') diff --git a/src/pages/home/report/ReportActionItemParentAction.tsx b/src/pages/home/report/ReportActionItemParentAction.tsx index fdd27f8d6da0..f3b35fbaba8c 100644 --- a/src/pages/home/report/ReportActionItemParentAction.tsx +++ b/src/pages/home/report/ReportActionItemParentAction.tsx @@ -152,7 +152,6 @@ function ReportActionItemParentAction({ index={index} isFirstVisibleReportAction={isFirstVisibleReportAction} shouldUseThreadDividerLine={shouldUseThreadDividerLine} - hideThreadReplies isThreadFirstChat /> )} From 13856816a89d65b21d60caa10093c0c03a0202fa Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 30 Oct 2024 18:16:43 +0800 Subject: [PATCH 03/10] prettier --- src/pages/home/report/ReportActionItem.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 0dcc5d8078d3..6692ce5ae2f6 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -363,7 +363,18 @@ function ReportActionItem({ isThreadFirstChat, ); }, - [draftMessage, action, reportID, toggleContextMenuFromActiveReportAction, originalReportID, shouldDisplayContextMenu, disabledActions, isArchivedRoom, isChronosReport, isThreadFirstChat], + [ + draftMessage, + action, + reportID, + toggleContextMenuFromActiveReportAction, + originalReportID, + shouldDisplayContextMenu, + disabledActions, + isArchivedRoom, + isChronosReport, + isThreadFirstChat, + ], ); // Handles manual scrolling to the bottom of the chat when the last message is an actionable whisper and it's resolved. From 70fede010b454bf4666e619f88fa789f93547e77 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 30 Oct 2024 18:18:21 +0800 Subject: [PATCH 04/10] update test --- tests/unit/ReportUtilsTest.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 81101b74f4d7..04dab0faf9a3 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -792,7 +792,7 @@ describe('ReportUtils', () => { it('should disable on thread-disabled actions', () => { const reportAction = ReportUtils.buildOptimisticCreatedReportAction('email1@test.com'); - expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + expect(ReportUtils.shouldDisableThread(reportAction, reportID, false)).toBeTruthy(); }); it('should disable thread on split expense actions', () => { @@ -804,7 +804,7 @@ describe('ReportUtils', () => { [{login: 'email1@test.com'}, {login: 'email2@test.com'}], NumberUtils.rand64(), ) as ReportAction; - expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + expect(ReportUtils.shouldDisableThread(reportAction, reportID, false)).toBeTruthy(); }); it('should disable on deleted and not-thread actions', () => { @@ -820,10 +820,10 @@ describe('ReportUtils', () => { ], childVisibleActionCount: 1, } as ReportAction; - expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeFalsy(); + expect(ReportUtils.shouldDisableThread(reportAction, reportID, false)).toBeFalsy(); reportAction.childVisibleActionCount = 0; - expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + expect(ReportUtils.shouldDisableThread(reportAction, reportID, false)).toBeTruthy(); }); it('should disable on archived reports and not-thread actions', () => { @@ -836,10 +836,10 @@ describe('ReportUtils', () => { const reportAction = { childVisibleActionCount: 1, } as ReportAction; - expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeFalsy(); + expect(ReportUtils.shouldDisableThread(reportAction, reportID, false)).toBeFalsy(); reportAction.childVisibleActionCount = 0; - expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + expect(ReportUtils.shouldDisableThread(reportAction, reportID, false)).toBeTruthy(); }); }); @@ -850,14 +850,14 @@ describe('ReportUtils', () => { whisperedTo: [123456], }, } as ReportAction; - expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + expect(ReportUtils.shouldDisableThread(reportAction, reportID, false)).toBeTruthy(); }); it('should disable on thread first chat', () => { const reportAction = { childReportID: reportID, } as ReportAction; - expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + expect(ReportUtils.shouldDisableThread(reportAction, reportID, true)).toBeTruthy(); }); }); From 9fe7049f3c1461acf487acbf5f922d41c8102c97 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 9 Nov 2024 11:55:08 +0800 Subject: [PATCH 05/10] update comment --- .../home/report/ContextMenu/BaseReportActionContextMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index b6ab066848b7..9368496274b2 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -76,7 +76,7 @@ type BaseReportActionContextMenuProps = { /** Flag to check if the chat is unread in the LHN. Used for the Mark as Read/Unread action */ isUnreadChat?: boolean; - /** True if this is the first chat preview of a thread */ + /** Is the action the first chat of a thread, in other words the parent action of a thread report */ isThreadFirstChat?: boolean; /** Content Ref */ From cf7ee192072c9ff2135c65b642c48665dd1fe667 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 21 Nov 2024 13:11:57 +0800 Subject: [PATCH 06/10] check whether its thread first chat without using the function --- src/libs/ReportUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 40a8f4291266..b1292343a7ac 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7275,8 +7275,9 @@ function getOriginalReportID(reportID: string, reportAction: OnyxInputOrEntry Date: Thu, 21 Nov 2024 13:13:16 +0800 Subject: [PATCH 07/10] remove isThreadFirstChat function --- src/libs/ReportUtils.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b1292343a7ac..d98a95f2b12d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1600,13 +1600,6 @@ function isWorkspaceThread(report: OnyxEntry): boolean { return isThread(report) && isChatReport(report) && CONST.WORKSPACE_ROOM_TYPES.some((type) => chatType === type); } -/** - * Returns true if reportAction is the first chat preview of a Thread - */ -function isThreadFirstChat(reportAction: OnyxInputOrEntry, reportID: string): boolean { - return reportAction?.childReportID?.toString() === reportID; -} - /** * Checks if a report is a child report. */ @@ -7747,9 +7740,9 @@ function hasOnlyHeldExpenses(iouReportID: string): boolean { /** * Checks if thread replies should be displayed */ -function shouldDisplayThreadReplies(reportAction: OnyxInputOrEntry, isThreadFirstChatParam: boolean): boolean { +function shouldDisplayThreadReplies(reportAction: OnyxInputOrEntry, isThreadFirstChat: boolean): boolean { const hasReplies = (reportAction?.childVisibleActionCount ?? 0) > 0; - return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChatParam; + return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChat; } /** @@ -7807,7 +7800,7 @@ function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry * - The action is a whisper action and it's neither a report preview nor IOU action * - The action is the thread's first chat */ -function shouldDisableThread(reportAction: OnyxInputOrEntry, reportID: string, isThreadFirstChatParam: boolean): boolean { +function shouldDisableThread(reportAction: OnyxInputOrEntry, reportID: string, isThreadFirstChat: boolean): boolean { const isSplitBillAction = ReportActionsUtils.isSplitBillAction(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction); @@ -7822,7 +7815,7 @@ function shouldDisableThread(reportAction: OnyxInputOrEntry, repor (isDeletedAction && !reportAction?.childVisibleActionCount) || (isArchivedReport && !reportAction?.childVisibleActionCount) || (isWhisperAction && !isReportPreviewAction && !isIOUAction) || - isThreadFirstChatParam + isThreadFirstChat ); } @@ -8678,7 +8671,6 @@ export { isSystemChat, isTaskReport, isThread, - isThreadFirstChat, isTrackExpenseReport, isUnread, isUnreadWithMention, From d7e888f00455bc2e4be1e18b0dbed6f6684b01bf Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 21 Nov 2024 13:21:52 +0800 Subject: [PATCH 08/10] rename --- src/libs/ReportUtils.ts | 12 ++++++------ .../ContextMenu/BaseReportActionContextMenu.tsx | 8 ++++---- .../home/report/ContextMenu/ContextMenuActions.tsx | 12 ++++++------ .../ContextMenu/PopoverReportActionContextMenu.tsx | 8 ++++---- .../report/ContextMenu/ReportActionContextMenu.ts | 6 +++--- src/pages/home/report/ReportActionItem.tsx | 12 ++++++------ .../home/report/ReportActionItemParentAction.tsx | 2 +- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d98a95f2b12d..b02e08b85dd4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7268,9 +7268,9 @@ function getOriginalReportID(reportID: string, reportAction: OnyxInputOrEntry, isThreadFirstChat: boolean): boolean { +function shouldDisplayThreadReplies(reportAction: OnyxInputOrEntry, isThreadReportParentAction: boolean): boolean { const hasReplies = (reportAction?.childVisibleActionCount ?? 0) > 0; - return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChat; + return hasReplies && !!reportAction?.childCommenterCount && !isThreadReportParentAction; } /** @@ -7800,7 +7800,7 @@ function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry * - The action is a whisper action and it's neither a report preview nor IOU action * - The action is the thread's first chat */ -function shouldDisableThread(reportAction: OnyxInputOrEntry, reportID: string, isThreadFirstChat: boolean): boolean { +function shouldDisableThread(reportAction: OnyxInputOrEntry, reportID: string, isThreadReportParentAction: boolean): boolean { const isSplitBillAction = ReportActionsUtils.isSplitBillAction(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction); @@ -7815,7 +7815,7 @@ function shouldDisableThread(reportAction: OnyxInputOrEntry, repor (isDeletedAction && !reportAction?.childVisibleActionCount) || (isArchivedReport && !reportAction?.childVisibleActionCount) || (isWhisperAction && !isReportPreviewAction && !isIOUAction) || - isThreadFirstChat + isThreadReportParentAction ); } diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 9368496274b2..ffb38365fb53 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -77,7 +77,7 @@ type BaseReportActionContextMenuProps = { isUnreadChat?: boolean; /** Is the action the first chat of a thread, in other words the parent action of a thread report */ - isThreadFirstChat?: boolean; + isThreadReportParentAction?: boolean; /** Content Ref */ contentRef?: RefObject; @@ -104,7 +104,7 @@ function BaseReportActionContextMenu({ isVisible = false, isPinnedChat = false, isUnreadChat = false, - isThreadFirstChat = false, + isThreadReportParentAction = false, selection = '', draftMessage = '', reportActionID, @@ -198,7 +198,7 @@ function BaseReportActionContextMenu({ reportID, isPinnedChat, isUnreadChat, - isThreadFirstChat, + isThreadReportParentAction, isOffline: !!isOffline, isMini, isProduction, @@ -289,7 +289,7 @@ function BaseReportActionContextMenu({ true, () => {}, true, - isThreadFirstChat, + isThreadReportParentAction, ); }; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 360802371d47..ff8d44ff8844 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -64,7 +64,7 @@ type ShouldShow = (args: { reportID: string; isPinnedChat: boolean; isUnreadChat: boolean; - isThreadFirstChat: boolean; + isThreadReportParentAction: boolean; isOffline: boolean; isMini: boolean; isProduction: boolean; @@ -179,11 +179,11 @@ const ContextMenuActions: ContextMenuAction[] = [ isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.replyInThread', icon: Expensicons.ChatBubbleReply, - shouldShow: ({type, reportAction, reportID, isThreadFirstChat}) => { + shouldShow: ({type, reportAction, reportID, isThreadReportParentAction}) => { if (type !== CONST.CONTEXT_MENU_TYPES.REPORT_ACTION) { return false; } - return !ReportUtils.shouldDisableThread(reportAction, reportID, isThreadFirstChat); + return !ReportUtils.shouldDisableThread(reportAction, reportID, isThreadReportParentAction); }, onPress: (closePopover, {reportAction, reportID}) => { const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); @@ -302,15 +302,15 @@ const ContextMenuActions: ContextMenuAction[] = [ isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.joinThread', icon: Expensicons.Bell, - shouldShow: ({reportAction, isArchivedRoom, isThreadFirstChat}) => { + shouldShow: ({reportAction, isArchivedRoom, isThreadReportParentAction}) => { const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); - const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, isThreadFirstChat); + const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, isThreadReportParentAction); const subscribed = childReportNotificationPreference !== 'hidden'; const isWhisperAction = ReportActionsUtils.isWhisperAction(reportAction) || ReportActionsUtils.isActionableTrackExpense(reportAction); const isExpenseReportAction = ReportActionsUtils.isMoneyRequestAction(reportAction) || ReportActionsUtils.isReportPreviewAction(reportAction); const isTaskAction = ReportActionsUtils.isCreatedTaskReportAction(reportAction); - return !subscribed && !isWhisperAction && !isTaskAction && !isExpenseReportAction && !isThreadFirstChat && (shouldDisplayThreadReplies || (!isDeletedAction && !isArchivedRoom)); + return !subscribed && !isWhisperAction && !isTaskAction && !isExpenseReportAction && !isThreadReportParentAction && (shouldDisplayThreadReplies || (!isDeletedAction && !isArchivedRoom)); }, onPress: (closePopover, {reportAction, reportID}) => { const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction); diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx index a23a0a1be47d..1d7311ef526f 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx @@ -62,7 +62,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef([]); const [shoudSwitchPositionIfOverflow, setShoudSwitchPositionIfOverflow] = useState(false); @@ -173,7 +173,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef {}, isOverflowMenu = false, - isThreadFirstChatParam = false, + isThreadReportParentActionParam = false, ) => { const {pageX = 0, pageY = 0} = extractPointerEvent(event); contextMenuAnchorRef.current = contextMenuAnchor; @@ -222,7 +222,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef void, isOverflowMenu?: boolean, - isThreadFirstChat?: boolean, + isThreadReportParentAction?: boolean, ) => void; type ReportActionContextMenu = { @@ -119,7 +119,7 @@ function showContextMenu( shouldCloseOnTarget = false, setIsEmojiPickerActive = () => {}, isOverflowMenu = false, - isThreadFirstChat = false, + isThreadReportParentAction = false, ) { if (!contextMenuRef.current) { return; @@ -144,7 +144,7 @@ function showContextMenu( shouldCloseOnTarget, setIsEmojiPickerActive, isOverflowMenu, - isThreadFirstChat, + isThreadReportParentAction, ); }; diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 74377aa5dfbb..768ffcf1929f 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -132,7 +132,7 @@ type ReportActionItemProps = { isFirstVisibleReportAction: boolean; /** True if this is the first chat preview of a thread */ - isThreadFirstChat?: boolean; + isThreadReportParentAction?: boolean; /** IF the thread divider line will be used */ shouldUseThreadDividerLine?: boolean; @@ -155,7 +155,7 @@ function ReportActionItem({ shouldShowSubscriptAvatar = false, onPress = undefined, isFirstVisibleReportAction = false, - isThreadFirstChat = false, + isThreadReportParentAction = false, shouldUseThreadDividerLine = false, shouldDisplayContextMenu = true, parentReportActionForTransactionThread, @@ -358,7 +358,7 @@ function ReportActionItem({ false, setIsEmojiPickerActive as () => void, undefined, - isThreadFirstChat, + isThreadReportParentAction, ); }, [ @@ -371,7 +371,7 @@ function ReportActionItem({ disabledActions, isArchivedRoom, isChronosReport, - isThreadFirstChat, + isThreadReportParentAction, ], ); @@ -798,7 +798,7 @@ function ReportActionItem({ } const numberOfThreadReplies = action.childVisibleActionCount ?? 0; - const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(action, isThreadFirstChat); + const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(action, isThreadReportParentAction); const oldestFourAccountIDs = action.childOldestFourAccountIDs ?.split(',') @@ -984,7 +984,7 @@ function ReportActionItem({ displayAsGroup={displayAsGroup} disabledActions={disabledActions} isVisible={hovered && draftMessage === undefined && !hasErrors} - isThreadFirstChat={isThreadFirstChat} + isThreadReportParentAction={isThreadReportParentAction} draftMessage={draftMessage} isChronosReport={isChronosReport} checkIfContextMenuActive={toggleContextMenuFromActiveReportAction} diff --git a/src/pages/home/report/ReportActionItemParentAction.tsx b/src/pages/home/report/ReportActionItemParentAction.tsx index 1e386d982d70..3f4ae35717de 100644 --- a/src/pages/home/report/ReportActionItemParentAction.tsx +++ b/src/pages/home/report/ReportActionItemParentAction.tsx @@ -159,7 +159,7 @@ function ReportActionItemParentAction({ index={index} isFirstVisibleReportAction={isFirstVisibleReportAction} shouldUseThreadDividerLine={shouldUseThreadDividerLine} - isThreadFirstChat + isThreadReportParentAction /> )} From cfc41bc42ba95bd6928d4e2456c460f6366e0c43 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 21 Nov 2024 13:27:05 +0800 Subject: [PATCH 09/10] update comment --- .../home/report/ContextMenu/BaseReportActionContextMenu.tsx | 5 ++++- src/pages/home/report/ReportActionItem.tsx | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index ffb38365fb53..1d7deea43a04 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -76,7 +76,10 @@ type BaseReportActionContextMenuProps = { /** Flag to check if the chat is unread in the LHN. Used for the Mark as Read/Unread action */ isUnreadChat?: boolean; - /** Is the action the first chat of a thread, in other words the parent action of a thread report */ + /** + * Is the action a thread's parent reportAction viewed from within the thread report? + * It will be false if we're viewing the same parent report action from the report it belongs to rather than the thread. + */ isThreadReportParentAction?: boolean; /** Content Ref */ diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 768ffcf1929f..399550069c0a 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -131,7 +131,10 @@ type ReportActionItemProps = { /** If this is the first visible report action */ isFirstVisibleReportAction: boolean; - /** True if this is the first chat preview of a thread */ + /** + * Is the action a thread's parent reportAction viewed from within the thread report? + * It will be false if we're viewing the same parent report action from the report it belongs to rather than the thread. + */ isThreadReportParentAction?: boolean; /** IF the thread divider line will be used */ From 39acd924ac61226b15055703c4b2aabf60920c38 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 21 Nov 2024 13:27:09 +0800 Subject: [PATCH 10/10] prettier --- src/libs/ReportUtils.ts | 4 +--- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 9 ++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b02e08b85dd4..42c84d7fa20d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7270,9 +7270,7 @@ function getOriginalReportID(reportID: string, reportAction: OnyxInputOrEntry { const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction);