@@ -95,6 +95,67 @@ const defaultProps = {
95
95
} ;
96
96
97
97
class SidebarLinks extends React . Component {
98
+ shouldComponentUpdate ( nextProps ) {
99
+ // We do not want to re-order reports in the LHN if the only change is the draft comment in the
100
+ // current report.
101
+
102
+ // We don't need to limit draft comment flashing for small screen widths as LHN is not visible.
103
+ if ( nextProps . isSmallScreenWidth ) {
104
+ return true ;
105
+ }
106
+
107
+ const didActiveReportChange = this . props . currentlyViewedReportID !== nextProps . currentlyViewedReportID ;
108
+
109
+ // Always re-order the list whenever the active report is changed
110
+ if ( didActiveReportChange ) {
111
+ return true ;
112
+ }
113
+
114
+ const previousDraftComments = this . props . draftComments ;
115
+ const nextDraftComments = nextProps . draftComments ;
116
+
117
+ const previousDraftReports = Object . keys ( previousDraftComments ) ;
118
+ const nextDraftReports = Object . keys ( nextDraftComments ) ;
119
+
120
+ const reportsWithNewDraftComments = nextDraftReports . filter ( ( report ) => {
121
+ const isNewDraftComment = ! previousDraftReports . includes ( report ) ;
122
+ const wasNonEmptyDraftComment = previousDraftComments [ report ] === '' ;
123
+ const hasDraftCommentChanged = previousDraftComments [ report ] !== nextDraftComments [ report ] ;
124
+
125
+ return isNewDraftComment || ( hasDraftCommentChanged && wasNonEmptyDraftComment ) ;
126
+ } ) ;
127
+ const reportsWithRemovedDraftComments = previousDraftReports . filter ( ( report ) => {
128
+ const isRemovedDraftComment = ! nextDraftReports . includes ( report ) ;
129
+ const isEmptyDraftComment = nextDraftComments [ report ] === '' ;
130
+ const hasDraftCommentChanged = previousDraftComments [ report ] !== nextDraftComments [ report ] ;
131
+
132
+ return isRemovedDraftComment || ( hasDraftCommentChanged && isEmptyDraftComment ) ;
133
+ } ) ;
134
+ const reportsWithEditedDraftComments = nextDraftReports . filter ( ( report ) => {
135
+ const didDraftCommentExistPreviously = previousDraftReports . includes ( report ) ;
136
+ const hasDraftCommentChanged = previousDraftComments [ report ] !== nextDraftComments [ report ] ;
137
+ const isNotANewDraftComment = ! reportsWithNewDraftComments . includes ( report ) ;
138
+ const isNotARemovedDraftComment = ! reportsWithRemovedDraftComments . includes ( report ) ;
139
+
140
+ return didDraftCommentExistPreviously && hasDraftCommentChanged && isNotANewDraftComment && isNotARemovedDraftComment ;
141
+ } ) ;
142
+
143
+ const allReportsWithDraftCommentChanges = [
144
+ ...reportsWithNewDraftComments ,
145
+ ...reportsWithRemovedDraftComments ,
146
+ ...reportsWithEditedDraftComments ,
147
+ ] ;
148
+
149
+ const activeReportID = this . props . currentlyViewedReportID ;
150
+ const reportKey = `${ ONYXKEYS . COLLECTION . REPORT_DRAFT_COMMENT } ${ activeReportID } ` ;
151
+
152
+ // Do not re-order reports if draft comment changes are only in the current report.
153
+ if ( allReportsWithDraftCommentChanges . length === 1 && allReportsWithDraftCommentChanges . includes ( reportKey ) ) {
154
+ return false ;
155
+ }
156
+ return true ;
157
+ }
158
+
98
159
showSearchPage ( ) {
99
160
Navigation . navigate ( ROUTES . SEARCH ) ;
100
161
}
0 commit comments