Skip to content

Commit e2aec0b

Browse files
committed
fix stale data issue in components that use report data and display options list
1 parent ab9b7d9 commit e2aec0b

File tree

4 files changed

+77
-13
lines changed

4 files changed

+77
-13
lines changed

src/pages/NewChatPage.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const propTypes = {
3232
/** All reports shared with the user */
3333
reports: PropTypes.objectOf(reportPropTypes),
3434

35+
/** Indicates whether the reports data is ready */
36+
isLoadingReportData: PropTypes.bool,
37+
3538
...windowDimensionsPropTypes,
3639

3740
...withLocalizePropTypes,
@@ -42,6 +45,7 @@ const defaultProps = {
4245
betas: [],
4346
personalDetails: {},
4447
reports: {},
48+
isLoadingReportData: true,
4549
};
4650

4751
class NewChatPage extends Component {
@@ -75,6 +79,13 @@ class NewChatPage extends Component {
7579
};
7680
}
7781

82+
componentDidUpdate(prevProps) {
83+
if (prevProps.isLoadingReportData === this.props.isLoadingReportData) {
84+
return;
85+
}
86+
this.updateOptionsWithSearchTerm(this.state.searchTerm);
87+
}
88+
7889
/**
7990
* Returns the sections needed for the OptionsSelector
8091
*
@@ -255,6 +266,7 @@ class NewChatPage extends Component {
255266
boldStyle
256267
shouldFocusOnSelectRow={this.props.isGroupChat}
257268
shouldShowConfirmButton={this.props.isGroupChat}
269+
shouldShowOptions={!this.props.isLoadingReportData}
258270
confirmButtonText={this.props.translate('newChatPage.createGroup')}
259271
onConfirmSelection={this.createGroup}
260272
placeholderText={this.props.translate('optionsSelector.nameEmailOrPhoneNumber')}
@@ -287,5 +299,8 @@ export default compose(
287299
betas: {
288300
key: ONYXKEYS.BETAS,
289301
},
302+
isLoadingReportData: {
303+
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
304+
},
290305
}),
291306
)(NewChatPage);

src/pages/SearchPage.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import compose from '../libs/compose';
2020
import personalDetailsPropType from './personalDetailsPropType';
2121
import reportPropTypes from './reportPropTypes';
2222
import Performance from '../libs/Performance';
23+
import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator';
2324

2425
const propTypes = {
2526
/* Onyx Props */
@@ -33,6 +34,9 @@ const propTypes = {
3334
/** All reports shared with the user */
3435
reports: PropTypes.objectOf(reportPropTypes),
3536

37+
/** Indicates whether report data is ready */
38+
isLoadingReportData: PropTypes.bool,
39+
3640
/** Window Dimensions Props */
3741
...windowDimensionsPropTypes,
3842

@@ -43,6 +47,7 @@ const defaultProps = {
4347
betas: [],
4448
personalDetails: {},
4549
reports: {},
50+
isLoadingReportData: true,
4651
};
4752

4853
class SearchPage extends Component {
@@ -76,6 +81,13 @@ class SearchPage extends Component {
7681
};
7782
}
7883

84+
componentDidUpdate(prevProps) {
85+
if (prevProps.isLoadingReportData === this.props.isLoadingReportData) {
86+
return;
87+
}
88+
this.updateOptions();
89+
}
90+
7991
onChangeText(searchValue = '') {
8092
this.setState({searchValue}, this.debouncedUpdateOptions);
8193
}
@@ -178,19 +190,23 @@ class SearchPage extends Component {
178190
onCloseButtonPress={() => Navigation.dismissModal(true)}
179191
/>
180192
<View style={[styles.flex1, styles.w100, styles.pRelative]}>
181-
<OptionsSelector
182-
sections={sections}
183-
value={this.state.searchValue}
184-
onSelectRow={this.selectReport}
185-
onChangeText={this.onChangeText}
186-
headerMessage={headerMessage}
187-
hideSectionHeaders
188-
showTitleTooltip
189-
shouldShowOptions={didScreenTransitionEnd}
190-
placeholderText={this.props.translate('optionsSelector.nameEmailOrPhoneNumber')}
191-
onLayout={this.searchRendered}
192-
safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle}
193-
/>
193+
{didScreenTransitionEnd ? (
194+
<OptionsSelector
195+
sections={sections}
196+
value={this.state.searchValue}
197+
onSelectRow={this.selectReport}
198+
onChangeText={this.onChangeText}
199+
headerMessage={headerMessage}
200+
hideSectionHeaders
201+
showTitleTooltip
202+
shouldShowOptions={!this.props.isLoadingReportData}
203+
placeholderText={this.props.translate('optionsSelector.nameEmailOrPhoneNumber')}
204+
onLayout={this.searchRendered}
205+
safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle}
206+
/>
207+
) : (
208+
<FullScreenLoadingIndicator />
209+
)}
194210
</View>
195211
</>
196212
)}
@@ -215,5 +231,8 @@ export default compose(
215231
betas: {
216232
key: ONYXKEYS.BETAS,
217233
},
234+
isLoadingReportData: {
235+
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
236+
},
218237
}),
219238
)(SearchPage);

