-
Notifications
You must be signed in to change notification settings - Fork 4k
[CP Staging] fix: refresh Search after an expense moves report or a report changes workspace #98752
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
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import ActivityIndicator from '@components/ActivityIndicator'; | |
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import {useSession} from '@components/OnyxListItemProvider'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import {useSearchQueryContext, useSearchResultsContext} from '@components/Search/SearchContext'; | ||
| import SelectionList from '@components/SelectionList'; | ||
| import type {WorkspaceListItemType} from '@components/SelectionList/ListItem/types'; | ||
| import UserListItem from '@components/SelectionList/ListItem/UserListItem'; | ||
|
|
@@ -19,6 +20,7 @@ import useParentReportAction from '@hooks/useParentReportAction'; | |
| import usePermissions from '@hooks/usePermissions'; | ||
| import useReportIsArchived from '@hooks/useReportIsArchived'; | ||
| import useReportTransactions from '@hooks/useReportTransactions'; | ||
| import useSearchShouldCalculateTotals from '@hooks/useSearchShouldCalculateTotals'; | ||
| import useShouldSuppressPromotionalUI from '@hooks/useShouldSuppressPromotionalUI'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import useWorkspaceList from '@hooks/useWorkspaceList'; | ||
|
|
@@ -38,6 +40,7 @@ import { | |
| isSettled, | ||
| isWorkspaceEligibleForReportChange, | ||
| } from '@libs/ReportUtils'; | ||
| import refreshSearchAfterReportAction from '@libs/SearchRefreshUtils'; | ||
| import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; | ||
| import {hasAppliedCommuterExclusion, isManualDistanceRequest, isOdometerDistanceRequest} from '@libs/TransactionUtils'; | ||
|
|
||
|
|
@@ -110,6 +113,20 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace | |
| isOdometerDistanceRequest: hasOdometerDistanceRequest, | ||
| }); | ||
| const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector}); | ||
| const {currentSearchQueryJSON, currentSearchKey} = useSearchQueryContext(); | ||
| const {currentSearchResults} = useSearchResultsContext(); | ||
| const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, currentSearchQueryJSON?.hash, true); | ||
|
|
||
| // The snapshot keeps the report row after a workspace change, and only the server can tell whether it still matches the query. | ||
| const refreshSearch = () => { | ||
| refreshSearchAfterReportAction({ | ||
| currentSearchQueryJSON, | ||
| currentSearchKey, | ||
| shouldCalculateTotals, | ||
| isOffline, | ||
| isLoading: !!currentSearchResults?.search?.isLoading, | ||
| }); | ||
|
Comment on lines
+116
to
+128
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. Is this not going to lead to many extra Search calls?
Contributor
Author
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. nope, it's one call per workspace pick. It only runs when you tap a row in that list, and if a search for the same hash and offset is already in flight, search method throws it away anyway |
||
| }; | ||
|
|
||
| const selectPolicy = (policyID?: string) => { | ||
| const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; | ||
|
|
@@ -140,6 +157,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace | |
| if (!invite?.policyExpenseChatReportID) { | ||
| moveIOUReportToPolicy(report, policy, reportPreviewAction, getCurrencyDecimals, false, reportTransactions); | ||
| } | ||
| refreshSearch(); | ||
| return; | ||
| // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 | ||
| } | ||
|
|
@@ -169,6 +187,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace | |
| isTrackIntentUser, | ||
| reportTransactions, | ||
| }); | ||
| refreshSearch(); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -189,6 +208,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace | |
| isTrackIntentUser, | ||
| reportTransactions, | ||
| }); | ||
| refreshSearch(); | ||
| }; | ||
|
|
||
| const {data, shouldShowNoResultsFoundMessage, shouldShowSearchInput} = useWorkspaceList({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.