Skip to content
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
4 changes: 3 additions & 1 deletion src/components/ShowContextMenuContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import * as ReportActionContextMenu from '../pages/home/report/ContextMenu/ReportActionContextMenu';
import * as ContextMenuActions from '../pages/home/report/ContextMenu/ContextMenuActions';
import * as DeviceCapabilities from '../libs/DeviceCapabilities';
import * as ReportUtils from '../libs/ReportUtils';

const ShowContextMenuContext = React.createContext({
anchor: null,
Expand Down Expand Up @@ -32,7 +33,8 @@ function showContextMenuForReport(event, anchor, reportID, action, checkIfContex
'',
anchor,
reportID,
action,
action.reportActionID,
ReportUtils.getOriginalReportID(reportID, action),
'',
checkIfContextMenuActive,
checkIfContextMenuActive,
Expand Down
50 changes: 35 additions & 15 deletions src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, {useState} from 'react';
import React, {useMemo, useState, memo} from 'react';
import {InteractionManager, View} from 'react-native';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import getReportActionContextMenuStyles from '../../../../styles/getReportActionContextMenuStyles';
import ContextMenuItem from '../../../../components/ContextMenuItem';
import {propTypes as genericReportActionContextMenuPropTypes, defaultProps as GenericReportActionContextMenuDefaultProps} from './genericReportActionContextMenuPropTypes';
Expand All @@ -12,6 +14,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../../../compo
import {withBetas} from '../../../../components/OnyxProvider';
import * as Session from '../../../../libs/actions/Session';
import {hideContextMenu} from './ReportActionContextMenu';
import ONYXKEYS from '../../../../ONYXKEYS';

const propTypes = {
/** String representing the context menu type [LINK, REPORT_ACTION] which controls context menu choices */
Expand Down Expand Up @@ -44,18 +47,14 @@ const defaultProps = {
function BaseReportActionContextMenu(props) {
const [shouldKeepOpen, setShouldKeepOpen] = useState(false);
const wrapperStyle = getReportActionContextMenuStyles(props.isMini, props.isSmallScreenWidth);

const reportAction = useMemo(() => {
if (_.isEmpty(props.reportActions) || props.reportActionID === '0') return {};
return props.reportActions[props.reportActionID] || {};
}, [props.reportActions, props.reportActionID]);

const shouldShowFilter = (contextAction) =>
contextAction.shouldShow(
props.type,
props.reportAction,
props.isArchivedRoom,
props.betas,
props.anchor,
props.isChronosReport,
props.reportID,
props.isPinnedChat,
props.isUnreadChat,
);
contextAction.shouldShow(props.type, reportAction, props.isArchivedRoom, props.betas, props.anchor, props.isChronosReport, props.reportID, props.isPinnedChat, props.isUnreadChat);

/**
* Checks if user is anonymous. If true and the action doesn't accept for anonymous user, hides the context menu and
Expand Down Expand Up @@ -85,7 +84,7 @@ function BaseReportActionContextMenu(props) {
{_.map(_.filter(ContextMenuActions, shouldShowFilter), (contextAction) => {
const closePopup = !props.isMini;
const payload = {
reportAction: props.reportAction,
reportAction,
reportID: props.reportID,
draftMessage: props.draftMessage,
selection: props.selection,
Expand All @@ -106,7 +105,7 @@ function BaseReportActionContextMenu(props) {
return (
<ContextMenuItem
icon={contextAction.icon}
text={props.translate(contextAction.textTranslateKey, {action: props.reportAction})}
text={props.translate(contextAction.textTranslateKey, {action: reportAction})}
successIcon={contextAction.successIcon}
successText={contextAction.successTextTranslateKey ? props.translate(contextAction.successTextTranslateKey) : undefined}
isMini={props.isMini}
Expand All @@ -125,4 +124,25 @@ function BaseReportActionContextMenu(props) {
BaseReportActionContextMenu.propTypes = propTypes;
BaseReportActionContextMenu.defaultProps = defaultProps;

export default compose(withLocalize, withBetas(), withWindowDimensions)(BaseReportActionContextMenu);
export default compose(
withLocalize,
withBetas(),
withWindowDimensions,
withOnyx({
reportActions: {
key: ({originalReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`,

@hungvu193 hungvu193 Sep 12, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

with thread report, this will lead to empty reportAction because it always get the reportActions of the parent.
Slack report: https://expensify.slack.com/archives/C049HHMV9SM/p1694515263690629

cc @dukenv0307 @tgolen @jjcoffee

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@hungvu193 Because the structure of the complete task is wrong. This is stored in the task report but the field means this is the parent report action #24644

canEvict: false,
},
}),
)(
memo(BaseReportActionContextMenu, (prevProps, nextProps) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please add code comments to explain why this memo is here and what it's purpose is?

const prevReportAction = lodashGet(prevProps.reportActions, prevProps.reportActionID, '');
const nextReportAction = lodashGet(nextProps.reportActions, nextProps.reportActionID, '');

// We only want to re-render when the report action that is attached to is changed
if (prevReportAction !== nextReportAction) {
return false;
}
return _.isEqual(_.omit(prevProps, 'reportActions'), _.omit(nextProps, 'reportActions'));
}),
);
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class PopoverReportActionContextMenu extends React.Component {

this.state = {
reportID: '0',
reportAction: {},
reportActionID: '0',
originalReportID: '0',
selection: '',
reportActionDraftMessage: '',
isPopoverVisible: false,
Expand Down Expand Up @@ -112,7 +113,7 @@ class PopoverReportActionContextMenu extends React.Component {
* @return {Boolean}
*/
isActiveReportAction(actionID) {
return Boolean(actionID) && this.state.reportAction.reportActionID === actionID;
return Boolean(actionID) && this.state.reportActionID === actionID;
}

/**
Expand All @@ -123,7 +124,8 @@ class PopoverReportActionContextMenu extends React.Component {
* @param {String} [selection] - Copied content.
* @param {Element} contextMenuAnchor - popoverAnchor
* @param {String} reportID - Active Report Id
* @param {Object} reportAction - ReportAction for ContextMenu
* @param {Object} reportActionID - ReportAction for ContextMenu
* @param {String} originalReportID - The currrent Report Id of the reportAction
* @param {String} draftMessage - ReportAction Draftmessage
* @param {Function} [onShow] - Run a callback when Menu is shown
* @param {Function} [onHide] - Run a callback when Menu is hidden
Expand All @@ -138,7 +140,8 @@ class PopoverReportActionContextMenu extends React.Component {
selection,
contextMenuAnchor,
reportID,
reportAction,
reportActionID,
originalReportID,
draftMessage,
onShow = () => {},
onHide = () => {},
Expand Down Expand Up @@ -170,7 +173,8 @@ class PopoverReportActionContextMenu extends React.Component {
},
type,
reportID,
reportAction,
reportActionID,
originalReportID,
selection,
isPopoverVisible: true,
reportActionDraftMessage: draftMessage,
Expand Down Expand Up @@ -216,7 +220,7 @@ class PopoverReportActionContextMenu extends React.Component {
* After Popover hides, call the registered onPopoverHide & onPopoverHideActionCallback callback and reset it
*/
runAndResetOnPopoverHide() {
this.setState({reportID: '0', reportAction: {}}, () => {
this.setState({reportID: '0', reportActionID: '0', originalReportID: '0'}, () => {
this.onPopoverHide = this.runAndResetCallback(this.onPopoverHide);
this.onPopoverHideActionCallback = this.runAndResetCallback(this.onPopoverHideActionCallback);
});
Expand Down Expand Up @@ -310,7 +314,7 @@ class PopoverReportActionContextMenu extends React.Component {
isVisible
type={this.state.type}
reportID={this.state.reportID}
reportAction={this.state.reportAction}
reportActionID={this.state.reportActionID}
draftMessage={this.state.reportActionDraftMessage}
selection={this.state.selection}
isArchivedRoom={this.state.isArchivedRoom}
Expand All @@ -319,6 +323,7 @@ class PopoverReportActionContextMenu extends React.Component {
isUnreadChat={this.state.isUnreadChat}
anchor={this.contextMenuTargetNode}
contentRef={this.contentRef}
originalReportID={this.state.originalReportID}
/>
</PopoverWithMeasuredContent>
<ConfirmModal
Expand Down
10 changes: 7 additions & 3 deletions src/pages/home/report/ContextMenu/ReportActionContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function hideContextMenu(shouldDelay, onHideCallback = () => {}) {
* @param {String} [selection] - Copied content.
* @param {Element} contextMenuAnchor - popoverAnchor
* @param {String} reportID - Active Report Id
* @param {Object} reportAction - ReportAction for ContextMenu
* @param {String} reportActionID - ReportActionID for ContextMenu
* @param {String} originalReportID - The currrent Report Id of the reportAction
* @param {String} draftMessage - ReportAction Draftmessage
* @param {Function} [onShow=() => {}] - Run a callback when Menu is shown
* @param {Function} [onHide=() => {}] - Run a callback when Menu is hidden
Expand All @@ -54,7 +55,8 @@ function showContextMenu(
selection,
contextMenuAnchor,
reportID = '0',
reportAction = {},
reportActionID = '0',
originalReportID = '0',
draftMessage = '',
onShow = () => {},
onHide = () => {},
Expand All @@ -72,13 +74,15 @@ function showContextMenu(
hideContextMenu();
contextMenuRef.current.runAndResetOnPopoverHide();
}

contextMenuRef.current.showContextMenu(
type,
event,
selection,
contextMenuAnchor,
reportID,
reportAction,
reportActionID,
originalReportID,
draftMessage,
onShow,
onHide,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import PropTypes from 'prop-types';
import reportActionPropTypes from '../reportActionPropTypes';

const propTypes = {
/** The ID of the report this report action is attached to. */
reportID: PropTypes.string.isRequired,

/** The report action this context menu is attached to. */
reportAction: PropTypes.shape(reportActionPropTypes).isRequired,
/** The ID of the report action this context menu is attached to. */
reportActionID: PropTypes.string.isRequired,

/** The ID of the original report from which the given reportAction is first created. */
originalReportID: PropTypes.string.isRequired,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just need a bit of clarity on this one. Can you explain (maybe with an example) what you mean when you say in your proposal "The thread first chat originalReportID and reportID is different."?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The thread first chat is the parent report action. When we pass the reportID to BaseContextMenu it is the ID of the thread report. Because now we pass the reportActionID to BaseContextMenu, we also need to pass the originalReportID that is the correct reportID of the reportAction to get the detail of the reportAction in Onyx.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Screencast.from.07-09-2023.22.07.10.webm

As you can see in the video, the first message in the thread is the thread first chat.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, I think I get what you mean now! Maybe a clearer name would be parentReportID if I understand you correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jjcoffee Other places in the App also use this name. And if the reportAction isn't the thread first chat reportID and originalReportID will be the same. So I think this name is better.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah ignore me, I see that we're using the same naming elsewhere!


/** If true, this component will be a small, row-oriented menu that displays icons but not text.
If false, this component will be a larger, column-oriented menu that displays icons alongside text in each row. */
Expand Down
10 changes: 6 additions & 4 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,16 @@ function ReportActionItem(props) {
selection,
popoverAnchorRef,
props.report.reportID,
props.action,
props.action.reportActionID,
originalReportID,
props.draftMessage,
() => {},
toggleContextMenuFromActiveReportAction,
ReportUtils.isArchivedRoom(originalReport),
ReportUtils.chatIncludesChronos(originalReport),
);
},
[props.draftMessage, props.action, props.report.reportID, toggleContextMenuFromActiveReportAction, originalReport],
[props.draftMessage, props.action, props.report.reportID, toggleContextMenuFromActiveReportAction, originalReport, originalReportID],
);

const toggleReaction = useCallback(
Expand Down Expand Up @@ -561,8 +562,9 @@ function ReportActionItem(props) {
{props.shouldDisplayNewMarker && <UnreadActionIndicator reportActionID={props.action.reportActionID} />}
<MiniReportActionContextMenu
reportID={props.report.reportID}
reportAction={props.action}
isArchivedRoom={ReportUtils.isArchivedRoom(originalReport)}
reportActionID={props.action.reportActionID}
originalReportID={originalReportID}
isArchivedRoom={ReportUtils.isArchivedRoom(props.report)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dukenv0307

We are using report to check isArchivedRoom here in the MiniReportActionContextMenu but originalReport/originalReportID to check isArchivedRoom in ReportActionContextMenu.showContextMenu. Was this a mistake or was there some logic in this?

displayAsGroup={props.displayAsGroup}
isVisible={hovered && !props.draftMessage && !hasErrors}
draftMessage={props.draftMessage}
Expand Down