-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add debug option to LHN context menu #50519
Changes from all commits
6379568
b48302e
7665b16
e73413b
642069b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<Beta[]>; | ||
|
||
/** All of the actions of the report */ | ||
reportActions: OnyxEntry<ReportActions>; | ||
|
||
/** The transaction linked to the report action this context menu is attached to. */ | ||
transaction: OnyxEntry<Transaction>; | ||
}; | ||
|
||
type BaseReportActionContextMenuProps = BaseReportActionContextMenuOnyxProps & { | ||
type BaseReportActionContextMenuProps = { | ||
/** The ID of the report this report action is attached to. */ | ||
reportID: string; | ||
|
||
|
@@ -114,10 +103,7 @@ function BaseReportActionContextMenu({ | |
selection = '', | ||
draftMessage = '', | ||
reportActionID, | ||
transaction, | ||
reportID, | ||
betas, | ||
reportActions, | ||
checkIfContextMenuActive, | ||
disabledActions = [], | ||
setIsEmojiPickerActive, | ||
|
@@ -131,6 +117,13 @@ function BaseReportActionContextMenu({ | |
const {isOffline} = useNetwork(); | ||
const {isProduction} = useEnvironment(); | ||
const threedotRef = useRef<View>(null); | ||
const [betas] = useOnyx(ONYXKEYS.BETAS); | ||
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, { | ||
canEvict: false, | ||
}); | ||
const transactionID = ReportActionsUtils.getLinkedTransactionID(reportActionID, reportID); | ||
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); | ||
const [user] = useOnyx(ONYXKEYS.USER); | ||
|
||
const reportAction: OnyxEntry<ReportAction> = useMemo(() => { | ||
if (isEmptyObject(reportActions) || reportActionID === '0' || reportActionID === '-1') { | ||
|
@@ -185,22 +178,23 @@ function BaseReportActionContextMenu({ | |
let filteredContextMenuActions = ContextMenuActions.filter( | ||
(contextAction) => | ||
!disabledActions.includes(contextAction) && | ||
contextAction.shouldShow( | ||
contextAction.shouldShow({ | ||
type, | ||
reportAction, | ||
isArchivedRoom, | ||
betas, | ||
anchor, | ||
menuTarget: anchor, | ||
isChronosReport, | ||
reportID, | ||
isPinnedChat, | ||
isUnreadChat, | ||
!!isOffline, | ||
isOffline: !!isOffline, | ||
isMini, | ||
isProduction, | ||
moneyRequestAction, | ||
areHoldRequirementsMet, | ||
), | ||
user, | ||
}), | ||
); | ||
|
||
if (isMini) { | ||
|
@@ -358,35 +352,6 @@ function BaseReportActionContextMenu({ | |
); | ||
} | ||
|
||
export default withOnyx<BaseReportActionContextMenuProps, BaseReportActionContextMenuOnyxProps>({ | ||
betas: { | ||
key: ONYXKEYS.BETAS, | ||
}, | ||
reportActions: { | ||
key: ({originalReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, | ||
canEvict: false, | ||
pac-guerreiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
transaction: { | ||
key: ({reportActions, reportActionID}) => { | ||
const reportAction = reportActions?.[reportActionID]; | ||
return `${ONYXKEYS.COLLECTION.TRANSACTION}${(reportAction && ReportActionsUtils.getLinkedTransactionID(reportAction)) ?? -1}`; | ||
}, | ||
}, | ||
})( | ||
memo(BaseReportActionContextMenu, (prevProps, nextProps) => { | ||
pac-guerreiro marked this conversation as resolved.
Show resolved
Hide resolved
pac-guerreiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; | ||
} | ||
|
||
Comment on lines
-383
to
-387
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pac-guerreiro I am having trouble with this place. It seems There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pac-guerreiro note that we implemented a customized function instead of lodashIsEqual function only in memo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only want to make sure our change doesn't break any old behavior There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The component will be re-rendered if |
||
return lodashIsEqual(prevPropsWithoutReportActions, nextPropsWithoutReportActions); | ||
}), | ||
); | ||
export default memo(BaseReportActionContextMenu, lodashIsEqual); | ||
|
||
export type {BaseReportActionContextMenuProps}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes caused a regression, details here.