-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix bulk merge post-merge navigation to open target thread report #88634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b341560
b9359c4
9a22f68
f03bf99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,11 @@ import {useSearchActionsContext, useSearchStateContext} from '@components/Search | |
| import {initBulkEditDraftTransaction} from '@libs/actions/IOU/BulkEdit'; | ||
| import {unholdRequest} from '@libs/actions/IOU/Hold'; | ||
| import {setupMergeTransactionDataAndNavigate} from '@libs/actions/MergeTransaction'; | ||
| import {exportReportToCSV} from '@libs/actions/Report'; | ||
| import type {TargetTransactionThreadReportCandidate} from '@libs/actions/MergeTransaction'; | ||
| import {createTransactionThreadReport, exportReportToCSV} from '@libs/actions/Report'; | ||
| import {getExportTemplates, handlePreventSearchAPI} from '@libs/actions/Search'; | ||
| import initSplitExpense from '@libs/actions/SplitExpenses'; | ||
| import {getTargetTransactionThreadReportIDForSelection} from '@libs/MergeTransactionUtils'; | ||
| import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; | ||
| import {getIOUActionForTransactionID, getReportAction, isDeletedAction} from '@libs/ReportActionsUtils'; | ||
| import {isMergeActionForSelectedTransactions, isSplitAction} from '@libs/ReportSecondaryActionUtils'; | ||
|
|
@@ -89,6 +91,8 @@ function useSelectedTransactionsActions({ | |
| const [integrationsExportTemplates] = useOnyx(ONYXKEYS.NVP_INTEGRATION_SERVER_EXPORT_TEMPLATES); | ||
| const [csvExportLayouts] = useOnyx(ONYXKEYS.NVP_CSV_EXPORT_LAYOUTS); | ||
| const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); | ||
| const [betas] = useOnyx(ONYXKEYS.BETAS); | ||
|
marufsharifi marked this conversation as resolved.
|
||
| const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); | ||
| const [allReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS); | ||
| const {getCurrencyDecimals} = useCurrencyListActions(); | ||
|
|
||
|
|
@@ -419,13 +423,45 @@ function useSelectedTransactionsActions({ | |
|
|
||
| const canMergeTransaction = selectedTransactionsList.length < 3 && report && policy && isMergeActionForSelectedTransactions(selectedTransactionsList, [report], [policy]); | ||
| if (canMergeTransaction) { | ||
| const transactionID = selectedTransactionsList.at(0)?.transactionID; | ||
| if (transactionID) { | ||
| const selectedTransaction = selectedTransactionsList.at(0); | ||
| const transactionID = selectedTransaction?.transactionID; | ||
| if (transactionID && selectedTransaction) { | ||
| options.push({ | ||
| text: translate('common.merge'), | ||
| icon: expensifyIcons.ArrowCollapse, | ||
| value: MERGE, | ||
| onSelected: () => | ||
| onSelected: () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-3 (docs)The fallback chain for resolving Consider extracting the common resolution logic into a single shared utility (e.g., extending Reviewed at: b341560 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency. |
||
| const isSingleSelection = selectedTransactionsList.length === 1; | ||
| let targetTransactionThreadReportIDOverride: string | undefined; | ||
| const iouReportAction = isSingleSelection ? getIOUActionForTransactionID(reportActions, transactionID) : undefined; | ||
|
|
||
| if (isSingleSelection) { | ||
| const selectedTransactionMeta = selectedTransactionsMeta?.[transactionID]; | ||
| targetTransactionThreadReportIDOverride = getTargetTransactionThreadReportIDForSelection(selectedTransaction, selectedTransactionMeta, iouReportAction); | ||
|
|
||
| if (!targetTransactionThreadReportIDOverride) { | ||
| const transactionViolations = allTransactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; | ||
| const createdThreadReport = createTransactionThreadReport( | ||
| introSelected, | ||
| login ?? '', | ||
| currentUserAccountID, | ||
| betas, | ||
| report, | ||
| iouReportAction, | ||
| selectedTransaction, | ||
| transactionViolations, | ||
| ); | ||
| targetTransactionThreadReportIDOverride = createdThreadReport?.reportID; | ||
| } | ||
| } | ||
|
|
||
| const targetTransactionThreadReportCandidate: TargetTransactionThreadReportCandidate | undefined = targetTransactionThreadReportIDOverride | ||
| ? { | ||
| transactionID, | ||
| threadReportID: targetTransactionThreadReportIDOverride, | ||
| } | ||
| : undefined; | ||
|
|
||
| setupMergeTransactionDataAndNavigate( | ||
| transactionID, | ||
| selectedTransactionsList, | ||
|
|
@@ -435,7 +471,9 @@ function useSelectedTransactionsActions({ | |
| false, | ||
| isOnSearch, | ||
| selectedTransactionsList.length > 1 ? [policy, policy] : undefined, | ||
| ), | ||
| targetTransactionThreadReportCandidate, | ||
| ); | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import ROUTES from '@src/ROUTES'; | ||
| import SCREENS from '@src/SCREENS'; | ||
| import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute'; | ||
|
|
||
| function normalizeRoute(route?: string): string | undefined { | ||
| if (!route) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const decodedRoute = (() => { | ||
| try { | ||
| return decodeURIComponent(route); | ||
| } catch { | ||
| return route; | ||
| } | ||
| })(); | ||
|
|
||
| return decodedRoute.startsWith('/') ? decodedRoute.substring(1) : decodedRoute; | ||
| } | ||
|
|
||
| function isSearchOriginForMerge(routeName: string, backTo?: string): boolean { | ||
| if (routeName !== SCREENS.RIGHT_MODAL.SEARCH_REPORT) { | ||
| return false; | ||
|
marufsharifi marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const normalizedBackTo = normalizeRoute(backTo); | ||
| if (normalizedBackTo) { | ||
| return normalizedBackTo.startsWith(ROUTES.SEARCH_ROOT.route); | ||
| } | ||
|
|
||
| return isSearchTopmostFullScreenRoute(); | ||
| } | ||
|
|
||
| export default isSearchOriginForMerge; | ||
Uh oh!
There was an error while loading. Please reload this page.