Skip to content
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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 16 additions & 51 deletions src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;

Expand Down Expand Up @@ -114,10 +103,7 @@ function BaseReportActionContextMenu({
selection = '',
draftMessage = '',
reportActionID,
transaction,
reportID,
betas,
reportActions,
checkIfContextMenuActive,
disabledActions = [],
setIsEmojiPickerActive,
Expand All @@ -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);
Copy link
Member

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.

const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
const [user] = useOnyx(ONYXKEYS.USER);

const reportAction: OnyxEntry<ReportAction> = useMemo(() => {
if (isEmptyObject(reportActions) || reportActionID === '0' || reportActionID === '-1') {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pac-guerreiro I am having trouble with this place. It seems lodashIsEqual(prevPropsWithoutReportActions, nextPropsWithoutReportActions); can't detect the different between prevReportAction and nextReportAction

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

@pac-guerreiro pac-guerreiro Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DylanDylann

reportActions was injected into the component by withOnyx as a prop, but I removed withOnyx and reportActions is now returned by useOnyx, so it doesn't make sense to do this check anymore inside memo.

The component will be re-rendered if useOnyx is triggered by some change to reportActions, so I think the old behaviour should be the same

return lodashIsEqual(prevPropsWithoutReportActions, nextPropsWithoutReportActions);
}),
);
export default memo(BaseReportActionContextMenu, lodashIsEqual);

export type {BaseReportActionContextMenuProps};
Loading
Loading