Skip to content

Commit ea893a7

Browse files
authored
Merge pull request Expensify#65179 from thelullabyy/feat/64933/refactor-show-context-menu-context
MED Refactor ShowContextMenuContext to pass isReportArchived instead of rNVPs
2 parents 07df224 + 2547aec commit ea893a7

15 files changed

Lines changed: 27 additions & 74 deletions

File tree

src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP
3535

3636
return (
3737
<ShowContextMenuContext.Consumer>
38-
{({anchor, report, reportNameValuePairs, action, checkIfContextMenuActive, isDisabled, shouldDisplayContextMenu}) => (
38+
{({anchor, report, isReportArchived, action, checkIfContextMenuActive, isDisabled, shouldDisplayContextMenu}) => (
3939
<PressableWithoutFeedback
4040
style={[style, (isOffline || !sourceID) && styles.cursorDefault]}
4141
onPress={() => {
@@ -51,14 +51,7 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP
5151
if (isDisabled || !shouldDisplayContextMenu) {
5252
return;
5353
}
54-
showContextMenuForReport(
55-
event,
56-
anchor,
57-
report?.reportID,
58-
action,
59-
checkIfContextMenuActive,
60-
isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived),
61-
);
54+
showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, isReportArchived));
6255
}}
6356
shouldUseHapticsOnLongPress
6457
accessibilityLabel={displayName}

src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function ImageRenderer({tnode}: ImageRendererProps) {
101101
thumbnailImageComponent
102102
) : (
103103
<ShowContextMenuContext.Consumer>
104-
{({onShowContextMenu, anchor, report, reportNameValuePairs, action, checkIfContextMenuActive, isDisabled, shouldDisplayContextMenu}) => (
104+
{({onShowContextMenu, anchor, report, isReportArchived, action, checkIfContextMenuActive, isDisabled, shouldDisplayContextMenu}) => (
105105
<AttachmentContext.Consumer>
106106
{({reportID, accountID, type}) => (
107107
<PressableWithoutFocus
@@ -129,14 +129,7 @@ function ImageRenderer({tnode}: ImageRendererProps) {
129129
return;
130130
}
131131
return onShowContextMenu(() =>
132-
showContextMenuForReport(
133-
event,
134-
anchor,
135-
report?.reportID,
136-
action,
137-
checkIfContextMenuActive,
138-
isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived),
139-
),
132+
showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, isReportArchived)),
140133
);
141134
}}
142135
isNested

src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,15 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona
7070

7171
return (
7272
<ShowContextMenuContext.Consumer>
73-
{({onShowContextMenu, anchor, report, reportNameValuePairs, action, checkIfContextMenuActive, isDisabled, shouldDisplayContextMenu}) => (
73+
{({onShowContextMenu, anchor, report, isReportArchived, action, checkIfContextMenuActive, isDisabled, shouldDisplayContextMenu}) => (
7474
<Text
7575
suppressHighlighting
7676
onLongPress={(event) => {
7777
if (isDisabled || !shouldDisplayContextMenu) {
7878
return;
7979
}
8080
return onShowContextMenu(() =>
81-
showContextMenuForReport(
82-
event,
83-
anchor,
84-
report?.reportID,
85-
action,
86-
checkIfContextMenuActive,
87-
isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived),
88-
),
81+
showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, isReportArchived)),
8982
);
9083
}}
9184
onPress={(event) => {

src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function PreRenderer({TDefaultRenderer, onPressIn, onPressOut, onLongPress, ...d
5252
return (
5353
<View style={isLast ? styles.mt2 : styles.mv2}>
5454
<ShowContextMenuContext.Consumer>
55-
{({onShowContextMenu, anchor, report, reportNameValuePairs, action, checkIfContextMenuActive, isDisabled, shouldDisplayContextMenu}) => (
55+
{({onShowContextMenu, anchor, report, isReportArchived, action, checkIfContextMenuActive, isDisabled, shouldDisplayContextMenu}) => (
5656
<PressableWithoutFeedback
5757
onPress={onPressIn ?? (() => {})}
5858
onPressIn={onPressIn}
@@ -62,14 +62,7 @@ function PreRenderer({TDefaultRenderer, onPressIn, onPressOut, onLongPress, ...d
6262
if (isDisabled || !shouldDisplayContextMenu) {
6363
return;
6464
}
65-
return showContextMenuForReport(
66-
event,
67-
anchor,
68-
report?.reportID,
69-
action,
70-
checkIfContextMenuActive,
71-
isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived),
72-
);
65+
return showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, isReportArchived));
7366
});
7467
}}
7568
shouldUseHapticsOnLongPress

src/components/LHNOptionsList/LHNOptionsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
212212
}
213213
: null;
214214
}
215-
const lastMessageTextFromReport = getLastMessageTextForReport(item, lastActorDetails, itemPolicy, itemReportNameValuePairs);
215+
const lastMessageTextFromReport = getLastMessageTextForReport(item, lastActorDetails, itemPolicy, !!itemReportNameValuePairs?.private_isArchived);
216216

217217
const shouldShowRBRorGBRTooltip = firstReportIDWithGBRorRBR === reportID;
218218

src/components/MoneyRequestConfirmationListFooter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function MoneyRequestConfirmationListFooter({
338338
() => ({
339339
anchor: null,
340340
report: undefined,
341-
reportNameValuePairs: undefined,
341+
isReportArchived: false,
342342
action: undefined,
343343
checkIfContextMenuActive: () => {},
344344
onShowContextMenu: () => {},

src/components/ReportActionItem/TaskView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
7373
() => ({
7474
anchor: null,
7575
report,
76-
reportNameValuePairs: undefined,
76+
isReportArchived: false,
7777
action,
7878
transactionThreadReport: undefined,
7979
checkIfContextMenuActive: () => {},

src/components/ShowContextMenuContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {getOriginalReportID} from '@libs/ReportUtils';
77
import {showContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
88
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
99
import CONST from '@src/CONST';
10-
import type {Report, ReportAction, ReportNameValuePairs} from '@src/types/onyx';
10+
import type {Report, ReportAction} from '@src/types/onyx';
1111

1212
type ShowContextMenuContextProps = {
1313
anchor: ContextMenuAnchor;
1414
report: OnyxEntry<Report>;
15-
reportNameValuePairs: OnyxEntry<ReportNameValuePairs>;
15+
isReportArchived: boolean;
1616
action: OnyxEntry<ReportAction>;
1717
transactionThreadReport?: OnyxEntry<Report>;
1818
checkIfContextMenuActive: () => void;
@@ -25,7 +25,7 @@ const ShowContextMenuContext = createContext<ShowContextMenuContextProps>({
2525
anchor: null,
2626
onShowContextMenu: (callback) => callback(),
2727
report: undefined,
28-
reportNameValuePairs: undefined,
28+
isReportArchived: false,
2929
action: undefined,
3030
transactionThreadReport: undefined,
3131
checkIfContextMenuActive: () => {},

src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel, isDele
4545
)}
4646
{!isDeleted ? (
4747
<ShowContextMenuContext.Consumer>
48-
{({anchor, report, reportNameValuePairs, action, checkIfContextMenuActive, isDisabled, onShowContextMenu, shouldDisplayContextMenu}) => (
48+
{({anchor, report, isReportArchived, action, checkIfContextMenuActive, isDisabled, onShowContextMenu, shouldDisplayContextMenu}) => (
4949
<PressableWithoutFeedback
5050
style={[styles.videoThumbnailContainer]}
5151
accessibilityLabel={accessibilityLabel}
@@ -58,14 +58,7 @@ function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel, isDele
5858
return;
5959
}
6060
onShowContextMenu(() => {
61-
showContextMenuForReport(
62-
event,
63-
anchor,
64-
report?.reportID,
65-
action,
66-
checkIfContextMenuActive,
67-
isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived),
68-
);
61+
showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, isReportArchived));
6962
});
7063
}}
7164
shouldUseHapticsOnLongPress

src/libs/OptionsListUtils.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ import {
125125
getUpgradeWorkspaceMessage,
126126
hasIOUWaitingOnCurrentUserBankAccount,
127127
isArchivedNonExpenseReport,
128-
isArchivedReport,
129128
isChatThread,
130129
isDefaultRoom,
131130
isDM,
@@ -717,20 +716,15 @@ function hasHiddenDisplayNames(accountIDs: number[]) {
717716
/**
718717
* Get the last message text from the report directly or from other sources for special cases.
719718
*/
720-
function getLastMessageTextForReport(
721-
report: OnyxEntry<Report>,
722-
lastActorDetails: Partial<PersonalDetails> | null,
723-
policy?: OnyxEntry<Policy>,
724-
reportNameValuePairs?: OnyxInputOrEntry<ReportNameValuePairs>,
725-
): string {
719+
function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails: Partial<PersonalDetails> | null, policy?: OnyxEntry<Policy>, isReportArchived = false): string {
726720
const reportID = report?.reportID;
727721
const lastReportAction = reportID ? lastVisibleReportActions[reportID] : undefined;
728722

729723
// some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action
730724
const lastOriginalReportAction = reportID ? lastReportActions[reportID] : undefined;
731725
let lastMessageTextFromReport = '';
732726

733-
if (isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived)) {
727+
if (isArchivedNonExpenseReport(report, isReportArchived)) {
734728
const archiveReason =
735729
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
736730
(isClosedAction(lastOriginalReportAction) && getOriginalMessage(lastOriginalReportAction)?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT;
@@ -858,7 +852,7 @@ function getLastMessageTextForReport(
858852
// we do not want to show report closed in LHN for non archived report so use getReportLastMessage as fallback instead of lastMessageText from report
859853
if (
860854
reportID &&
861-
!isArchivedReport(reportNameValuePairs) &&
855+
!isReportArchived &&
862856
(report.lastActionType === CONST.REPORT.ACTIONS.TYPE.CLOSED || (lastOriginalReportAction?.reportActionID && isDeletedAction(lastOriginalReportAction)))
863857
) {
864858
return lastMessageTextFromReport || (getReportLastMessage(reportID).lastMessageText ?? '');
@@ -973,7 +967,7 @@ function createOption(accountIDs: number[], personalDetails: OnyxInputOrEntry<Pe
973967
const lastActorAccountID = report.lastActorAccountID || lastAction?.actorAccountID;
974968
const lastActorDetails = lastActorAccountID ? (personalDetails?.[lastActorAccountID] ?? null) : null;
975969
const lastActorDisplayName = getLastActorDisplayName(lastActorDetails);
976-
const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails, undefined, reportNameValuePairs);
970+
const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails, undefined, !!result.private_isArchived);
977971
let lastMessageText = lastMessageTextFromReport;
978972

979973
const shouldDisplayLastActorName =

0 commit comments

Comments
 (0)