-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix Audit Reports navigation and prioritize report routes #87778
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
Closed
marufsharifi
wants to merge
31
commits into
Expensify:main
from
marufsharifi:fix/audit-reports-navigation-prioritize-report-routes
Closed
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
ce0b326
fix: correct Audit Reports navigation and prioritize report routes
marufsharifi 14bac24
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 28cc656
Refactor task modal dismiss logic into shared helper
marufsharifi 225c9c2
Guard leave flow backTo against current report
marufsharifi 1387baa
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 315fd72
Return to task after edits
marufsharifi a8b07e2
Unwrap search backTo on leave
marufsharifi 603c727
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi b80540b
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 5ff28e6
Preserve backTo when deleting tasks
marufsharifi 4408c14
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 5ad1115
fix task delete navigation from search
marufsharifi e05683a
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi ab00393
fix lint
marufsharifi fbd2f2c
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 76de249
Fix task delete navigation when task has messages
marufsharifi dd5cb71
Update task delete tests
marufsharifi 3fcfba9
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 54ae055
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi d04c744
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 872c413
fix lint
marufsharifi 274701e
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 5f7850d
fix back navigation after deleting task details
marufsharifi 308ef5d
fix nested backTo handling when leaving thread
marufsharifi 2b1820c
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 270d54b
fix task delete redirect after leaving details
marufsharifi 92e7825
fix task delete navigation when task has messages
marufsharifi 1419009
Merge branch 'main' into fix/audit-reports-navigation-prioritize-repo…
marufsharifi 703284c
guard search route helper before navigation is ready
marufsharifi a79ba6d
fix chat expense preview navigation context
marufsharifi 437f624
fix navigationRef guard in search route helper
marufsharifi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/libs/Navigation/helpers/dismissModalForCurrentContext.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute'; | ||
|
|
||
| function dismissModalForCurrentContext(reportID?: string) { | ||
| if (isSearchTopmostFullScreenRoute()) { | ||
| Navigation.dismissModal(); | ||
| return; | ||
| } | ||
|
|
||
| if (!reportID) { | ||
| Navigation.dismissModal(); | ||
| return; | ||
| } | ||
|
|
||
| Navigation.dismissModalWithReport({reportID}); | ||
| } | ||
|
|
||
| export default dismissModalForCurrentContext; |
22 changes: 22 additions & 0 deletions
22
src/libs/Navigation/helpers/getReportRouteForCurrentContext.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type {Route} from '@src/ROUTES'; | ||
| import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute'; | ||
|
|
||
| type GetReportRouteForCurrentContextParams = { | ||
| reportID: string | undefined; | ||
| reportActionID?: string; | ||
| backTo?: Route; | ||
| }; | ||
|
|
||
| function getReportRouteForCurrentContext({reportID, reportActionID, backTo}: GetReportRouteForCurrentContextParams): Route { | ||
| const currentRoute = backTo ?? (Navigation.getActiveRoute() as Route); | ||
|
|
||
| if (isSearchTopmostFullScreenRoute()) { | ||
| return ROUTES.SEARCH_REPORT.getRoute({reportID, reportActionID, backTo: currentRoute}); | ||
| } | ||
|
|
||
| return ROUTES.REPORT_WITH_ID.getRoute(reportID, reportActionID, undefined, currentRoute); | ||
| } | ||
|
|
||
| export default getReportRouteForCurrentContext; |
8 changes: 6 additions & 2 deletions
8
src/libs/Navigation/helpers/isSearchTopmostFullScreenRoute.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/libs/Navigation/helpers/shouldUseBackToOnLeaveReport.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type {Route} from '@src/ROUTES'; | ||
|
|
||
| function normalizeRoute(route: string): string { | ||
| return route | ||
| .replaceAll(/\?.*/g, '') | ||
| .replaceAll(/^\/+|\/+$/g, '') | ||
| .replaceAll(/\/+/g, '/'); | ||
| } | ||
|
|
||
| function getNestedBackToRoute(route: string): Route | undefined { | ||
| const [, queryString = ''] = route.split('?'); | ||
|
|
||
| if (!queryString) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const params = new URLSearchParams(queryString); | ||
| const encodedBackTo = params.get('backTo'); | ||
|
|
||
| if (!encodedBackTo) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return encodedBackTo as Route; | ||
| } | ||
|
|
||
| function doesRouteTargetCurrentReport(route: string, reportID: string): boolean { | ||
| const normalizedRoute = normalizeRoute(route); | ||
| const currentReportRoutes = [ | ||
| ROUTES.REPORT_WITH_ID.getRoute(reportID), | ||
| ROUTES.SEARCH_REPORT.getRoute({reportID}), | ||
| ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID}), | ||
| ROUTES.EXPENSE_REPORT_RHP.getRoute({reportID}), | ||
| ].map(normalizeRoute); | ||
|
|
||
| return currentReportRoutes.some((currentReportRoute) => normalizedRoute === currentReportRoute || normalizedRoute.startsWith(`${currentReportRoute}/`)); | ||
| } | ||
|
|
||
| function getBackToOnLeaveReport(reportID: string | undefined, backTo?: Route): Route | undefined { | ||
| if (!backTo) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const normalizedBackTo = normalizeRoute(backTo); | ||
| const isSearchRoute = normalizedBackTo.startsWith(ROUTES.SEARCH_ROOT.route); | ||
|
|
||
| if (isSearchRoute) { | ||
| if (!reportID || !doesRouteTargetCurrentReport(backTo, reportID)) { | ||
| return backTo; | ||
| } | ||
|
|
||
| return getNestedBackToRoute(backTo) ?? backTo; | ||
| } | ||
|
|
||
| if (!reportID) { | ||
| return backTo; | ||
| } | ||
|
|
||
| if (doesRouteTargetCurrentReport(backTo, reportID)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return backTo; | ||
| } | ||
|
|
||
| function shouldUseBackToOnLeaveReport(reportID: string | undefined, backTo?: Route): boolean { | ||
| return !!getBackToOnLeaveReport(reportID, backTo); | ||
| } | ||
|
|
||
| export {getBackToOnLeaveReport}; | ||
| export default shouldUseBackToOnLeaveReport; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have discussed this before. Could you please help me understand why we need this change and what we are trying to achieve with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper is needed because
backTois not always safe to use directly in the leave flow. In some cases it points back to the current report, while in Search flows it represents the user’s original Search context. The helper makes that distinction so we preserve the Search return path when appropriate without changing the existing non-Search behavior