Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libs/actions/IOU/PerDiem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import {updateIOUOwnerAndTotal} from '@libs/IOUUtils';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import {validateAmount} from '@libs/MoneyRequestUtils';
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
import Navigation from '@libs/Navigation/Navigation';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {buildNextStepNew, buildOptimisticNextStep} from '@libs/NextStepUtils';
Expand Down Expand Up @@ -38,6 +39,7 @@ import playSound, {SOUNDS} from '@libs/Sound';
import {buildOptimisticTransaction} from '@libs/TransactionUtils';
import {buildOptimisticPolicyRecentlyUsedTags} from '@userActions/Policy/Tag';
import {notifyNewAction} from '@userActions/Report';
import {mergeTransactionIdsHighlightOnSearchRoute} from '@userActions/Transaction';
import {removeDraftTransaction} from '@userActions/TransactionEdit';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -999,6 +1001,11 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf

// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));

if (isFromGlobalCreate && !isReportTopmostSplitNavigator() && transaction.transactionID) {
mergeTransactionIdsHighlightOnSearchRoute(CONST.SEARCH.DATA_TYPES.EXPENSE, {[transaction.transactionID]: true});
}

handleNavigateAfterExpenseCreate({activeReportID, transactionID: transaction.transactionID, isFromGlobalCreate, shouldHandleNavigation});

