1- import type { OnyxEntry , OnyxUpdate } from 'react-native-onyx' ;
1+ import type { OnyxUpdate } from 'react-native-onyx' ;
22import Onyx from 'react-native-onyx' ;
33import CONST from '@src/CONST' ;
44import type { OnyxKey } from '@src/ONYXKEYS' ;
@@ -11,7 +11,7 @@ import {compute, FORMULA_PART_TYPES, parse} from './Formula';
1111import Log from './Log' ;
1212import type { UpdateContext } from './OptimisticReportNamesConnectionManager' ;
1313import Permissions from './Permissions' ;
14- import { isArchivedReport , isValidReport } from './ReportUtils' ;
14+ import { isArchivedReport } from './ReportUtils' ;
1515
1616/**
1717 * Get the title field from report name value pairs
@@ -175,49 +175,6 @@ function isValidReportType(reportType?: string): boolean {
175175 ) ;
176176}
177177
178- /**
179- * Checks if a report is partial/incomplete by validating essential fields.
180- */
181- function isPartialReport ( report : Partial < Report > ) : boolean {
182- if ( ! report ) {
183- return true ;
184- }
185-
186- // These fields are the ONLY ones ALWAYS set in ALL optimistic report building functions
187- const hasEssentialFields = report . reportID && report . type && report . ownerAccountID !== undefined && report . stateNum !== undefined && report . statusNum !== undefined ;
188-
189- return ! hasEssentialFields ;
190- }
191-
192- /**
193- * Returns the first update containing the most complete Report in the batch.
194- */
195- function getReportFromUpdates ( reportID : string , updates : OnyxUpdate [ ] ) : Report | undefined {
196- if ( ! reportID ) {
197- return undefined ;
198- }
199- const reportKey = getReportKey ( reportID ) ;
200-
201- const report = updates . find ( ( update ) => {
202- if ( update . key !== reportKey ) {
203- return false ;
204- }
205-
206- const reportUpdate = update . value as OnyxEntry < Report > | undefined ;
207- if ( ! reportUpdate || ! isValidReport ( reportUpdate ) || ! isValidReportType ( reportUpdate . type ) ) {
208- return false ;
209- }
210-
211- if ( isPartialReport ( reportUpdate ) ) {
212- return false ;
213- }
214-
215- return true ;
216- } ) ?. value as Report | undefined ;
217-
218- return report ;
219- }
220-
221178/**
222179 * Compute a new report name if needed based on an optimistic update
223180 */
@@ -366,15 +323,6 @@ function updateOptimisticReportNamesFromUpdates(updates: OnyxUpdate[], context:
366323 report = getReportByTransactionID ( getTransactionIDFromKey ( update . key ) , context ) ;
367324 }
368325
369- // Send the latest report data to `compute()` for transaction updates, just like for report updates.
370- // Without this, if a batch includes both report and transaction updates,
371- // the report name could be computed with stale data and overwrite the correct one.
372- const reportID = report ?. reportID ?? transactionUpdate . reportID ;
373- const reportUpdate = reportID ? getReportFromUpdates ( reportID , updates ) : undefined ;
374- if ( reportUpdate ) {
375- report = { ...( report ?? { } ) , ...reportUpdate } ;
376- }
377-
378326 if ( report ) {
379327 const reportNameUpdate = computeReportNameIfNeeded ( report , update , context ) ;
380328
0 commit comments