-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
14893: Edit message arrow up #15207
14893: Edit message arrow up #15207
Changes from 2 commits
4ef5645
0c821ff
0d1f768
0d91a37
17dc211
f54539a
6091178
e1834f1
5ec7c39
8114e7d
112ce8a
8118c20
9444c98
2b1a943
42ce483
6784b28
ab82acd
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ import reportPropTypes from '../reportPropTypes'; | |
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView'; | ||
import ReportHeaderSkeletonView from '../../components/ReportHeaderSkeletonView'; | ||
import withViewportOffsetTop, {viewportOffsetTopPropTypes} from '../../components/withViewportOffsetTop'; | ||
import * as ReportActionsUtils from '../../libs/ReportActionsUtils'; | ||
|
||
const propTypes = { | ||
/** Navigation route context info provided by react navigation */ | ||
|
@@ -111,6 +112,9 @@ class ReportScreen extends React.Component { | |
this.chatWithAccountManager = this.chatWithAccountManager.bind(this); | ||
this.dismissBanner = this.dismissBanner.bind(this); | ||
|
||
// We need this.sortedAndFilteredReportActions to be set before this.state is initialized because the function to calculate the newMarkerReportActionID uses the sorted report actions | ||
this.sortedAndFilteredReportActions = this.getSortedReportActionsForDisplay(props.reportActions); | ||
|
||
this.state = { | ||
skeletonViewContainerHeight: reportActionsListViewHeight, | ||
isBannerVisible: true, | ||
|
@@ -123,6 +127,60 @@ class ReportScreen extends React.Component { | |
Navigation.setIsReportScreenIsReady(); | ||
} | ||
|
||
shouldComponentUpdate(nextProps) { | ||
if (!_.isEqual(nextProps.reportActions, this.props.reportActions)) { | ||
this.sortedAndFilteredReportActions = this.getSortedReportActionsForDisplay(nextProps.reportActions); | ||
|
||
return true; | ||
} | ||
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. @gedu I am not very happy with moving all of this logic up which mens amore components will have to re-render because of this. Could we keep it in the Then we could get the sorted report actions in the ReportScreen, pass it down to the Report screen components and we can call the Is there anything I am missing? 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. @mountiny We needed to move up so the I could move About the rerender, it will be the same as before, because when 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. Thanks for context. |
||
|
||
if (nextProps.report.isLoadingMoreReportActions !== this.props.report.isLoadingMoreReportActions) { | ||
return true; | ||
} | ||
|
||
if (nextProps.report.isLoadingReportActions !== this.props.report.isLoadingReportActions) { | ||
return true; | ||
} | ||
|
||
if (nextProps.report.lastReadTime !== this.props.report.lastReadTime) { | ||
return true; | ||
} | ||
|
||
if (this.props.isSmallScreenWidth !== nextProps.isSmallScreenWidth) { | ||
return true; | ||
} | ||
|
||
if (this.props.isDrawerOpen !== nextProps.isDrawerOpen) { | ||
return true; | ||
} | ||
|
||
if (lodashGet(this.props.report, 'hasOutstandingIOU') !== lodashGet(nextProps.report, 'hasOutstandingIOU')) { | ||
return true; | ||
} | ||
|
||
if (this.props.isComposerFullSize !== nextProps.isComposerFullSize) { | ||
return true; | ||
} | ||
|
||
if (this.props.isSidebarLoaded !== nextProps.isSidebarLoaded) { | ||
return true; | ||
} | ||
|
||
if (this.props.personalDetails !== nextProps.personalDetails) { | ||
return true; | ||
} | ||
|
||
if (this.props.policies !== nextProps.policies) { | ||
return true; | ||
} | ||
|
||
if (this.props.betas !== nextProps.betas) { | ||
return true; | ||
} | ||
|
||
return !_.isEqual(lodashGet(this.props.report, 'icons', []), lodashGet(nextProps.report, 'icons', [])); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (this.props.route.params.reportID === prevProps.route.params.reportID) { | ||
return; | ||
|
@@ -139,6 +197,29 @@ class ReportScreen extends React.Component { | |
Report.addComment(getReportID(this.props.route), text); | ||
} | ||
|
||
/** | ||
* @param {Object} reportActions | ||
* @returns {Array} | ||
*/ | ||
getSortedReportActionsForDisplay(reportActions) { | ||
// HACK ALERT: We're temporarily filtering out any reportActions keyed by sequenceNumber | ||
// to prevent bugs during the migration from sequenceNumber -> reportActionID | ||
const filteredReportActions = _.filter(reportActions, (reportAction, key) => { | ||
if (!reportAction) { | ||
return false; | ||
} | ||
|
||
if (String(reportAction.sequenceNumber) === key) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
const sortedReportActions = ReportActionsUtils.getSortedReportActions(filteredReportActions, true); | ||
return ReportActionsUtils.filterReportActionsForDisplay(sortedReportActions); | ||
} | ||
|
||
/** | ||
* When false the ReportActionsView will completely unmount and we will show a loader until it returns true. | ||
* | ||
|
@@ -269,7 +350,7 @@ class ReportScreen extends React.Component { | |
{(this.isReportReadyForDisplay() && !isLoadingInitialReportActions) && ( | ||
<> | ||
<ReportActionsView | ||
reportActions={this.props.reportActions} | ||
reportActions={this.sortedAndFilteredReportActions} | ||
report={this.props.report} | ||
session={this.props.session} | ||
isComposerFullSize={this.props.isComposerFullSize} | ||
|
@@ -280,7 +361,7 @@ class ReportScreen extends React.Component { | |
errors={addWorkspaceRoomOrChatErrors} | ||
pendingAction={addWorkspaceRoomOrChatPendingAction} | ||
isOffline={this.props.network.isOffline} | ||
reportActions={this.props.reportActions} | ||
reportActions={this.sortedAndFilteredReportActions} | ||
report={this.props.report} | ||
isComposerFullSize={this.props.isComposerFullSize} | ||
onSubmitComment={this.onSubmitComment} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,12 +63,9 @@ class ReportActionsView extends React.Component { | |
this.unsubscribeVisibilityListener = null; | ||
this.hasCachedActions = _.size(props.reportActions) > 0; | ||
|
||
// We need this.sortedAndFilteredReportActions to be set before this.state is initialized because the function to calculate the newMarkerReportActionID uses the sorted report actions | ||
this.sortedAndFilteredReportActions = this.getSortedReportActionsForDisplay(props.reportActions); | ||
|
||
this.state = { | ||
isFloatingMessageCounterVisible: false, | ||
newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions), | ||
newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, props.reportActions), | ||
}; | ||
|
||
this.currentScrollOffset = 0; | ||
|
@@ -133,7 +130,6 @@ class ReportActionsView extends React.Component { | |
|
||
shouldComponentUpdate(nextProps, nextState) { | ||
if (!_.isEqual(nextProps.reportActions, this.props.reportActions)) { | ||
this.sortedAndFilteredReportActions = this.getSortedReportActionsForDisplay(nextProps.reportActions); | ||
this.mostRecentIOUReportActionID = ReportActionsUtils.getMostRecentIOUReportActionID(nextProps.reportActions); | ||
return true; | ||
} | ||
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. Is this required in here as well if we have added the logic to the ReportScreen? 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. Yes, the 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. @gedu sorry I wan not clear, I meant the big chunk of the 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. ohhhh got it, yes it is true, my bad, I miss it after some merge conflicts, updating PR |
||
|
@@ -204,16 +200,17 @@ class ReportActionsView extends React.Component { | |
if (didReportBecomeVisible) { | ||
this.setState({ | ||
newMarkerReportActionID: ReportUtils.isUnread(this.props.report) | ||
? ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions) | ||
? ReportUtils.getNewMarkerReportActionID(this.props.report, this.props.reportActions) | ||
: '', | ||
}); | ||
this.openReportIfNecessary(); | ||
} | ||
|
||
// If the report action marking the unread point is deleted we need to recalculate which action should be the unread marker | ||
if (this.state.newMarkerReportActionID && _.isEmpty(lodashGet(this.props.reportActions[this.state.newMarkerReportActionID], 'message[0].html'))) { | ||
// If the report is unread, we want to check if the number of actions has decreased. If so, then it seems that one of them was deleted. In this case, if the deleted action was the | ||
// one marking the unread point, we need to recalculate which action should be the unread marker. | ||
if (ReportUtils.isUnread(this.props.report) && ReportActionsUtils.filterReportActionsForDisplay(prevProps.reportActions).length > this.props.reportActions.length) { | ||
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. There's no 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. It was removed here c351930 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 will look at it thanks 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. yes, please remove here as well. App crashes right now when other sends message which makes 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. ok, cool, I will update it |
||
this.setState({ | ||
newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions), | ||
newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.props.reportActions), | ||
}); | ||
} | ||
|
||
|
@@ -230,7 +227,7 @@ class ReportActionsView extends React.Component { | |
const didManuallyMarkReportAsUnread = (prevProps.report.lastReadTime !== this.props.report.lastReadTime) | ||
&& ReportUtils.isUnread(this.props.report); | ||
if (didManuallyMarkReportAsUnread) { | ||
this.setState({newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions)}); | ||
this.setState({newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.props.reportActions)}); | ||
} | ||
|
||
// Ensures subscription event succeeds when the report/workspace room is created optimistically. | ||
|
@@ -308,7 +305,7 @@ class ReportActionsView extends React.Component { | |
return; | ||
} | ||
|
||
const oldestReportAction = _.last(this.sortedAndFilteredReportActions); | ||
const oldestReportAction = _.last(this.props.reportActions); | ||
|
||
// Don't load more chats if we're already at the beginning of the chat history | ||
if (oldestReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { | ||
|
@@ -372,7 +369,6 @@ class ReportActionsView extends React.Component { | |
if (!_.size(this.props.reportActions)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
{!this.props.isComposerFullSize && ( | ||
|
@@ -385,7 +381,7 @@ class ReportActionsView extends React.Component { | |
report={this.props.report} | ||
onScroll={this.trackScroll} | ||
onLayout={this.recordTimeToMeasureItemLayout} | ||
sortedReportActions={this.sortedAndFilteredReportActions} | ||
sortedReportActions={this.props.reportActions} | ||
mostRecentIOUReportActionID={this.mostRecentIOUReportActionID} | ||
isLoadingMoreReportActions={this.props.report.isLoadingMoreReportActions} | ||
loadMoreChats={this.loadMoreChats} | ||
|
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.
can we return true if
this.props.report
changed?I found regression (not refreshing) while adding/removing members.
i.e.
-This should not show Split bill on + menu.
This works fine on production
This happens because
report.participants
updated but not re-renderedThere 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.
I am asking this because this already does in
main
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.
@0xmiroslav so this is not a regression from this PR? I think if not, we can continue here and you can file a bug report for this case
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.
This PR causes that regression.
Here,
does
meansre-renders
becauseReportScreen
doesn't either extendPureComponent
or useshouldComponentUpdate
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.
Actually, I don't think we need
shouldComponentUpdate
inReportScreen
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.
@gedu For what optimization did you introduce
shouldComponentUpdate
inReportScreen
?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.
@0xmiroslav Hey, I've been looking at what you wrote and couldn't reproduce it like that, I could, following other steps, and only on web, mobile is working as expected.
Screen.Recording.2023-02-27.at.09.28.55.mp4
On the other hand, looking at the code, I see
#announce
and#admins
always will show Split Bill on the + menu (if there are 2 members). This was working (above in the video showing the only case isn't working).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.
I added the check to the reports as you suggested and is fixing the case I found, doing some round of testing and uploading fix, thanks
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.
@gedu you opened production site on left. please run this PR on both sides.
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.
Discussed it here and we determined that it's ok to filter/sort in
render()
. I think that we should do that and remove the derived state.