if (activeReportID) {
Expand Down
6 changes: 6 additions & 0 deletions src/libs/actions/IOU/SendInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DateUtils from '@libs/DateUtils';
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import Log from '@libs/Log';
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
import {getReportActionHtml, getReportActionText} from '@libs/ReportActionsUtils';
import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction} from '@libs/ReportUtils';
import {
Expand All @@ -23,6 +24,7 @@ import {startSpan} from '@libs/telemetry/activeSpans';
import {buildOptimisticTransaction} from '@libs/TransactionUtils';
import {buildOptimisticPolicyRecentlyUsedTags} from '@userActions/Policy/Tag';
import {notifyNewAction} from '@userActions/Report';
import {mergeTransactionIdsHighlightOnSearchRoute} from '@userActions/Transaction';
import {removeDraftTransaction} from '@userActions/TransactionEdit';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -818,6 +820,10 @@ function sendInvoice({
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));

if (isFromGlobalCreate && !isReportTopmostSplitNavigator() && transactionID) {
mergeTransactionIdsHighlightOnSearchRoute(CONST.SEARCH.DATA_TYPES.INVOICE, {[transactionID]: true});
}

handleNavigateAfterExpenseCreate({
activeReportID: invoiceRoom.reportID,
transactionID,
Expand Down
19 changes: 14 additions & 5 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction';
import type {FileObject} from '@src/types/utils/Attachment';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {resolveDetachReceiptConflicts} from '../RequestConflictUtils';

Check warning on line 264 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected parent import '../RequestConflictUtils'. Use '@userActions/RequestConflictUtils' instead

type IOURequestType = ValueOf<typeof CONST.IOU.REQUEST_TYPE>;

Expand Down Expand Up @@ -779,7 +779,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 782 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -909,7 +909,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 912 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -923,7 +923,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 926 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -932,7 +932,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 935 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -946,7 +946,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 949 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -959,7 +959,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 962 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -968,7 +968,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 971 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -978,7 +978,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 981 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -987,7 +987,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 990 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand Down Expand Up @@ -1174,15 +1174,12 @@
return;
}

const type = isInvoice ? CONST.SEARCH.DATA_TYPES.INVOICE : CONST.SEARCH.DATA_TYPES.EXPENSE;

// We mark this transaction to be highlighted when opening the expense search route page
mergeTransactionIdsHighlightOnSearchRoute(type, {[transactionID]: true});

if (!shouldHandleNavigation) {
return;
}

const type = isInvoice ? CONST.SEARCH.DATA_TYPES.INVOICE : CONST.SEARCH.DATA_TYPES.EXPENSE;

// When already on Search ROOT with the same type (expense vs invoice), we navigate to the same screen (no-op or refresh); record as dismiss_modal_only.
// When on another Search sub-tab (e.g. Chats), or on Search with a different type (e.g. on Invoice, submitting expense), record as navigate_to_search.
const rootState = navigationRef.getRootState();
Expand Down Expand Up @@ -6607,6 +6604,10 @@
}

if (!requestMoneyInformation.isRetry) {
if (isFromGlobalCreate && !isReportTopmostSplitNavigator() && transaction.transactionID) {
Comment thread
TaduJR marked this conversation as resolved.
Outdated
mergeTransactionIdsHighlightOnSearchRoute(CONST.SEARCH.DATA_TYPES.EXPENSE, {[transaction.transactionID]: true});
}

handleNavigateAfterExpenseCreate({
activeReportID: backToReport ?? activeReportID,
transactionID: transaction.transactionID,
Expand Down Expand Up @@ -6991,6 +6992,10 @@
}

if (!params.isRetry) {
if (isFromGlobalCreate && !isReportTopmostSplitNavigator() && transaction?.transactionID) {
mergeTransactionIdsHighlightOnSearchRoute(CONST.SEARCH.DATA_TYPES.EXPENSE, {[transaction.transactionID]: true});
}

handleNavigateAfterExpenseCreate({
activeReportID,
transactionID: transaction?.transactionID,
Expand Down Expand Up @@ -7850,6 +7855,10 @@
InteractionManager.runAfterInteractions(() => removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));
const activeReportID = isMoneyRequestReport && report?.reportID ? report.reportID : parameters.chatReportID;

if (isFromGlobalCreate && !isReportTopmostSplitNavigator() && parameters.transactionID) {
mergeTransactionIdsHighlightOnSearchRoute(CONST.SEARCH.DATA_TYPES.EXPENSE, {[parameters.transactionID]: true});
}

if (shouldHandleNavigation) {
handleNavigateAfterExpenseCreate({activeReportID: backToReport ?? activeReportID, isFromGlobalCreate, transactionID: parameters.transactionID});
}
Expand Down
20 changes: 3 additions & 17 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14982,40 +14982,26 @@ describe('actions/IOU', () => {
});
});

it('handleNavigateAfterExpenseCreate', async () => {
it('handleNavigateAfterExpenseCreate does not call mergeTransactionIdsHighlightOnSearchRoute (highlight is now inlined in action functions)', async () => {
Comment thread
TaduJR marked this conversation as resolved.
Outdated
const mockedIsReportTopmostSplitNavigator = isReportTopmostSplitNavigator as jest.MockedFunction<typeof isReportTopmostSplitNavigator>;
const spyOnMergeTransactionIdsHighlightOnSearchRoute = jest.spyOn(require('@libs/actions/Transaction'), 'mergeTransactionIdsHighlightOnSearchRoute');
const activeReportID = '1';
const transactionID = '1';
mockedIsReportTopmostSplitNavigator.mockReturnValue(false);

// When on the Inbox tab, or NOT from the "global create" button, or without a transactionID,
// the function dismissModalAndOpenReportInInboxTab will always be called to handle it,
// so mergeTransactionIdsHighlightOnSearchRoute will never be invoked.
// Highlight side-effect is now inlined in each action function, not in this helper.
Comment thread
TaduJR marked this conversation as resolved.
Outdated
handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: false});
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(0);

handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: true});
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(0);

mockedIsReportTopmostSplitNavigator.mockReturnValue(true);
handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: true, transactionID});
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(0);

// When NOT on the Inbox tab
mockedIsReportTopmostSplitNavigator.mockReturnValue(false);
handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: true, transactionID});

// then mergeTransactionIdsHighlightOnSearchRoute will be called
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(1);
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledWith(CONST.SEARCH.DATA_TYPES.EXPENSE, {[transactionID]: true});
spyOnMergeTransactionIdsHighlightOnSearchRoute.mockClear();

// If expense is an invoice
handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: true, transactionID, isInvoice: true});
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(0);

expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(1);
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledWith(CONST.SEARCH.DATA_TYPES.INVOICE, {[transactionID]: true});
spyOnMergeTransactionIdsHighlightOnSearchRoute.mockReset();
});

Expand Down
Loading