From 2e6b8e6c6e69cb2fd973e76192a40efcc2e01663 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 11 May 2023 19:36:25 -0700 Subject: [PATCH 01/36] add back ReportActionItem --- src/pages/home/report/ReportActionItem.js | 386 +++++++++++----------- 1 file changed, 189 insertions(+), 197 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index b2c86d55204e..c9322747cbf6 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -1,6 +1,6 @@ import _ from 'underscore'; import lodashGet from 'lodash/get'; -import React, {Component} from 'react'; +import React, {useState, useRef, useEffect, memo, useCallback} from 'react'; import {View} from 'react-native'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; @@ -62,9 +62,6 @@ const propTypes = { /** Is this the most recent IOU Action? */ isMostRecentIOUReportAction: PropTypes.bool.isRequired, - /** Whether there is an outstanding amount in IOU */ - hasOutstandingIOU: PropTypes.bool, - /** Should we display the new marker on top of the comment? */ shouldDisplayNewMarker: PropTypes.bool.isRequired, @@ -88,151 +85,133 @@ const propTypes = { const defaultProps = { draftMessage: '', - hasOutstandingIOU: false, preferredSkinTone: CONST.EMOJI_DEFAULT_SKIN_TONE, personalDetails: {}, shouldShowSubscriptAvatar: false, }; -class ReportActionItem extends Component { - constructor(props) { - super(props); - this.popoverAnchor = undefined; - this.state = { - isContextMenuActive: ReportActionContextMenu.isActiveReportAction(props.action.reportActionID), - }; - this.checkIfContextMenuActive = this.checkIfContextMenuActive.bind(this); - this.showPopover = this.showPopover.bind(this); - this.renderItemContent = this.renderItemContent.bind(this); - this.toggleReaction = this.toggleReaction.bind(this); - } - - shouldComponentUpdate(nextProps, nextState) { - return ( - this.props.displayAsGroup !== nextProps.displayAsGroup || - this.props.draftMessage !== nextProps.draftMessage || - this.props.isMostRecentIOUReportAction !== nextProps.isMostRecentIOUReportAction || - this.props.hasOutstandingIOU !== nextProps.hasOutstandingIOU || - this.props.shouldDisplayNewMarker !== nextProps.shouldDisplayNewMarker || - !_.isEqual(this.props.action, nextProps.action) || - this.state.isContextMenuActive !== nextState.isContextMenuActive || - lodashGet(this.props.report, 'statusNum') !== lodashGet(nextProps.report, 'statusNum') || - lodashGet(this.props.report, 'stateNum') !== lodashGet(nextProps.report, 'stateNum') || - this.props.translate !== nextProps.translate - ); - } +function ReportActionItem(props) { + const [isContextMenuActive, setIsContextMenuActive] = useState(ReportActionContextMenu.isActiveReportAction(props.action.reportActionID)); + const textInputRef = useRef(); + const popoverAnchorRef = useRef(); - componentDidUpdate(prevProps) { - if (prevProps.draftMessage || !this.props.draftMessage) { + const isDraftEmpty = !props.draftMessage; + useEffect(() => { + if (isDraftEmpty) { return; } // Only focus the input when user edits a message, skip it for existing drafts being edited of the report. // There is an animation when the comment is hidden and the edit form is shown, and there can be bugs on different mobile platforms // if the input is given focus in the middle of that animation which can prevent the keyboard from opening. - focusTextInputAfterAnimation(this.textInput, 100); - } + focusTextInputAfterAnimation(textInputRef.current, 100); + }, [isDraftEmpty]); - checkIfContextMenuActive() { - this.setState({isContextMenuActive: ReportActionContextMenu.isActiveReportAction(this.props.action.reportActionID)}); - } + const toggleContextMenuFromActiveReportAction = useCallback(() => { + setIsContextMenuActive(ReportActionContextMenu.isActiveReportAction(props.action.reportActionID)); + }, [props.action.reportActionID]); /** * Show the ReportActionContextMenu modal popover. * * @param {Object} [event] - A press event. */ - showPopover(event) { - // Block menu on the message being Edited or if the report action item has errors - if (this.props.draftMessage || !_.isEmpty(this.props.action.errors)) { - return; - } - - this.setState({isContextMenuActive: true}); - - const selection = SelectionScraper.getCurrentSelection(); - ReportActionContextMenu.showContextMenu( - ContextMenuActions.CONTEXT_MENU_TYPES.REPORT_ACTION, - event, - selection, - this.popoverAnchor, - this.props.report.reportID, - this.props.action, - this.props.draftMessage, - undefined, - this.checkIfContextMenuActive, - ReportUtils.isArchivedRoom(this.props.report), - ReportUtils.chatIncludesChronos(this.props.report), - ); - } + const showPopover = useCallback( + (event) => { + // Block menu on the message being Edited or if the report action item has errors + if (props.draftMessage || !_.isEmpty(props.action.errors)) { + return; + } + + setIsContextMenuActive(true); + + const selection = SelectionScraper.getCurrentSelection(); + ReportActionContextMenu.showContextMenu( + ContextMenuActions.CONTEXT_MENU_TYPES.REPORT_ACTION, + event, + selection, + popoverAnchorRef.current, + props.report.reportID, + props.action, + props.draftMessage, + undefined, + toggleContextMenuFromActiveReportAction, + ReportUtils.isArchivedRoom(props.report), + ReportUtils.chatIncludesChronos(props.report), + ); + }, + [props.draftMessage, props.report, props.action, toggleContextMenuFromActiveReportAction], + ); - toggleReaction(emoji) { - Report.toggleEmojiReaction(this.props.report.reportID, this.props.action, emoji); - } + const toggleReaction = useCallback( + (emoji) => { + Report.toggleEmojiReaction(props.report.reportID, props.action, emoji); + }, + [props.report, props.action], + ); /** * Get the content of ReportActionItem * @param {Boolean} hovered whether the ReportActionItem is hovered * @returns {Object} child component(s) */ - renderItemContent(hovered = false) { + const renderItemContent = (hovered = false) => { let children; - if (this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) { + if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) { // There is no single iouReport for bill splits, so only 1:1 requests require an iouReportID - const iouReportID = this.props.action.originalMessage.IOUReportID ? this.props.action.originalMessage.IOUReportID.toString() : '0'; + const iouReportID = props.action.originalMessage.IOUReportID ? props.action.originalMessage.IOUReportID.toString() : '0'; children = ( ); - } else if (ReportActionUtils.isCreatedTaskReportAction(this.props.action)) { + } else if (ReportActionUtils.isCreatedTaskReportAction(props.action)) { children = ( ); } else { - const message = _.last(lodashGet(this.props.action, 'message', [{}])); - const isAttachment = _.has(this.props.action, 'isAttachment') ? this.props.action.isAttachment : ReportUtils.isReportMessageAttachment(message); + const message = _.last(lodashGet(props.action, 'message', [{}])); + const isAttachment = _.has(props.action, 'isAttachment') ? props.action.isAttachment : ReportUtils.isReportMessageAttachment(message); children = ( - {!this.props.draftMessage ? ( + {!props.draftMessage ? ( ) : ( (this.textInput = el)} - report={this.props.report} + action={props.action} + draftMessage={props.draftMessage} + reportID={props.report.reportID} + index={props.index} + ref={textInputRef} + report={props.report} // Avoid defining within component due to an existing Onyx bug - preferredSkinTone={this.props.preferredSkinTone} + preferredSkinTone={props.preferredSkinTone} shouldDisableEmojiPicker={ - (ReportUtils.chatIncludesConcierge(this.props.report) && User.isBlockedFromConcierge(this.props.blockedFromConcierge)) || - ReportUtils.isArchivedRoom(this.props.report) + (ReportUtils.chatIncludesConcierge(props.report) && User.isBlockedFromConcierge(props.blockedFromConcierge)) || ReportUtils.isArchivedRoom(props.report) } /> )} @@ -240,22 +219,22 @@ class ReportActionItem extends Component { ); } - const reactions = _.get(this.props, ['action', 'message', 0, 'reactions'], []); + const reactions = _.get(props, ['action', 'message', 0, 'reactions'], []); const hasReactions = reactions.length > 0; return ( <> {children} {hasReactions && ( - + )} ); - } + }; /** * Get ReportActionItem with a proper wrapper @@ -263,21 +242,21 @@ class ReportActionItem extends Component { * @param {Boolean} isWhisper whether the ReportActionItem is a whisper * @returns {Object} report action item */ - renderReportActionItem(hovered, isWhisper) { - const content = this.renderItemContent(hovered || this.state.isContextMenuActive); + const renderReportActionItem = (hovered, isWhisper) => { + const content = renderItemContent(hovered || isContextMenuActive); - if (this.props.draftMessage) { + if (props.draftMessage) { return {content}; } - if (!this.props.displayAsGroup) { + if (!props.displayAsGroup) { return ( {content} @@ -285,102 +264,101 @@ class ReportActionItem extends Component { } return {content}; - } + }; - render() { - if (this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { - return ; - } - if (this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED) { - return ; - } - if (this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CHRONOSOOOLIST) { - return ( - - ); - } - - const hasErrors = !_.isEmpty(this.props.action.errors); - const whisperedTo = lodashGet(this.props.action, 'whisperedTo', []); - const isWhisper = whisperedTo.length > 0; - const isMultipleParticipant = whisperedTo.length > 1; - const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedTo); - const whisperedToPersonalDetails = isWhisper ? _.filter(this.props.personalDetails, (details) => _.includes(whisperedTo, details.login)) : []; - const displayNamesWithTooltips = isWhisper ? ReportUtils.getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant) : []; + if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { + return ; + } + if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED) { + return ; + } + if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CHRONOSOOOLIST) { return ( - (this.popoverAnchor = el)} - onPressIn={() => this.props.isSmallScreenWidth && DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()} - onPressOut={() => ControlSelection.unblock()} - onSecondaryInteraction={this.showPopover} - preventDefaultContextMenu={!this.props.draftMessage && !hasErrors} - withoutFocusOnSecondaryInteraction - > - - {(hovered) => ( - - {this.props.shouldDisplayNewMarker && } - + ); + } + + const hasErrors = !_.isEmpty(props.action.errors); + const whisperedTo = lodashGet(props.action, 'whisperedTo', []); + const isWhisper = whisperedTo.length > 0; + const isMultipleParticipant = whisperedTo.length > 1; + const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedTo); + const whisperedToPersonalDetails = isWhisper ? _.filter(props.personalDetails, (details) => _.includes(whisperedTo, details.login)) : []; + const displayNamesWithTooltips = isWhisper ? ReportUtils.getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant) : []; + return ( + props.isSmallScreenWidth && DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()} + onPressOut={() => ControlSelection.unblock()} + onSecondaryInteraction={showPopover} + preventDefaultContextMenu={!props.draftMessage && !hasErrors} + withoutFocusOnSecondaryInteraction + > + + {(hovered) => ( + + {props.shouldDisplayNewMarker && } + + ReportActions.clearReportActionErrors(props.report.reportID, props.action)} + pendingAction={props.draftMessage ? null : props.action.pendingAction} + errors={props.action.errors} + errorRowStyles={[styles.ml10, styles.mr2]} + needsOffscreenAlphaCompositing={props.action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU} > - ReportActions.clearReportActionErrors(this.props.report.reportID, this.props.action)} - pendingAction={this.props.draftMessage ? null : this.props.action.pendingAction} - errors={this.props.action.errors} - errorRowStyles={[styles.ml10, styles.mr2]} - needsOffscreenAlphaCompositing={this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU} - > - {isWhisper && ( - - - - - - {this.props.translate('reportActionContextMenu.onlyVisible')} -   - - + + - )} - {this.renderReportActionItem(hovered, isWhisper)} - - - + + {props.translate('reportActionContextMenu.onlyVisible')} +   + + + + )} + {renderReportActionItem(hovered, isWhisper)} + - )} - - - - - - ); - } + + + )} + + + + + + ); } + ReportActionItem.propTypes = propTypes; ReportActionItem.defaultProps = defaultProps; @@ -402,4 +380,18 @@ export default compose( key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, }, }), -)(ReportActionItem); +)( + memo( + ReportActionItem, + (prevProps, nextProps) => + prevProps.displayAsGroup === nextProps.displayAsGroup && + prevProps.draftMessage === nextProps.draftMessage && + prevProps.isMostRecentIOUReportAction !== nextProps.isMostRecentIOUReportAction && + prevProps.hasOutstandingIOU === nextProps.hasOutstandingIOU && + prevProps.shouldDisplayNewMarker === nextProps.shouldDisplayNewMarker && + !_.isEqual(prevProps.action, nextProps.action) && + lodashGet(prevProps.report, 'statusNum') === lodashGet(nextProps.report, 'statusNum') && + lodashGet(prevProps.report, 'stateNum') === lodashGet(nextProps.report, 'stateNum') && + prevProps.translate === nextProps.translate, + ), +); From c6304eea80eeb0e6c22fb9dc03ddd17efc302ef0 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 11 May 2023 19:37:25 -0700 Subject: [PATCH 02/36] add back ReportActionItemMessageEdit and refPropTypes --- src/components/refPropTypes.js | 3 +++ src/pages/home/report/ReportActionItemMessageEdit.js | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 src/components/refPropTypes.js diff --git a/src/components/refPropTypes.js b/src/components/refPropTypes.js new file mode 100644 index 000000000000..a67f6323d1d9 --- /dev/null +++ b/src/components/refPropTypes.js @@ -0,0 +1,3 @@ +import PropTypes from 'prop-types'; + +export default PropTypes.oneOfType([PropTypes.func, PropTypes.object]); diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 4d44cde04034..045ca8248ca7 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -31,6 +31,7 @@ import CONST from '../../../CONST'; import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; import withKeyboardState, {keyboardStatePropTypes} from '../../../components/withKeyboardState'; +import refPropTypes from '../../../components/refPropTypes'; import * as ComposerUtils from '../../../libs/ComposerUtils'; const propTypes = { @@ -47,7 +48,7 @@ const propTypes = { index: PropTypes.number.isRequired, /** A ref to forward to the text input */ - forwardedRef: PropTypes.func, + forwardedRef: refPropTypes, /** The report currently being looked at */ // eslint-disable-next-line react/no-unused-prop-types @@ -293,7 +294,7 @@ class ReportActionItemMessageEdit extends React.Component { multiline ref={(el) => { this.textInput = el; - this.props.forwardedRef(el); + this.props.forwardedRef.current = el; }} nativeID={this.messageEditInput} onChangeText={this.updateDraft} // Debounced saveDraftComment From 29ac1a9f693026f33f278161ab1f92955ab51f7d Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 11 May 2023 19:38:41 -0700 Subject: [PATCH 03/36] add back pressableWithSecondaryInteraction --- .../pressableWithSecondaryInteractionPropTypes.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/PressableWithSecondaryInteraction/pressableWithSecondaryInteractionPropTypes.js b/src/components/PressableWithSecondaryInteraction/pressableWithSecondaryInteractionPropTypes.js index e54598cb1394..b036404e018d 100644 --- a/src/components/PressableWithSecondaryInteraction/pressableWithSecondaryInteractionPropTypes.js +++ b/src/components/PressableWithSecondaryInteraction/pressableWithSecondaryInteractionPropTypes.js @@ -1,4 +1,5 @@ import PropTypes from 'prop-types'; +import refPropTypes from '../refPropTypes'; import stylePropTypes from '../../styles/stylePropTypes'; const propTypes = { @@ -18,7 +19,7 @@ const propTypes = { children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired, /** The ref to the search input (may be null on small screen widths) */ - forwardedRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), + forwardedRef: refPropTypes, /** Prevent the default ContextMenu on web/Desktop */ preventDefaultContextMenu: PropTypes.bool, From 845a86bd4a538d49369cbf42c9e32ab309c497d6 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 16 May 2023 13:06:54 -0700 Subject: [PATCH 04/36] merge main --- src/pages/home/report/ReportActionItem.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index ed2f092fea88..150a44dc9350 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -297,6 +297,21 @@ function ReportActionItem(props) { return {content}; }; + if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { + return ; + } + if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED) { + return ; + } + if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CHRONOSOOOLIST) { + return ( + + ); + } + const hasErrors = !_.isEmpty(props.action.errors); const whisperedTo = lodashGet(props.action, 'whisperedTo', []); const isWhisper = whisperedTo.length > 0; From 1eaf072946dcea105cef4346d7a249947934e986 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 16 May 2023 13:08:10 -0700 Subject: [PATCH 05/36] fix console warnings --- src/components/ReportActionItem/IOUPreview.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/IOUPreview.js b/src/components/ReportActionItem/IOUPreview.js index 0f538b74326a..ad05676973e3 100644 --- a/src/components/ReportActionItem/IOUPreview.js +++ b/src/components/ReportActionItem/IOUPreview.js @@ -27,6 +27,7 @@ import * as OptionsListUtils from '../../libs/OptionsListUtils'; import * as CurrencyUtils from '../../libs/CurrencyUtils'; import * as IOUUtils from '../../libs/IOUUtils'; import * as ReportUtils from '../../libs/ReportUtils'; +import refPropTypes from '../refPropTypes'; const propTypes = { /** The active IOUReport, used for Onyx subscription */ @@ -43,7 +44,7 @@ const propTypes = { action: PropTypes.shape(reportActionPropTypes), /** Popover context menu anchor, used for showing context menu */ - contextMenuAnchor: PropTypes.shape({current: PropTypes.elementType}), + contextMenuAnchor: refPropTypes, /** Callback for updating context menu active state, used for showing context menu */ checkIfContextMenuActive: PropTypes.func, From c49dff864fa0b2be2389050705275c5564db54e9 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 17 May 2023 12:38:02 -0700 Subject: [PATCH 06/36] wip --- ios/Podfile.lock | 6 +++--- src/pages/home/report/ReportActionItem.js | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index f0d6720080e8..d62469e46b86 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1019,7 +1019,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Airship: c70eed50e429f97f5adb285423c7291fb7a032ae AirshipFrameworkProxy: 2eefb77bb77b5120b0f48814b0d44439aa3ad415 - boost: 57d2868c099736d80fcd648bf211b4431e51a558 + boost: a7c83b31436843459a1961bfd74b96033dc77234 CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 FBLazyVector: ff54429f0110d3c722630a98096ba689c39f6d5f @@ -1062,7 +1062,7 @@ SPEC CHECKSUMS: Permission-LocationWhenInUse: 3ba99e45c852763f730eabecec2870c2382b7bd4 Plaid: 7d340abeadb46c7aa1a91f896c5b22395a31fcf2 PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef - RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 + RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda RCTRequired: e9e7b8b45aa9bedb2fdad71740adf07a7265b9be RCTTypeSafety: 9ae0e9206625e995f0df4d5b9ddc94411929fb30 React: a71c8e1380f07e01de721ccd52bcf9c03e81867d @@ -1135,4 +1135,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 5feaab251246f42f41e69c8a28fa331b4899e814 -COCOAPODS: 1.12.0 +COCOAPODS: 1.11.3 diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 150a44dc9350..f637c6497fc6 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -115,6 +115,7 @@ function ReportActionItem(props) { }, [isDraftEmpty]); const toggleContextMenuFromActiveReportAction = useCallback(() => { + console.log('>>>> Here'); setIsContextMenuActive(ReportActionContextMenu.isActiveReportAction(props.action.reportActionID)); }, [props.action.reportActionID]); @@ -123,26 +124,25 @@ function ReportActionItem(props) { * * @param {Object} [event] - A press event. */ - const showPopover = useCallback( - (event) => { - // Block menu on the message being Edited or if the report action item has errors - if (props.draftMessage || !_.isEmpty(props.action.errors)) { - return; - } + const showPopover = useCallback((event) => { + // Block menu on the message being Edited or if the report action item has errors + if (props.draftMessage || !_.isEmpty(props.action.errors)) { + return; + } - setIsContextMenuActive(true); + setIsContextMenuActive(true); const selection = SelectionScraper.getCurrentSelection(); ReportActionContextMenu.showContextMenu( ContextMenuActions.CONTEXT_MENU_TYPES.REPORT_ACTION, event, selection, - popoverAnchor, + popoverAnchorRef, props.report.reportID, props.action, props.draftMessage, undefined, - checkIfContextMenuActive, + toggleContextMenuFromActiveReportAction, ReportUtils.isArchivedRoom(props.report), ReportUtils.chatIncludesChronos(props.report), props.action.childReportID, @@ -239,8 +239,7 @@ function ReportActionItem(props) { const reactions = _.get(props, ['action', 'message', 0, 'reactions'], []); const hasReactions = reactions.length > 0; - const shouldDisplayThreadReplies = - props.action.childCommenterCount && Permissions.canUseThreads(props.betas) && !ReportUtils.isThreadFirstChat(props.action, props.report.reportID); + const shouldDisplayThreadReplies = props.action.childCommenterCount && Permissions.canUseThreads(props.betas) && !ReportUtils.isThreadFirstChat(props.action, props.report.reportID); const oldestFourEmails = lodashGet(props.action, 'childOldestFourEmails', '').split(','); return ( From 5b862a3354aa938ee0f9c3c5f05be7654ca6a826 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 17 May 2023 12:55:00 -0700 Subject: [PATCH 07/36] fix long press to pull up context menu --- .../PopoverReportActionContextMenu.js | 2 +- src/pages/home/report/ReportActionItem.js | 55 ++++++++++--------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js index dfdf559e79c7..66a0ea6049fb 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js @@ -96,7 +96,7 @@ class PopoverReportActionContextMenu extends React.Component { getContextMenuMeasuredLocation() { return new Promise((resolve) => { if (this.contextMenuAnchor) { - this.contextMenuAnchor.measureInWindow((x, y) => resolve({x, y})); + this.contextMenuAnchor.current.measureInWindow((x, y) => resolve({x, y})); } else { resolve({x: 0, y: 0}); } diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 5ad61d1eb849..c1cfd31b7bd4 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -124,30 +124,33 @@ function ReportActionItem(props) { * * @param {Object} [event] - A press event. */ - const showPopover = useCallback((event) => { - // Block menu on the message being Edited or if the report action item has errors - if (props.draftMessage || !_.isEmpty(props.action.errors)) { - return; - } - - setIsContextMenuActive(true); - - const selection = SelectionScraper.getCurrentSelection(); - ReportActionContextMenu.showContextMenu( - ContextMenuActions.CONTEXT_MENU_TYPES.REPORT_ACTION, - event, - selection, - popoverAnchorRef, - props.report.reportID, - props.action, - props.draftMessage, - undefined, - toggleContextMenuFromActiveReportAction, - ReportUtils.isArchivedRoom(props.report), - ReportUtils.chatIncludesChronos(props.report), - props.action.childReportID, - ); - }); + const showPopover = useCallback( + (event) => { + // Block menu on the message being Edited or if the report action item has errors + if (props.draftMessage || !_.isEmpty(props.action.errors)) { + return; + } + + setIsContextMenuActive(true); + + const selection = SelectionScraper.getCurrentSelection(); + ReportActionContextMenu.showContextMenu( + ContextMenuActions.CONTEXT_MENU_TYPES.REPORT_ACTION, + event, + selection, + popoverAnchorRef, + props.report.reportID, + props.action, + props.draftMessage, + () => {}, + toggleContextMenuFromActiveReportAction, + ReportUtils.isArchivedRoom(props.report), + ReportUtils.chatIncludesChronos(props.report), + props.action.childReportID, + ); + }, + [props.draftMessage, props.action, props.report, toggleContextMenuFromActiveReportAction], + ); const toggleReaction = useCallback( (emoji) => { @@ -193,8 +196,8 @@ function ReportActionItem(props) { chatReportID={props.report.reportID} action={props.action} isHovered={hovered} - contextMenuAnchor={popoverAnchor} - checkIfContextMenuActive={checkIfContextMenuActive} + contextMenuAnchor={popoverAnchorRef} + checkIfContextMenuActive={toggleContextMenuFromActiveReportAction} /> ); } else if ( From 666995b82487ace78d8f6dc69552590377acaf25 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 17 May 2023 12:55:17 -0700 Subject: [PATCH 08/36] remove unused --- ios/Podfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 2d815f342d17..766a322607bd 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1019,7 +1019,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Airship: c70eed50e429f97f5adb285423c7291fb7a032ae AirshipFrameworkProxy: 2eefb77bb77b5120b0f48814b0d44439aa3ad415 - boost: a7c83b31436843459a1961bfd74b96033dc77234 + boost: 57d2868c099736d80fcd648bf211b4431e51a558 CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 FBLazyVector: ff54429f0110d3c722630a98096ba689c39f6d5f @@ -1062,7 +1062,7 @@ SPEC CHECKSUMS: Permission-LocationWhenInUse: 3ba99e45c852763f730eabecec2870c2382b7bd4 Plaid: 7d340abeadb46c7aa1a91f896c5b22395a31fcf2 PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef - RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda + RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 RCTRequired: e9e7b8b45aa9bedb2fdad71740adf07a7265b9be RCTTypeSafety: 9ae0e9206625e995f0df4d5b9ddc94411929fb30 React: a71c8e1380f07e01de721ccd52bcf9c03e81867d @@ -1135,4 +1135,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 4ed1c7b099741c82e2b0411b95f6468e72be6c76 -COCOAPODS: 1.11.3 +COCOAPODS: 1.12.0 From 0b01e76d4cb9e16a50ef67f3302594026d1d1f77 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 17 May 2023 14:33:57 -0700 Subject: [PATCH 09/36] remove weird stuff from merge --- src/pages/home/report/ReportActionItem.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index acf23d157a67..ac4d69a3b4c0 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -261,15 +261,12 @@ function ReportActionItem(props) { const reactions = _.get(props, ['action', 'message', 0, 'reactions'], []); const hasReactions = reactions.length > 0; - const numberOfThreadReplies = _.get(this.props, ['action', 'childVisibleActionCount'], 0); + const numberOfThreadReplies = _.get(props, ['action', 'childVisibleActionCount'], 0); const hasReplies = numberOfThreadReplies > 0; const shouldDisplayThreadReplies = - hasReplies && - this.props.action.childCommenterCount && - Permissions.canUseThreads(this.props.betas) && - !ReportUtils.isThreadFirstChat(this.props.action, this.props.report.reportID); - const oldestFourEmails = lodashGet(this.props.action, 'childOldestFourEmails', '').split(','); + hasReplies && props.action.childCommenterCount && Permissions.canUseThreads(props.betas) && !ReportUtils.isThreadFirstChat(props.action, props.report.reportID); + const oldestFourEmails = lodashGet(props.action, 'childOldestFourEmails', '').split(','); return ( <> @@ -285,9 +282,9 @@ function ReportActionItem(props) { )} {shouldDisplayThreadReplies && ( From b925ee1f4084a1954ef46f909c8d8fb433c5697a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 13:21:40 -0700 Subject: [PATCH 10/36] Update src/pages/home/report/ReportActionItem.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/pages/home/report/ReportActionItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index ac4d69a3b4c0..9628180550d2 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -370,7 +370,7 @@ function ReportActionItem(props) { pendingAction={props.draftMessage ? null : props.action.pendingAction} errors={props.action.errors} errorRowStyles={[styles.ml10, styles.mr2]} - needsOffscreenAlphaCompositing={props.action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU} + needsOffscreenAlphaCompositing={ReportActionsUtils.isMoneyRequestAction(this.props.action)} > {isWhisper && ( From a61a258c34ab5241332664cb77333630bcd8c4cb Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 13:22:01 -0700 Subject: [PATCH 11/36] Update src/pages/home/report/ReportActionItem.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/pages/home/report/ReportActionItem.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 9628180550d2..fe84a3b9f801 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -405,6 +405,7 @@ function ReportActionItem(props) { isVisible={hovered && !props.draftMessage && !hasErrors} draftMessage={props.draftMessage} isChronosReport={ReportUtils.chatIncludesChronos(props.report)} + childReportActionID={props.action.childReportActionID} /> )} From 1abb820f1c6d5e60a1d096ce03ed4ab318763965 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 13:24:26 -0700 Subject: [PATCH 12/36] add hasOutstandingIOU into proptypes --- src/pages/home/report/ReportActionItem.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index ac4d69a3b4c0..5d86ad057d42 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -78,6 +78,10 @@ const propTypes = { /** Draft message - if this is set the comment is in 'edit' mode */ draftMessage: PropTypes.string, + /* Whether the option has an outstanding IOU */ + // eslint-disable-next-line react/no-unused-prop-types + hasOutstandingIOU: PropTypes.bool.isRequired, + /** Stores user's preferred skin tone */ preferredSkinTone: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), From 891495a9d4317c0205e978dbd3976d515b37b4ff Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 13:27:03 -0700 Subject: [PATCH 13/36] fix typo --- src/pages/home/report/ReportActionItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 7c727ef957d6..e76dbde56015 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -374,7 +374,7 @@ function ReportActionItem(props) { pendingAction={props.draftMessage ? null : props.action.pendingAction} errors={props.action.errors} errorRowStyles={[styles.ml10, styles.mr2]} - needsOffscreenAlphaCompositing={ReportActionsUtils.isMoneyRequestAction(this.props.action)} + needsOffscreenAlphaCompositing={ReportActionsUtils.isMoneyRequestAction(props.action)} > {isWhisper && ( From 41b5cd65ad3cfa380244798cb7e82346845ddca4 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 16:31:08 -0700 Subject: [PATCH 14/36] Update src/pages/home/report/ReportActionItem.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/pages/home/report/ReportActionItem.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index e76dbde56015..4e558ba01c5f 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -108,6 +108,7 @@ function ReportActionItem(props) { const popoverAnchorRef = useRef(); const isDraftEmpty = !props.draftMessage; + useEffect(() => { if (isDraftEmpty) { return; From 1430ac0f259827e89ecbde86daab94920f97a6d6 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 16:32:08 -0700 Subject: [PATCH 15/36] default prop types --- src/pages/home/report/ReportActionItem.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index e76dbde56015..c042324c6fef 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -80,7 +80,7 @@ const propTypes = { /* Whether the option has an outstanding IOU */ // eslint-disable-next-line react/no-unused-prop-types - hasOutstandingIOU: PropTypes.bool.isRequired, + hasOutstandingIOU: PropTypes.bool, /** Stores user's preferred skin tone */ preferredSkinTone: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), @@ -99,6 +99,7 @@ const defaultProps = { preferredSkinTone: CONST.EMOJI_DEFAULT_SKIN_TONE, personalDetails: {}, shouldShowSubscriptAvatar: false, + hasOutstandingIOU: false, betas: [], }; @@ -108,6 +109,7 @@ function ReportActionItem(props) { const popoverAnchorRef = useRef(); const isDraftEmpty = !props.draftMessage; + useEffect(() => { if (isDraftEmpty) { return; From 25a09b79f7989f8a6797ee1bcdcb44b5184bd00b Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 16:45:34 -0700 Subject: [PATCH 16/36] fix right click --- .../PressableWithSecondaryInteraction/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/PressableWithSecondaryInteraction/index.js b/src/components/PressableWithSecondaryInteraction/index.js index 037fb3afae73..b4752f5c058b 100644 --- a/src/components/PressableWithSecondaryInteraction/index.js +++ b/src/components/PressableWithSecondaryInteraction/index.js @@ -17,8 +17,13 @@ class PressableWithSecondaryInteraction extends Component { } componentDidMount() { - if (this.props.forwardedRef && _.isFunction(this.props.forwardedRef)) { - this.props.forwardedRef(this.pressableRef); + if (this.props.forwardedRef) { + if (_.isFunction(this.props.forwardedRef)) { + this.props.forwardedRef(this.pressableRef); + } + if (_.isObject(this.props.forwardedRef)) { + this.props.forwardedRef.current = this.pressableRef; + } } this.pressableRef.addEventListener('contextmenu', this.executeSecondaryInteractionOnContextMenu); } From 575c306513f5f31f2819698cbe54cbb2e76e2495 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 16:47:38 -0700 Subject: [PATCH 17/36] remove unused line break --- src/pages/home/report/ReportActionItem.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index c042324c6fef..08da94bd1b17 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -109,7 +109,6 @@ function ReportActionItem(props) { const popoverAnchorRef = useRef(); const isDraftEmpty = !props.draftMessage; - useEffect(() => { if (isDraftEmpty) { return; @@ -170,7 +169,7 @@ function ReportActionItem(props) { * @param {Boolean} hovered whether the ReportActionItem is hovered * @returns {Object} child component(s) */ - const renderItemContent = (hovered = false) => { + function renderItemContent = (hovered = false) => { let children; const originalMessage = lodashGet(props.action, 'originalMessage', {}); // Show the IOUPreview for when request was created, bill was split or money was sent From 5617258371620ae36b9f6e066d36efd4df4f7ef2 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 16:52:55 -0700 Subject: [PATCH 18/36] typo --- src/pages/home/report/ReportActionItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 08da94bd1b17..b7421e524456 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -169,7 +169,7 @@ function ReportActionItem(props) { * @param {Boolean} hovered whether the ReportActionItem is hovered * @returns {Object} child component(s) */ - function renderItemContent = (hovered = false) => { + const renderItemContent = (hovered = false) => { let children; const originalMessage = lodashGet(props.action, 'originalMessage', {}); // Show the IOUPreview for when request was created, bill was split or money was sent From cccebb865ce75157749cd9310de4771c22af3a0d Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 17:29:40 -0700 Subject: [PATCH 19/36] Update src/components/PressableWithSecondaryInteraction/index.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/components/PressableWithSecondaryInteraction/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/PressableWithSecondaryInteraction/index.js b/src/components/PressableWithSecondaryInteraction/index.js index b4752f5c058b..4b2ff0d0b200 100644 --- a/src/components/PressableWithSecondaryInteraction/index.js +++ b/src/components/PressableWithSecondaryInteraction/index.js @@ -23,7 +23,7 @@ class PressableWithSecondaryInteraction extends Component { } if (_.isObject(this.props.forwardedRef)) { this.props.forwardedRef.current = this.pressableRef; - } + } } this.pressableRef.addEventListener('contextmenu', this.executeSecondaryInteractionOnContextMenu); } From 49dff2bcc58ff6f0748a098e43bf4fa5ef229f0c Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 18 May 2023 17:29:46 -0700 Subject: [PATCH 20/36] Update src/components/PressableWithSecondaryInteraction/index.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/components/PressableWithSecondaryInteraction/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/PressableWithSecondaryInteraction/index.js b/src/components/PressableWithSecondaryInteraction/index.js index 4b2ff0d0b200..efb64fbb5397 100644 --- a/src/components/PressableWithSecondaryInteraction/index.js +++ b/src/components/PressableWithSecondaryInteraction/index.js @@ -20,8 +20,7 @@ class PressableWithSecondaryInteraction extends Component { if (this.props.forwardedRef) { if (_.isFunction(this.props.forwardedRef)) { this.props.forwardedRef(this.pressableRef); - } - if (_.isObject(this.props.forwardedRef)) { + } else if (_.isObject(this.props.forwardedRef)) { this.props.forwardedRef.current = this.pressableRef; } } From c5b635073d01b96a1d8e4c39d2be6be96e17e66b Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 19 May 2023 10:52:19 -0700 Subject: [PATCH 21/36] Fix proptypes errors --- src/components/ReportActionItem/MoneyRequestAction.js | 3 ++- src/components/ReportActionItem/ReportPreview.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestAction.js b/src/components/ReportActionItem/MoneyRequestAction.js index 85fa92267405..66ddcf568922 100644 --- a/src/components/ReportActionItem/MoneyRequestAction.js +++ b/src/components/ReportActionItem/MoneyRequestAction.js @@ -20,6 +20,7 @@ import * as ReportUtils from '../../libs/ReportUtils'; import * as Report from '../../libs/actions/Report'; import withLocalize, {withLocalizePropTypes} from '../withLocalize'; import * as ReportActionsUtils from '../../libs/ReportActionsUtils'; +import refPropTypes from '../refPropTypes'; const propTypes = { /** All the data of the action */ @@ -35,7 +36,7 @@ const propTypes = { isMostRecentIOUReportAction: PropTypes.bool.isRequired, /** Popover context menu anchor, used for showing context menu */ - contextMenuAnchor: PropTypes.shape({current: PropTypes.elementType}), + contextMenuAnchor: refPropTypes, /** Callback for updating context menu active state, used for showing context menu */ checkIfContextMenuActive: PropTypes.func, diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 814a38dba5b5..6c5856869e0b 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -24,6 +24,7 @@ import SettlementButton from '../SettlementButton'; import themeColors from '../../styles/themes/default'; import getButtonState from '../../libs/getButtonState'; import * as IOU from '../../libs/actions/IOU'; +import refPropTypes from '../refPropTypes'; const propTypes = { /** All the data of the action */ @@ -71,7 +72,7 @@ const propTypes = { }), /** Popover context menu anchor, used for showing context menu */ - contextMenuAnchor: PropTypes.shape({current: PropTypes.elementType}), + contextMenuAnchor: refPropTypes, /** Callback for updating context menu active state, used for showing context menu */ checkIfContextMenuActive: PropTypes.func, From 7f326f17b7b31e1db5dbb5fe05032cb290100594 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 19 May 2023 11:42:23 -0700 Subject: [PATCH 22/36] fix error passing ref into tooltips --- src/styles/getTooltipStyles.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index 985eddbd3dee..ad2a7552fa1d 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -67,7 +67,13 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || tooltip.contains(element)) { + if (!element || !tooltip || !tooltip.current) { + return false; + } + if (tooltip && tooltip.contains(element)) { + return false; + } + if (tooltip.current && tooltip.current.contains(element)) { return false; } From 7620f3a84d338779aac707e0e674b5bb4cd77bd6 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 19 May 2023 11:42:56 -0700 Subject: [PATCH 23/36] remove unused --- src/styles/getTooltipStyles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index ad2a7552fa1d..a3d813b0fab6 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -67,7 +67,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || !tooltip || !tooltip.current) { + if (!element) { return false; } if (tooltip && tooltip.contains(element)) { From 852f7bc0dbd900d5b5fcc162b57b1df271776f7a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 19 May 2023 11:43:19 -0700 Subject: [PATCH 24/36] consolidate logic --- src/styles/getTooltipStyles.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index a3d813b0fab6..2263d349cbb7 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -67,13 +67,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element) { - return false; - } - if (tooltip && tooltip.contains(element)) { - return false; - } - if (tooltip.current && tooltip.current.contains(element)) { + if (!element || (tooltip && tooltip.contains(element)) || (tooltip.current && tooltip.current.contains(element))) { return false; } From 8a9b2710b0d37443b746fc172e74c203122a18ba Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 19 May 2023 13:49:15 -0700 Subject: [PATCH 25/36] fix condition --- src/styles/getTooltipStyles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index 2263d349cbb7..f33668d0c248 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -67,7 +67,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || (tooltip && tooltip.contains(element)) || (tooltip.current && tooltip.current.contains(element))) { + if (!element || (tooltip && tooltip.contains(element)) || (tooltip && tooltip.current && tooltip.current.contains(element))) { return false; } From d95494aa1534cea5fb4f0af1491f45559fc179fc Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 19 May 2023 13:50:36 -0700 Subject: [PATCH 26/36] consolidate logic --- src/styles/getTooltipStyles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index f33668d0c248..036ca4578e0f 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -67,7 +67,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || (tooltip && tooltip.contains(element)) || (tooltip && tooltip.current && tooltip.current.contains(element))) { + if (!element || (tooltip && (tooltip.contains(element) || (tooltip.current && tooltip.current.contains(element))))) { return false; } From 4a35a5ae1470bafa03f8e121e0ebca4a760cb095 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 05:15:25 +0800 Subject: [PATCH 27/36] prettier --- src/pages/home/report/ReportActionItem.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 391bb599de7f..0a6d8bcba4df 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -244,9 +244,7 @@ function ReportActionItem(props) { action={props.action} style={[ !props.displayAsGroup && isAttachment ? styles.mt2 : undefined, - _.contains([..._.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG), CONST.REPORT.ACTIONS.TYPE.IOU], props.action.actionName) - ? styles.colorMuted - : undefined, + _.contains([..._.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG), CONST.REPORT.ACTIONS.TYPE.IOU], props.action.actionName) ? styles.colorMuted : undefined, ]} /> ) : ( From de7f9906a89ef074c6da1be3ac627373039570ef Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 05:46:20 +0800 Subject: [PATCH 28/36] use _.contains to simplify condition --- src/styles/getTooltipStyles.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index 64e95caa63d8..f710ce9cd532 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -1,3 +1,4 @@ +import _ from 'underscore'; import spacing from './utilities/spacing'; import styles from './styles'; import colors from './colors'; @@ -67,7 +68,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || (tooltip && (tooltip.contains(element) || (tooltip.current && tooltip.current.contains(element))))) { + if (!element || _.contains(tooltip.current || tooltip, element)) { return false; } From c52ac848a680bd875e417ed301a1ff74ea516bb7 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 05:55:40 +0800 Subject: [PATCH 29/36] apply changes from #18523 --- src/pages/home/report/ReportActionItem.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 0a6d8bcba4df..b37e4d0bb08f 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -366,6 +366,15 @@ function ReportActionItem(props) { {(hovered) => ( {props.shouldDisplayNewMarker && } + - )} From 8a5cb7edbbf03667ea2eb32198516becce7d10ff Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 06:00:53 +0800 Subject: [PATCH 30/36] Update src/styles/getTooltipStyles.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/styles/getTooltipStyles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index f710ce9cd532..0ef358bec276 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -68,7 +68,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || _.contains(tooltip.current || tooltip, element)) { + if (!element || _.contains(tooltip && tooltip.current || tooltip, element)) { return false; } From 78fecb9a23793a70e5d76f478c6daa261c039ba1 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 06:04:06 +0800 Subject: [PATCH 31/36] use lodashGet --- src/styles/getTooltipStyles.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index f710ce9cd532..1a9276859bc1 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -1,4 +1,5 @@ import _ from 'underscore'; +import lodashGet from 'lodash/get'; import spacing from './utilities/spacing'; import styles from './styles'; import colors from './colors'; @@ -68,7 +69,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || _.contains(tooltip.current || tooltip, element)) { + if (!element || _.contains(lodashGet(tooltip, 'current', tooltip), element)) { return false; } From eb17e6afaf6497474a383dd364fb5968b8664827 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 06:19:00 +0800 Subject: [PATCH 32/36] change back to conditional logic --- src/styles/getTooltipStyles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index 1a9276859bc1..fc2648da6051 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -69,7 +69,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || _.contains(lodashGet(tooltip, 'current', tooltip), element)) { + if (!element || (tooltip && (tooltip.contains(element) || (tooltip.current && tooltip.current.contains(element))))) { return false; } From 11a9021f4bd63186ce33d5d24c3615d3f8e1473a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 06:24:59 +0800 Subject: [PATCH 33/36] check tooltip.current first, in case tooltip.contains doesn't exist --- src/styles/getTooltipStyles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index fc2648da6051..6badab96bb45 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -69,7 +69,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { const element = document.elementFromPoint(xOffset, yOffset); // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || (tooltip && (tooltip.contains(element) || (tooltip.current && tooltip.current.contains(element))))) { + if (!element || tooltip && ((tooltip.current && tooltip.current.contains(element)) || tooltip.contains(element))) { return false; } From 54c7a121778a4cfc3e1b5adfef1a4c09dd930ba4 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 06:26:30 +0800 Subject: [PATCH 34/36] simplify logic with variable --- src/styles/getTooltipStyles.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index 6badab96bb45..e1d228ddb692 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -67,9 +67,10 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { } const element = document.elementFromPoint(xOffset, yOffset); + const tooltipRef = tooltip && tooltip.current || tooltip; // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself - if (!element || tooltip && ((tooltip.current && tooltip.current.contains(element)) || tooltip.contains(element))) { + if (!element || (tooltipRef && tooltipRef.contains(element))) { return false; } From a98c97d9a46ab6e9c1e89ecf301a6871864cea17 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 06:54:53 +0800 Subject: [PATCH 35/36] Update src/styles/getTooltipStyles.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/styles/getTooltipStyles.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index e1d228ddb692..a81c57107296 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -1,5 +1,3 @@ -import _ from 'underscore'; -import lodashGet from 'lodash/get'; import spacing from './utilities/spacing'; import styles from './styles'; import colors from './colors'; From 992a4b6c5c5f512be667dbd1196841f9eefb606f Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 22 May 2023 06:55:04 +0800 Subject: [PATCH 36/36] Update src/styles/getTooltipStyles.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/styles/getTooltipStyles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/getTooltipStyles.js b/src/styles/getTooltipStyles.js index a81c57107296..ab2b6b433224 100644 --- a/src/styles/getTooltipStyles.js +++ b/src/styles/getTooltipStyles.js @@ -65,7 +65,7 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip) { } const element = document.elementFromPoint(xOffset, yOffset); - const tooltipRef = tooltip && tooltip.current || tooltip; + const tooltipRef = (tooltip && tooltip.current) || tooltip; // Ensure it's not the already rendered element of this very tooltip, so the tooltip doesn't try to "avoid" itself if (!element || (tooltipRef && tooltipRef.contains(element))) {