Skip to content

Commit e0344f8

Browse files
committed
feat: refactor show context menu context
1 parent 0c28b4e commit e0344f8

11 files changed

Lines changed: 26 additions & 56 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/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: undefined,
342342
action: undefined,
343343
checkIfContextMenuActive: () => {},
344344
onShowContextMenu: () => {},

src/components/ReportActionItem/TaskView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
6262
const isOpen = isOpenTaskReport(report);
6363
const isCompleted = isCompletedTaskReport(report);
6464
const isParentReportArchived = useReportIsArchived(parentReport?.reportID);
65+
const isReportArchived = useReportIsArchived(report?.reportID);
6566
const isTaskModifiable = canModifyTask(report, currentUserPersonalDetails.accountID, isParentReportArchived);
6667
const isTaskActionable = canActionTask(report, currentUserPersonalDetails.accountID, parentReport, isParentReportArchived);
6768

@@ -73,15 +74,15 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
7374
() => ({
7475
anchor: null,
7576
report,
76-
reportNameValuePairs: undefined,
77+
isReportArchived,
7778
action,
7879
transactionThreadReport: undefined,
7980
checkIfContextMenuActive: () => {},
8081
isDisabled: true,
8182
onShowContextMenu: (callback: () => void) => callback(),
8283
shouldDisplayContextMenu: false,
8384
}),
84-
[report, action],
85+
[report, action, isReportArchived],
8586
);
8687

8788
const attachmentContextValue = useMemo(() => ({type: CONST.ATTACHMENT_TYPE.ONBOARDING, accountID}), [accountID]);

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: undefined,
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/pages/TransactionDuplicate/Confirmation.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
1515
import Text from '@components/Text';
1616
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1717
import useLocalize from '@hooks/useLocalize';
18+
import useReportIsArchived from '@hooks/useReportIsArchived';
1819
import useReviewDuplicatesNavigation from '@hooks/useReviewDuplicatesNavigation';
1920
import useThemeStyles from '@hooks/useThemeStyles';
2021
import Navigation from '@libs/Navigation/Navigation';
@@ -48,6 +49,7 @@ function Confirmation() {
4849
const reportAction = Object.values(reportActions ?? {}).find(
4950
(action) => ReportActionsUtils.isMoneyRequestAction(action) && ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID === reviewDuplicates?.transactionID,
5051
);
52+
const isReportArchived = useReportIsArchived(report?.reportID);
5153

5254
const transactionsMergeParams = useMemo(() => TransactionUtils.buildMergeDuplicatesParams(reviewDuplicates, transaction), [reviewDuplicates, transaction]);
5355
const isReportOwner = iouReport?.ownerAccountID === currentUserPersonalDetails?.accountID;
@@ -72,11 +74,11 @@ function Confirmation() {
7274
report,
7375
checkIfContextMenuActive: () => {},
7476
onShowContextMenu: () => {},
75-
reportNameValuePairs: undefined,
77+
isReportArchived,
7678
anchor: null,
7779
isDisabled: false,
7880
}),
79-
[report, reportAction],
81+
[report, reportAction, isReportArchived],
8082
);
8183

8284
const reportTransactionID = report?.reportID ? getTransactionID(report.reportID) : undefined;

src/pages/home/report/PureReportActionItem.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import UnreadActionIndicator from '@components/UnreadActionIndicator';
4040
import useLocalize from '@hooks/useLocalize';
4141
import usePermissions from '@hooks/usePermissions';
4242
import usePrevious from '@hooks/usePrevious';
43+
import useReportIsArchived from '@hooks/useReportIsArchived';
4344
import useResponsiveLayout from '@hooks/useResponsiveLayout';
4445
import useStyleUtils from '@hooks/useStyleUtils';
4546
import useTheme from '@hooks/useTheme';
@@ -446,6 +447,7 @@ function PureReportActionItem({
446447
const isReportActionLinked = linkedReportActionID && action.reportActionID && linkedReportActionID === action.reportActionID;
447448
const [isReportActionActive, setIsReportActionActive] = useState(!!isReportActionLinked);
448449
const isActionableWhisper = isActionableMentionWhisper(action) || isActionableTrackExpense(action) || isActionableReportMentionWhisper(action);
450+
const isReportArchived = useReportIsArchived(report?.reportID);
449451

450452
const highlightedBackgroundColorIfNeeded = useMemo(
451453
() => (isReportActionLinked ? StyleUtils.getBackgroundColorStyle(theme.messageHighlightBG) : {}),
@@ -667,15 +669,15 @@ function PureReportActionItem({
667669
() => ({
668670
anchor: popoverAnchorRef.current,
669671
report,
670-
reportNameValuePairs,
672+
isReportArchived,
671673
action,
672674
transactionThreadReport,
673675
checkIfContextMenuActive: toggleContextMenuFromActiveReportAction,
674676
onShowContextMenu: handleShowContextMenu,
675677
isDisabled: false,
676678
shouldDisplayContextMenu,
677679
}),
678-
[report, action, toggleContextMenuFromActiveReportAction, transactionThreadReport, handleShowContextMenu, reportNameValuePairs, shouldDisplayContextMenu],
680+
[report, action, toggleContextMenuFromActiveReportAction, transactionThreadReport, handleShowContextMenu, shouldDisplayContextMenu, isReportArchived],
679681
);
680682

681683
const attachmentContextValue = useMemo(() => {

0 commit comments

Comments
 (0)