src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const propTypes = {
2727
/** All reports shared with the user */
2828
reports: PropTypes.objectOf(reportPropTypes),
2929

30+
/** Indicates whether report data is ready */
31+
isLoadingReportData: PropTypes.bool,
32+
3033
/** padding bottom style of safe area */
3134
safeAreaPaddingBottomStyle: PropTypes.oneOfType([
3235
PropTypes.arrayOf(PropTypes.object),
@@ -44,6 +47,7 @@ const defaultProps = {
4447
personalDetails: {},
4548
reports: {},
4649
betas: [],
50+
isLoadingReportData: true,
4751
};
4852

4953
class MoneyRequestParticipantsSelector extends Component {
@@ -67,6 +71,13 @@ class MoneyRequestParticipantsSelector extends Component {
6771
};
6872
}
6973

74+
componentDidUpdate(prevProps) {
75+
if (prevProps.isLoadingReportData === this.props.isLoadingReportData) {
76+
return;
77+
}
78+
this.updateOptionsWithSearchTerm(this.state.searchTerm);
79+
}
80+
7081
/**
7182
* @param {string} searchTerm
7283
* @returns {Object}
@@ -164,6 +175,7 @@ class MoneyRequestParticipantsSelector extends Component {
164175
placeholderText={this.props.translate('optionsSelector.nameEmailOrPhoneNumber')}
165176
boldStyle
166177
safeAreaPaddingBottomStyle={this.props.safeAreaPaddingBottomStyle}
178+
shouldShowOptions={!this.props.isLoadingReportData}
167179
/>
168180
);
169181
}
@@ -184,5 +196,8 @@ export default compose(
184196
betas: {
185197
key: ONYXKEYS.BETAS,
186198
},
199+
isLoadingReportData: {
200+
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
201+
},
187202
}),
188203
)(MoneyRequestParticipantsSelector);

src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSplitSelector.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const propTypes = {
4949
PropTypes.object,
5050
]),
5151

52+
/** Indicates whether report data is ready */
53+
isLoadingReportData: PropTypes.bool,
54+
5255
...withLocalizePropTypes,
5356
};
5457

@@ -58,6 +61,7 @@ const defaultProps = {
5861
personalDetails: {},
5962
reports: {},
6063
safeAreaPaddingBottomStyle: {},
64+
isLoadingReportData: true,
6165
};
6266

6367
class MoneyRequestParticipantsSplitSelector extends Component {
@@ -89,6 +93,13 @@ class MoneyRequestParticipantsSplitSelector extends Component {
8993
};
9094
}
9195

96+
componentDidUpdate(prevProps) {
97+
if (prevProps.isLoadingReportData === this.props.isLoadingReportData) {
98+
return;
99+
}
100+
this.updateOptionsWithSearchTerm(this.state.searchTerm);
101+
}
102+
92103
/**
93104
* Returns the sections needed for the OptionsSelector
94105
*
@@ -238,6 +249,7 @@ class MoneyRequestParticipantsSplitSelector extends Component {
238249
onConfirmSelection={this.finalizeParticipants}
239250
placeholderText={this.props.translate('optionsSelector.nameEmailOrPhoneNumber')}
240251
safeAreaPaddingBottomStyle={this.props.safeAreaPaddingBottomStyle}
252+
shouldShowOptions={!this.props.isLoadingReportData}
241253
/>
242254
</View>
243255
);
@@ -259,5 +271,8 @@ export default compose(
259271
betas: {
260272
key: ONYXKEYS.BETAS,
261273
},
274+
isLoadingReportData: {
275+
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
276+
},
262277
}),
263278
)(MoneyRequestParticipantsSplitSelector);

0 commit comments

Comments
 (0)