@@ -137,6 +137,8 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
137137 const { translate} = useLocalize ( ) ;
138138 const reportIDFromRoute = getNonEmptyStringOnyxID ( route . params ?. reportID ) ;
139139 const reportActionIDFromRoute = route ?. params ?. reportActionID ;
140+ const parentReportIDFromRoute = route ?. params ?. parentReportID ;
141+ const parentReportActionIDFromRoute = route ?. params ?. parentReportActionID ;
140142 const isFocused = useIsFocused ( ) ;
141143 const prevIsFocused = usePrevious ( isFocused ) ;
142144 const firstRenderRef = useRef ( true ) ;
@@ -157,9 +159,9 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
157159 const [ reportNameValuePairsOnyx ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_NAME_VALUE_PAIRS } ${ reportIDFromRoute } ` , { allowStaleData : true , canBeMissing : true } ) ;
158160 const [ reportMetadata = defaultReportMetadata ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ reportIDFromRoute } ` , { canBeMissing : true , allowStaleData : true } ) ;
159161 const [ policies = getEmptyObject < NonNullable < OnyxCollection < OnyxTypes . Policy > > > ( ) ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY , { allowStaleData : true , canBeMissing : false } ) ;
160- const [ parentReportAction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ getNonEmptyStringOnyxID ( reportOnyx ?. parentReportID ) } ` , {
162+ const [ parentReportAction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ getNonEmptyStringOnyxID ( reportOnyx ?. parentReportID ?? parentReportIDFromRoute ) } ` , {
161163 canEvict : false ,
162- selector : ( parentReportActions ) => getParentReportAction ( parentReportActions , reportOnyx ?. parentReportActionID ) ,
164+ selector : ( parentReportActions ) => getParentReportAction ( parentReportActions , reportOnyx ?. parentReportActionID ?? parentReportActionIDFromRoute ) ,
163165 canBeMissing : true ,
164166 } ) ;
165167 const deletedParentAction = isDeletedParentAction ( parentReportAction ) ;
@@ -205,6 +207,8 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
205207 return '' ;
206208 } , [ accountManagerReportID , accountManagerReport , personalDetails , translate ] ) ;
207209
210+ const [ parentReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReportIDFromRoute } ` , { canBeMissing : true } ) ;
211+
208212 /**
209213 * Create a lightweight Report so as to keep the re-rendering as light as possible by
210214 * passing in only the required props.
@@ -215,48 +219,58 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
215219 */
216220 const report = useMemo (
217221 ( ) =>
218- reportOnyx && {
219- lastReadTime : reportOnyx . lastReadTime ,
220- reportID : reportOnyx . reportID ,
221- policyID : reportOnyx . policyID ,
222- lastVisibleActionCreated : reportOnyx . lastVisibleActionCreated ,
223- statusNum : reportOnyx . statusNum ,
224- stateNum : reportOnyx . stateNum ,
225- writeCapability : reportOnyx . writeCapability ,
226- type : reportOnyx . type ,
227- errorFields : reportOnyx . errorFields ,
228- parentReportID : reportOnyx . parentReportID ,
229- parentReportActionID : reportOnyx . parentReportActionID ,
230- chatType : reportOnyx . chatType ,
231- pendingFields : reportOnyx . pendingFields ,
232- isDeletedParentAction : reportOnyx . isDeletedParentAction ,
233- reportName : reportOnyx . reportName ,
234- description : reportOnyx . description ,
235- managerID : reportOnyx . managerID ,
236- total : reportOnyx . total ,
237- nonReimbursableTotal : reportOnyx . nonReimbursableTotal ,
238- fieldList : reportOnyx . fieldList ,
239- ownerAccountID : reportOnyx . ownerAccountID ,
240- currency : reportOnyx . currency ,
241- unheldTotal : reportOnyx . unheldTotal ,
242- unheldNonReimbursableTotal : reportOnyx . unheldNonReimbursableTotal ,
243- participants : reportOnyx . participants ,
244- isWaitingOnBankAccount : reportOnyx . isWaitingOnBankAccount ,
245- iouReportID : reportOnyx . iouReportID ,
246- isOwnPolicyExpenseChat : reportOnyx . isOwnPolicyExpenseChat ,
247- isPinned : reportOnyx . isPinned ,
248- chatReportID : reportOnyx . chatReportID ,
249- visibility : reportOnyx . visibility ,
250- oldPolicyName : reportOnyx . oldPolicyName ,
251- policyName : reportOnyx . policyName ,
252- private_isArchived : reportNameValuePairsOnyx ?. private_isArchived ,
253- lastMentionedTime : reportOnyx . lastMentionedTime ,
254- avatarUrl : reportOnyx . avatarUrl ,
255- permissions,
256- invoiceReceiver : reportOnyx . invoiceReceiver ,
257- policyAvatar : reportOnyx . policyAvatar ,
258- } ,
259- [ reportOnyx , reportNameValuePairsOnyx , permissions ] ,
222+ // This is required to get the transaction data from the parent report, to render the optimistic transaction thread
223+ parentReportIDFromRoute && parentReportActionIDFromRoute
224+ ? ( {
225+ ...reportOnyx ,
226+ reportID : reportIDFromRoute ,
227+ parentReportID : parentReportIDFromRoute ,
228+ parentReportActionID : parentReportActionIDFromRoute ,
229+ policyID : parentReport ?. policyID ,
230+ type : CONST . REPORT . TYPE . CHAT ,
231+ } as OnyxTypes . Report )
232+ : reportOnyx && {
233+ lastReadTime : reportOnyx . lastReadTime ,
234+ reportID : reportOnyx . reportID ,
235+ policyID : reportOnyx . policyID ,
236+ lastVisibleActionCreated : reportOnyx . lastVisibleActionCreated ,
237+ statusNum : reportOnyx . statusNum ,
238+ stateNum : reportOnyx . stateNum ,
239+ writeCapability : reportOnyx . writeCapability ,
240+ type : reportOnyx . type ,
241+ errorFields : reportOnyx . errorFields ,
242+ parentReportID : reportOnyx . parentReportID ,
243+ parentReportActionID : reportOnyx . parentReportActionID ,
244+ chatType : reportOnyx . chatType ,
245+ pendingFields : reportOnyx . pendingFields ,
246+ isDeletedParentAction : reportOnyx . isDeletedParentAction ,
247+ reportName : reportOnyx . reportName ,
248+ description : reportOnyx . description ,
249+ managerID : reportOnyx . managerID ,
250+ total : reportOnyx . total ,
251+ nonReimbursableTotal : reportOnyx . nonReimbursableTotal ,
252+ fieldList : reportOnyx . fieldList ,
253+ ownerAccountID : reportOnyx . ownerAccountID ,
254+ currency : reportOnyx . currency ,
255+ unheldTotal : reportOnyx . unheldTotal ,
256+ unheldNonReimbursableTotal : reportOnyx . unheldNonReimbursableTotal ,
257+ participants : reportOnyx . participants ,
258+ isWaitingOnBankAccount : reportOnyx . isWaitingOnBankAccount ,
259+ iouReportID : reportOnyx . iouReportID ,
260+ isOwnPolicyExpenseChat : reportOnyx . isOwnPolicyExpenseChat ,
261+ isPinned : reportOnyx . isPinned ,
262+ chatReportID : reportOnyx . chatReportID ,
263+ visibility : reportOnyx . visibility ,
264+ oldPolicyName : reportOnyx . oldPolicyName ,
265+ policyName : reportOnyx . policyName ,
266+ private_isArchived : reportNameValuePairsOnyx ?. private_isArchived ,
267+ lastMentionedTime : reportOnyx . lastMentionedTime ,
268+ avatarUrl : reportOnyx . avatarUrl ,
269+ permissions,
270+ invoiceReceiver : reportOnyx . invoiceReceiver ,
271+ policyAvatar : reportOnyx . policyAvatar ,
272+ } ,
273+ [ parentReportIDFromRoute , parentReportActionIDFromRoute , reportOnyx , reportIDFromRoute , parentReport ?. policyID , reportNameValuePairsOnyx ?. private_isArchived , permissions ] ,
260274 ) ;
261275 const reportID = report ?. reportID ;
262276
@@ -308,7 +322,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
308322 } ) ;
309323 const combinedReportActions = getCombinedReportActions ( reportActions , transactionThreadReportID ?? null , Object . values ( transactionThreadReportActions ) ) ;
310324 const lastReportAction = [ ...combinedReportActions , parentReportAction ] . find ( ( action ) => canEditReportAction ( action ) && ! isMoneyRequestAction ( action ) ) ;
311- const policy = policies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ report ?. policyID } ` ] ;
325+ const policy = policies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ report ?. policyID ?? parentReport ?. policyID } ` ] ;
312326 const isTopMostReportId = currentReportIDValue ?. currentReportID === reportIDFromRoute ;
313327 const didSubscribeToReportLeavingEvents = useRef ( false ) ;
314328 const isTransactionThreadView = isReportTransactionThread ( report ) ;
@@ -370,6 +384,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
370384 < MoneyRequestHeader
371385 report = { report }
372386 policy = { policy }
387+ backTo = { backTo }
373388 parentReportAction = { parentReportAction }
374389 onBackButtonPress = { onBackButtonPress }
375390 />
@@ -817,11 +832,12 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
817832 < ReportActionsView
818833 report = { report }
819834 reportActions = { reportActions }
820- isLoadingInitialReportActions = { reportMetadata ?. isLoadingInitialReportActions }
835+ isLoadingInitialReportActions = { reportMetadata ?. isLoadingInitialReportActions && ! isTransactionThreadView }
821836 hasNewerActions = { hasNewerActions }
822837 hasOlderActions = { hasOlderActions }
823838 parentReportAction = { parentReportAction }
824839 transactionThreadReportID = { transactionThreadReportID }
840+ isReportTransactionThread = { isTransactionThreadView }
825841 />
826842 ) : null }
827843 { ! ! report && shouldDisplayMoneyRequestActionsList && ! shouldWaitForTransactions ? (
0 commit comments