1- import cloneDeep from 'lodash/cloneDeep' ;
21import isEmpty from 'lodash/isEmpty' ;
32import Onyx from 'react-native-onyx' ;
43import type { OnyxCollection , OnyxEntry , OnyxUpdate } from 'react-native-onyx' ;
@@ -17,7 +16,6 @@ import type {
1716 OpenBulkChangeApproverPageParams ,
1817 OpenSearchPageParams ,
1918 ReportExportParams ,
20- RevertSplitTransactionParams ,
2119 SubmitReportParams ,
2220} from '@libs/API/parameters' ;
2321import { READ_COMMANDS , SIDE_EFFECT_REQUEST_COMMANDS , WRITE_COMMANDS } from '@libs/API/types' ;
@@ -38,7 +36,6 @@ import {
3836 buildOptimisticIOUReportAction ,
3937 generateReportID ,
4038 getParsedComment ,
41- getReportOrDraftReport ,
4239 getReportTransactions ,
4340 hasHeldExpenses ,
4441 isExpenseReport ,
@@ -75,10 +72,8 @@ import type {PaymentInformation} from '@src/types/onyx/LastPaymentMethod';
7572import type { ConnectionName } from '@src/types/onyx/Policy' ;
7673import type { OnyxData } from '@src/types/onyx/Request' ;
7774import type Nullable from '@src/types/utils/Nullable' ;
78- import type PrefixedRecord from '@src/types/utils/PrefixedRecord' ;
7975import SafeString from '@src/utils/SafeString' ;
8076import { setPersonalBankAccountContinueKYCOnSuccess } from './BankAccounts' ;
81- import { getReportPreviewAction } from './IOU' ;
8277import { deleteMoneyRequest } from './IOU/DeleteMoneyRequest' ;
8378import { prepareRejectMoneyRequestData , rejectMoneyRequest } from './IOU/RejectMoneyRequest' ;
8479import type { RejectMoneyRequestData } from './IOU/RejectMoneyRequest' ;
@@ -991,161 +986,6 @@ function bulkDeleteReports({
991986 }
992987}
993988
994- function revertSplitTransactionOnSearch (
995- hash : number ,
996- originalTransactionID : string ,
997- params : RevertSplitTransactionParams ,
998- optimisticDeletedSplitTransactions : PrefixedRecord < typeof ONYXKEYS . COLLECTION . TRANSACTION , Transaction > = { } ,
999- optimisticRestoredTransaction ?: Transaction ,
1000- optimisticOriginalTransaction ?: Transaction ,
1001- previousSnapshotOriginalTransaction ?: Transaction ,
1002- ) {
1003- let optimisticData : Array <
1004- OnyxUpdate < typeof ONYXKEYS . COLLECTION . REPORT | typeof ONYXKEYS . COLLECTION . REPORT_ACTIONS | typeof ONYXKEYS . COLLECTION . SNAPSHOT | typeof ONYXKEYS . COLLECTION . TRANSACTION >
1005- > = [ ] ;
1006- let failureData : Array <
1007- OnyxUpdate < typeof ONYXKEYS . COLLECTION . REPORT | typeof ONYXKEYS . COLLECTION . REPORT_ACTIONS | typeof ONYXKEYS . COLLECTION . SNAPSHOT | typeof ONYXKEYS . COLLECTION . TRANSACTION >
1008- > = [ ] ;
1009- const successData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . REPORT | typeof ONYXKEYS . COLLECTION . REPORT_ACTIONS > > = [ ] ;
1010- let finallyData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . SNAPSHOT > > = [ ] ;
1011-
1012- if ( Object . keys ( optimisticDeletedSplitTransactions ) . length > 0 && optimisticRestoredTransaction ) {
1013- const { optimisticData : loadingOptimisticData , finallyData : loadingFinallyData } = getOnyxLoadingData ( hash ) ;
1014- optimisticData = [ ...( loadingOptimisticData ?? [ ] ) ] ;
1015- finallyData = [ ...( loadingFinallyData ?? [ ] ) ] ;
1016- const iouReport = params . reportID ? getReportOrDraftReport ( params . reportID ) : undefined ;
1017- const previousIOUReport = cloneDeep ( iouReport ?? null ) ;
1018- const reportPreviewAction = getReportPreviewAction ( iouReport ?. chatReportID , iouReport ?. reportID ) ;
1019- const previousReportPreviewAction = cloneDeep ( reportPreviewAction ?? null ) ;
1020-
1021- const deletedSplitEntries = Object . fromEntries ( Object . keys ( optimisticDeletedSplitTransactions ) . map ( ( transactionKey ) => [ transactionKey , null ] ) ) as PrefixedRecord <
1022- typeof ONYXKEYS . COLLECTION . TRANSACTION ,
1023- null
1024- > ;
1025-
1026- const optimisticSnapshotData : PrefixedRecord < typeof ONYXKEYS . COLLECTION . TRANSACTION , Transaction | null > = {
1027- ...deletedSplitEntries ,
1028- [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ originalTransactionID } ` ] : optimisticRestoredTransaction ,
1029- } ;
1030-
1031- const optimisticSnapshotUpdate : OnyxUpdate < typeof ONYXKEYS . COLLECTION . SNAPSHOT > = {
1032- onyxMethod : Onyx . METHOD . MERGE ,
1033- key : `${ ONYXKEYS . COLLECTION . SNAPSHOT } ${ hash } ` ,
1034- value : {
1035- data : {
1036- ...optimisticSnapshotData ,
1037- } ,
1038- } ,
1039- } ;
1040- optimisticData . push ( optimisticSnapshotUpdate ) ;
1041- // Keep the transaction collection in sync for screens that do not render from the search snapshot.
1042- optimisticData . push (
1043- ...Object . keys ( optimisticDeletedSplitTransactions ) . map (
1044- ( transactionKey ) =>
1045- ( {
1046- onyxMethod : Onyx . METHOD . SET ,
1047- key : transactionKey ,
1048- value : null ,
1049- } ) as OnyxUpdate < typeof ONYXKEYS . COLLECTION . TRANSACTION > ,
1050- ) ,
1051- {
1052- onyxMethod : Onyx . METHOD . SET ,
1053- key : `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ originalTransactionID } ` ,
1054- value : optimisticRestoredTransaction ,
1055- } ,
1056- ) ;
1057-
1058- if ( params . reportID ) {
1059- optimisticData . push ( {
1060- onyxMethod : Onyx . METHOD . MERGE ,
1061- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ params . reportID } ` ,
1062- value : {
1063- reportID : null ,
1064- pendingFields : {
1065- preview : CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ,
1066- } ,
1067- } ,
1068- } ) ;
1069-
1070- successData . push ( {
1071- onyxMethod : Onyx . METHOD . SET ,
1072- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ params . reportID } ` ,
1073- value : null ,
1074- } ) ;
1075-
1076- failureData . push ( {
1077- onyxMethod : Onyx . METHOD . SET ,
1078- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ params . reportID } ` ,
1079- value : previousIOUReport ,
1080- } ) ;
1081- }
1082-
1083- if ( previousReportPreviewAction ?. reportActionID && iouReport ?. chatReportID ) {
1084- const updatedReportPreviewAction : Partial < ReportAction < typeof CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW > > = cloneDeep ( previousReportPreviewAction ) ;
1085- updatedReportPreviewAction . pendingAction = CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ;
1086-
1087- optimisticData . push ( {
1088- onyxMethod : Onyx . METHOD . MERGE ,
1089- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport . chatReportID } ` ,
1090- value : { [ previousReportPreviewAction . reportActionID ] : updatedReportPreviewAction } ,
1091- } ) ;
1092-
1093- successData . push ( {
1094- onyxMethod : Onyx . METHOD . MERGE ,
1095- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport . chatReportID } ` ,
1096- value : {
1097- [ previousReportPreviewAction . reportActionID ] : {
1098- pendingAction : null ,
1099- errors : null ,
1100- } ,
1101- } ,
1102- } ) ;
1103-
1104- failureData . push ( {
1105- onyxMethod : Onyx . METHOD . MERGE ,
1106- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReport . chatReportID } ` ,
1107- value : {
1108- [ previousReportPreviewAction . reportActionID ] : previousReportPreviewAction ,
1109- } ,
1110- } ) ;
1111- }
1112-
1113- const failureSnapshotData : PrefixedRecord < typeof ONYXKEYS . COLLECTION . TRANSACTION , Transaction | null > = {
1114- ...optimisticDeletedSplitTransactions ,
1115- [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ originalTransactionID } ` ] : previousSnapshotOriginalTransaction ?? null ,
1116- } ;
1117-
1118- const failureSnapshotUpdate : OnyxUpdate < typeof ONYXKEYS . COLLECTION . SNAPSHOT > = {
1119- onyxMethod : Onyx . METHOD . MERGE ,
1120- key : `${ ONYXKEYS . COLLECTION . SNAPSHOT } ${ hash } ` ,
1121- value : {
1122- data : {
1123- ...failureSnapshotData ,
1124- } ,
1125- } ,
1126- } ;
1127- failureData = [
1128- ...failureData ,
1129- failureSnapshotUpdate ,
1130- ...Object . entries ( optimisticDeletedSplitTransactions ) . map (
1131- ( [ transactionKey , transaction ] ) =>
1132- ( {
1133- onyxMethod : Onyx . METHOD . SET ,
1134- key : transactionKey ,
1135- value : transaction ,
1136- } ) as OnyxUpdate < typeof ONYXKEYS . COLLECTION . TRANSACTION > ,
1137- ) ,
1138- {
1139- onyxMethod : Onyx . METHOD . SET ,
1140- key : `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ originalTransactionID } ` ,
1141- value : optimisticOriginalTransaction ?? null ,
1142- } ,
1143- ] ;
1144- }
1145-
1146- API . write ( WRITE_COMMANDS . REVERT_SPLIT_TRANSACTION , params , { optimisticData, successData, failureData, finallyData} ) ;
1147- }
1148-
1149989function rejectMoneyRequestInBulk (
1150990 reportID : string ,
1151991 comment : string ,
@@ -1703,7 +1543,6 @@ function setOptimisticDataForTransactionThreadPreview(item: TransactionListItemT
17031543export {
17041544 saveSearch ,
17051545 search ,
1706- revertSplitTransactionOnSearch ,
17071546 bulkDeleteReports ,
17081547 rejectMoneyRequestsOnSearch ,
17091548 exportSearchItemsToCSV ,
@@ -1723,7 +1562,6 @@ export {
17231562 getLastPolicyBankAccountID ,
17241563 exportToIntegrationOnSearch ,
17251564 getPayOption ,
1726- isValidBulkPayOption ,
17271565 handleBulkPayItemSelected ,
17281566 isCurrencySupportWalletBulkPay ,
17291567 getExportTemplates ,
0 commit comments