From 8b44ad04f5daa2cd3b22bdb819da2170b8355ae3 Mon Sep 17 00:00:00 2001 From: Waseem Ahmed Date: Fri, 27 Sep 2024 17:28:48 +0530 Subject: [PATCH 1/3] hide hold option for invoices --- src/libs/ReportUtils.ts | 7 +++++++ .../report/ContextMenu/BaseReportActionContextMenu.tsx | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 684274bc0079..a8b9ce65e252 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3149,6 +3149,13 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry) return {canHoldRequest: false, canUnholdRequest: false}; } + if (isInvoiceReport(moneyRequestReport)) { + return { + canHoldRequest: false, + canUnholdRequest: false, + }; + } + const isRequestSettled = isSettled(moneyRequestReport?.reportID); const isApproved = isReportApproved(moneyRequestReport); const transactionID = moneyRequestReport ? ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID : 0; diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 644adfdd66fc..31d301dc8293 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -175,9 +175,10 @@ function BaseReportActionContextMenu({ const isMoneyRequest = useMemo(() => ReportUtils.isMoneyRequest(childReport), [childReport]); const isTrackExpenseReport = ReportUtils.isTrackExpenseReport(childReport); const isSingleTransactionView = isMoneyRequest || isTrackExpenseReport; - const isMoneyRequestOrReport = isMoneyRequestReport || isInvoiceReport || isSingleTransactionView; + const isMoneyRequestOrReport = isMoneyRequestReport || isSingleTransactionView; - const areHoldRequirementsMet = isMoneyRequestOrReport && !ReportUtils.isArchivedRoom(transactionThreadReportID ? childReport : parentReport, parentReportNameValuePairs); + const areHoldRequirementsMet = + !isInvoiceReport && isMoneyRequestOrReport && !ReportUtils.isArchivedRoom(transactionThreadReportID ? childReport : parentReport, parentReportNameValuePairs); const originalReportID = useMemo(() => ReportUtils.getOriginalReportID(reportID, reportAction), [reportID, reportAction]); From a6445bd3743e1465274f61d1023004a65bd7fa80 Mon Sep 17 00:00:00 2001 From: Waseem Ahmed Date: Sat, 5 Oct 2024 09:19:24 +0530 Subject: [PATCH 2/3] fix lint errors based on updated eslint rules --- .../BaseReportActionContextMenu.tsx | 67 ++++++------------- 1 file changed, 19 insertions(+), 48 deletions(-) diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 31d301dc8293..8cd9c6179eda 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -5,7 +5,7 @@ import {InteractionManager, View} from 'react-native'; // eslint-disable-next-line no-restricted-imports import type {GestureResponderEvent, Text as RNText, View as ViewType} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {useOnyx, withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {ContextMenuItemHandle} from '@components/ContextMenuItem'; import ContextMenuItem from '@components/ContextMenuItem'; import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal'; @@ -23,25 +23,14 @@ import shouldEnableContextMenuEnterShortcut from '@libs/shouldEnableContextMenuE import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Beta, ReportAction, ReportActions, Transaction} from '@src/types/onyx'; +import type {ReportAction} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type {ContextMenuAction, ContextMenuActionPayload} from './ContextMenuActions'; import ContextMenuActions from './ContextMenuActions'; import type {ContextMenuAnchor, ContextMenuType} from './ReportActionContextMenu'; import {hideContextMenu, showContextMenu} from './ReportActionContextMenu'; -type BaseReportActionContextMenuOnyxProps = { - /** Beta features list */ - betas: OnyxEntry; - - /** All of the actions of the report */ - reportActions: OnyxEntry; - - /** The transaction linked to the report action this context menu is attached to. */ - transaction: OnyxEntry; -}; - -type BaseReportActionContextMenuProps = BaseReportActionContextMenuOnyxProps & { +type BaseReportActionContextMenuProps = { /** The ID of the report this report action is attached to. */ reportID: string; @@ -114,10 +103,8 @@ function BaseReportActionContextMenu({ selection = '', draftMessage = '', reportActionID, - transaction, reportID, - betas, - reportActions, + originalReportID, checkIfContextMenuActive, disabledActions = [], setIsEmojiPickerActive, @@ -132,6 +119,9 @@ function BaseReportActionContextMenu({ const {isProduction} = useEnvironment(); const threedotRef = useRef(null); + const [betas] = useOnyx(`${ONYXKEYS.BETAS}`); + const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, {canEvict: false}); + const reportAction: OnyxEntry = useMemo(() => { if (isEmptyObject(reportActions) || reportActionID === '0' || reportActionID === '-1') { return; @@ -139,6 +129,8 @@ function BaseReportActionContextMenu({ return reportActions[reportActionID]; }, [reportActions, reportActionID]); + const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${(reportAction && ReportActionsUtils.getLinkedTransactionID(reportAction)) ?? -1}`); + const sourceID = ReportUtils.getSourceIDFromReportAction(reportAction); const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`); @@ -180,8 +172,6 @@ function BaseReportActionContextMenu({ const areHoldRequirementsMet = !isInvoiceReport && isMoneyRequestOrReport && !ReportUtils.isArchivedRoom(transactionThreadReportID ? childReport : parentReport, parentReportNameValuePairs); - const originalReportID = useMemo(() => ReportUtils.getOriginalReportID(reportID, reportAction), [reportID, reportAction]); - const shouldEnableArrowNavigation = !isMini && (isVisible || shouldKeepOpen); let filteredContextMenuActions = ContextMenuActions.filter( (contextAction) => @@ -359,35 +349,16 @@ function BaseReportActionContextMenu({ ); } -export default withOnyx({ - betas: { - key: ONYXKEYS.BETAS, - }, - reportActions: { - key: ({originalReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, - canEvict: false, - }, - transaction: { - key: ({reportActions, reportActionID}) => { - const reportAction = reportActions?.[reportActionID]; - return `${ONYXKEYS.COLLECTION.TRANSACTION}${(reportAction && ReportActionsUtils.getLinkedTransactionID(reportAction)) ?? -1}`; - }, - }, -})( - memo(BaseReportActionContextMenu, (prevProps, nextProps) => { - const {reportActions: prevReportActions, ...prevPropsWithoutReportActions} = prevProps; - const {reportActions: nextReportActions, ...nextPropsWithoutReportActions} = nextProps; - - const prevReportAction = prevReportActions?.[prevProps.reportActionID] ?? ''; - const nextReportAction = nextReportActions?.[nextProps.reportActionID] ?? ''; - - // We only want to re-render when the report action that is attached to is changed - if (prevReportAction !== nextReportAction) { - return false; - } +export default memo(BaseReportActionContextMenu, (prevProps, nextProps) => { + const {reportActionID: prevReportActionID, ...prevPropsWithoutReportActions} = prevProps; + const {reportActionID: nextReportActionID, ...nextPropsWithoutReportActions} = nextProps; + + // We only want to re-render when the report action that is attached to is changed + if (prevReportActionID !== nextReportActionID) { + return false; + } - return lodashIsEqual(prevPropsWithoutReportActions, nextPropsWithoutReportActions); - }), -); + return lodashIsEqual(prevPropsWithoutReportActions, nextPropsWithoutReportActions); +}); export type {BaseReportActionContextMenuProps}; From 183b8f56599d6fe560cb6c10e3ae964b97660589 Mon Sep 17 00:00:00 2001 From: Waseem Ahmed Date: Mon, 7 Oct 2024 17:10:12 +0530 Subject: [PATCH 3/3] revert withOnyx changes --- .../BaseReportActionContextMenu.tsx | 67 +++++++++++++------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 8cd9c6179eda..31d301dc8293 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -5,7 +5,7 @@ import {InteractionManager, View} from 'react-native'; // eslint-disable-next-line no-restricted-imports import type {GestureResponderEvent, Text as RNText, View as ViewType} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {useOnyx} from 'react-native-onyx'; +import {useOnyx, withOnyx} from 'react-native-onyx'; import type {ContextMenuItemHandle} from '@components/ContextMenuItem'; import ContextMenuItem from '@components/ContextMenuItem'; import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal'; @@ -23,14 +23,25 @@ import shouldEnableContextMenuEnterShortcut from '@libs/shouldEnableContextMenuE import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {ReportAction} from '@src/types/onyx'; +import type {Beta, ReportAction, ReportActions, Transaction} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type {ContextMenuAction, ContextMenuActionPayload} from './ContextMenuActions'; import ContextMenuActions from './ContextMenuActions'; import type {ContextMenuAnchor, ContextMenuType} from './ReportActionContextMenu'; import {hideContextMenu, showContextMenu} from './ReportActionContextMenu'; -type BaseReportActionContextMenuProps = { +type BaseReportActionContextMenuOnyxProps = { + /** Beta features list */ + betas: OnyxEntry; + + /** All of the actions of the report */ + reportActions: OnyxEntry; + + /** The transaction linked to the report action this context menu is attached to. */ + transaction: OnyxEntry; +}; + +type BaseReportActionContextMenuProps = BaseReportActionContextMenuOnyxProps & { /** The ID of the report this report action is attached to. */ reportID: string; @@ -103,8 +114,10 @@ function BaseReportActionContextMenu({ selection = '', draftMessage = '', reportActionID, + transaction, reportID, - originalReportID, + betas, + reportActions, checkIfContextMenuActive, disabledActions = [], setIsEmojiPickerActive, @@ -119,9 +132,6 @@ function BaseReportActionContextMenu({ const {isProduction} = useEnvironment(); const threedotRef = useRef(null); - const [betas] = useOnyx(`${ONYXKEYS.BETAS}`); - const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, {canEvict: false}); - const reportAction: OnyxEntry = useMemo(() => { if (isEmptyObject(reportActions) || reportActionID === '0' || reportActionID === '-1') { return; @@ -129,8 +139,6 @@ function BaseReportActionContextMenu({ return reportActions[reportActionID]; }, [reportActions, reportActionID]); - const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${(reportAction && ReportActionsUtils.getLinkedTransactionID(reportAction)) ?? -1}`); - const sourceID = ReportUtils.getSourceIDFromReportAction(reportAction); const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`); @@ -172,6 +180,8 @@ function BaseReportActionContextMenu({ const areHoldRequirementsMet = !isInvoiceReport && isMoneyRequestOrReport && !ReportUtils.isArchivedRoom(transactionThreadReportID ? childReport : parentReport, parentReportNameValuePairs); + const originalReportID = useMemo(() => ReportUtils.getOriginalReportID(reportID, reportAction), [reportID, reportAction]); + const shouldEnableArrowNavigation = !isMini && (isVisible || shouldKeepOpen); let filteredContextMenuActions = ContextMenuActions.filter( (contextAction) => @@ -349,16 +359,35 @@ function BaseReportActionContextMenu({ ); } -export default memo(BaseReportActionContextMenu, (prevProps, nextProps) => { - const {reportActionID: prevReportActionID, ...prevPropsWithoutReportActions} = prevProps; - const {reportActionID: nextReportActionID, ...nextPropsWithoutReportActions} = nextProps; - - // We only want to re-render when the report action that is attached to is changed - if (prevReportActionID !== nextReportActionID) { - return false; - } +export default withOnyx({ + betas: { + key: ONYXKEYS.BETAS, + }, + reportActions: { + key: ({originalReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, + canEvict: false, + }, + transaction: { + key: ({reportActions, reportActionID}) => { + const reportAction = reportActions?.[reportActionID]; + return `${ONYXKEYS.COLLECTION.TRANSACTION}${(reportAction && ReportActionsUtils.getLinkedTransactionID(reportAction)) ?? -1}`; + }, + }, +})( + memo(BaseReportActionContextMenu, (prevProps, nextProps) => { + const {reportActions: prevReportActions, ...prevPropsWithoutReportActions} = prevProps; + const {reportActions: nextReportActions, ...nextPropsWithoutReportActions} = nextProps; + + const prevReportAction = prevReportActions?.[prevProps.reportActionID] ?? ''; + const nextReportAction = nextReportActions?.[nextProps.reportActionID] ?? ''; + + // We only want to re-render when the report action that is attached to is changed + if (prevReportAction !== nextReportAction) { + return false; + } - return lodashIsEqual(prevPropsWithoutReportActions, nextPropsWithoutReportActions); -}); + return lodashIsEqual(prevPropsWithoutReportActions, nextPropsWithoutReportActions); + }), +); export type {BaseReportActionContextMenuProps};