Skip to content

Commit b081a39

Browse files
authored
Merge pull request Expensify#64086 from FitseTLT/fix-adding-non-invoice-expense-in-invoice-type-search
2 parents bbd1fed + 7ee91e5 commit b081a39

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

src/libs/actions/IOU.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ import type {QuickActionName} from '@src/types/onyx/QuickAction';
210210
import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report';
211211
import type ReportAction from '@src/types/onyx/ReportAction';
212212
import type {OnyxData} from '@src/types/onyx/Request';
213-
import type {SearchDataTypes, SearchPolicy, SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults';
213+
import type {SearchPolicy, SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults';
214214
import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction';
215215
import {isEmptyObject} from '@src/types/utils/EmptyObject';
216216
import {clearByKey as clearPdfByOnyxKey} from './CachedPDFPaths';
@@ -645,6 +645,7 @@ type GetSearchOnyxUpdateParams = {
645645
transaction: OnyxTypes.Transaction;
646646
participant?: Participant;
647647
iouReport?: OnyxEntry<OnyxTypes.Report>;
648+
isInvoice?: boolean;
648649
transactionThreadReportID: string | undefined;
649650
};
650651

@@ -2322,6 +2323,7 @@ function buildOnyxDataForInvoice(invoiceParams: BuildOnyxDataForInvoiceParams):
23222323
const searchUpdate = getSearchOnyxUpdate({
23232324
transaction,
23242325
participant,
2326+
isInvoice: true,
23252327
transactionThreadReportID: transactionParams.threadReport.reportID,
23262328
});
23272329

@@ -11267,15 +11269,15 @@ function resolveDuplicates(params: MergeDuplicatesParams) {
1126711269
API.write(WRITE_COMMANDS.RESOLVE_DUPLICATES, parameters, {optimisticData, failureData});
1126811270
}
1126911271

11270-
function getSearchOnyxUpdate({participant, transaction, iouReport, transactionThreadReportID}: GetSearchOnyxUpdateParams): OnyxData | undefined {
11272+
function getSearchOnyxUpdate({participant, transaction, iouReport, transactionThreadReportID, isInvoice}: GetSearchOnyxUpdateParams): OnyxData | undefined {
1127111273
const toAccountID = participant?.accountID;
1127211274
const fromAccountID = currentUserPersonalDetails?.accountID;
1127311275
const currentSearchQueryJSON = getCurrentSearchQueryJSON();
1127411276

1127511277
if (currentSearchQueryJSON && toAccountID != null && fromAccountID != null) {
11276-
const validSearchTypes: SearchDataTypes[] = [CONST.SEARCH.DATA_TYPES.EXPENSE, CONST.SEARCH.DATA_TYPES.INVOICE];
11277-
const shouldOptimisticallyUpdate =
11278-
currentSearchQueryJSON.status === CONST.SEARCH.STATUS.EXPENSE.ALL && validSearchTypes.includes(currentSearchQueryJSON.type) && currentSearchQueryJSON.flatFilters.length === 0;
11278+
const validSearchTypes =
11279+
(!isInvoice && currentSearchQueryJSON.type === CONST.SEARCH.DATA_TYPES.EXPENSE) || (isInvoice && currentSearchQueryJSON.type === CONST.SEARCH.DATA_TYPES.INVOICE);
11280+
const shouldOptimisticallyUpdate = currentSearchQueryJSON.status === CONST.SEARCH.STATUS.EXPENSE.ALL && validSearchTypes && currentSearchQueryJSON.flatFilters.length === 0;
1127911281

1128011282
if (shouldOptimisticallyUpdate) {
1128111283
const isOptimisticToAccountData = isOptimisticPersonalDetail(toAccountID);

tests/actions/IOUTest.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ jest.mock('@src/libs/SearchQueryUtils', () => ({
123123
getCurrentSearchQueryJSON: jest.fn().mockImplementation(() => ({
124124
hash: 12345,
125125
query: 'test',
126+
type: 'invoice',
127+
status: 'all',
128+
flatFilters: [],
126129
})),
127130
}));
128131

@@ -792,6 +795,22 @@ describe('actions/IOU', () => {
792795
});
793796
}),
794797
)
798+
.then(
799+
() =>
800+
new Promise<void>((resolve) => {
801+
const connection = Onyx.connect({
802+
key: ONYXKEYS.COLLECTION.SNAPSHOT,
803+
waitForCollectionCallback: true,
804+
callback: (snapshotData) => {
805+
Onyx.disconnect(connection);
806+
807+
// Snapshot data shouldn't be updated optimistically for requestMoney when the current search query type is invoice.
808+
expect(snapshotData).toBeUndefined();
809+
resolve();
810+
},
811+
});
812+
}),
813+
)
795814
.then(mockFetch?.resume)
796815
.then(
797816
() =>

0 commit comments

Comments
 (0)