Repository navigation
Decompose ReportActionsList: 6 #93694
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
2750b50
950d4ce
73e8c3a
9b61f3c
4075453
0929b0a
09a9340
faa7faa
5ec39cb
abbe2fc
33f4970
0c8a4c1
db5f1e6
73582a3
3ab6856
5f2f310
79acea1
f3ed365
1b2af34
c95f999
2c4a6ea
ce3e927
f97d91f
36f14bf
9eebbb1
c2e877a
4e9467f
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import {useEffect} from 'react'; | ||
| import {updateLoadingInitialReportAction} from '@libs/actions/Report'; | ||
| import useNetwork from './useNetwork'; | ||
|
|
||
| type UseLinkedMessageOfflineLoadingParams = { | ||
| /** The ID of the report whose initial-actions loading flag should be cleared */ | ||
| reportID: string; | ||
|
|
||
| /** The report action ID linked from the route, if any */ | ||
| reportActionIDFromRoute: string | undefined; | ||
| }; | ||
|
|
||
| /** | ||
| * When deep-linking to a message while offline, the linked actions are already cached, so clear the | ||
| * initial-actions loading flag instead of waiting for OpenReport. In the content, not the guard, because it | ||
| * only runs offline, where no skeleton shows. | ||
| */ | ||
| function useLinkedMessageOfflineLoading({reportID, reportActionIDFromRoute}: UseLinkedMessageOfflineLoadingParams) { | ||
| const {isOffline} = useNetwork(); | ||
|
|
||
| useEffect(() => { | ||
| // When we linked to message - we do not need to wait for initial actions - they already exists | ||
| if (!reportActionIDFromRoute || !isOffline) { | ||
| return; | ||
| } | ||
| updateLoadingInitialReportAction(reportID); | ||
| }, [isOffline, reportID, reportActionIDFromRoute]); | ||
| } | ||
|
|
||
| export default useLinkedMessageOfflineLoading; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import {useEffect} from 'react'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import markOpenReportEnd from '@libs/telemetry/markOpenReportEnd'; | ||
| import type * as OnyxTypes from '@src/types/onyx'; | ||
|
|
||
| /** | ||
| * Closes the open-report performance span as a cold open (`warm: false`) the moment a cold-load skeleton | ||
| * appears. Shared by every report surface that gates its own skeleton (the chat-list guard, the route | ||
| * orchestrator, and the money-request views): the open-report span must still close even though the list | ||
| * body — which would otherwise own this mark once mounted — isn't mounted while the skeleton shows. | ||
| */ | ||
| function useMarkOpenReportEndOnSkeleton(report: OnyxEntry<OnyxTypes.Report>, isSkeletonVisible: boolean) { | ||
| useEffect(() => { | ||
| if (!isSkeletonVisible || !report) { | ||
| return; | ||
| } | ||
| markOpenReportEnd(report, {warm: false}); | ||
| }, [report, isSkeletonVisible]); | ||
| } | ||
|
|
||
| export default useMarkOpenReportEndOnSkeleton; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| import {useRoute} from '@react-navigation/native'; | ||
| import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; | ||
| import {canUserPerformWriteAction, isReportTransactionThread as isReportTransactionThreadUtil} from '@libs/ReportUtils'; | ||
| import type {ReportsSplitNavigatorParamList} from '@navigation/types'; | ||
| import {useConciergeSessionActions, useConciergeSessionState} from '@pages/inbox/ConciergeSessionContext'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type SCREENS from '@src/SCREENS'; | ||
| import useLoadReportActions from './useLoadReportActions'; | ||
| import useNetworkWithOfflineStatus from './useNetworkWithOfflineStatus'; | ||
| import useOnyx from './useOnyx'; | ||
| import useParentReportAction from './useParentReportAction'; | ||
| import useReportActionsPagination from './useReportActionsPagination'; | ||
| import useReportActionsVisibility from './useReportActionsVisibility'; | ||
| import useReportIsArchived from './useReportIsArchived'; | ||
|
|
||
| /** | ||
| * Single read/derive pipeline for the report-actions list: the subscriptions and derivations the skeleton | ||
| * decision and the list render both need, computed once. Side-effect-free (no writes/navigation/telemetry/ | ||
| * session-start). The guard calls it once and passes `state`/`actions` via `ReportActionsListStateContext` | ||
| * and `ReportActionsListActionsContext` so the content doesn't re-subscribe. | ||
| */ | ||
| function useReportActionsListModel(reportID: string) { | ||
| const {isOffline} = useNetworkWithOfflineStatus(); | ||
| const route = useRoute<PlatformStackRouteProp<ReportsSplitNavigatorParamList, typeof SCREENS.REPORT>>(); | ||
| const reportActionIDFromRoute = route?.params?.reportActionID; | ||
|
|
||
| const [report, reportResult] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); | ||
|
|
||
| const { | ||
| reportActions, | ||
| allReportActions, | ||
| allReportActionIDs, | ||
| hasOlderActions, | ||
| hasNewerActions, | ||
| sortedAllReportActions, | ||
| oldestUnreadReportAction, | ||
| transactionThreadReportID, | ||
| transactionThreadReport, | ||
| parentReportActionForTransactionThread, | ||
| treatAsNoPaginationAnchor, | ||
| setTreatAsNoPaginationAnchor, | ||
| reportPreviewAction, | ||
| } = useReportActionsPagination(reportID, reportActionIDFromRoute); | ||
|
|
||
| const parentReportAction = useParentReportAction(report); | ||
|
|
||
| const [reportLoadingState] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${reportID}`); | ||
| const isLoadingInitialReportActions = reportLoadingState?.isLoadingInitialReportActions; | ||
| const hasOnceLoadedReportActions = reportLoadingState?.hasOnceLoadedReportActions; | ||
|
|
||
| const {sessionStartTime, showFullHistory: conciergeShowFullHistory, hadMessagesAtSessionStart: conciergeHadMessagesAtSessionStart} = useConciergeSessionState(); | ||
| const {setShowFullHistory: setConciergeShowFullHistory, setHadMessagesAtSessionStart: setConciergeHadMessagesAtSessionStart} = useConciergeSessionActions(); | ||
| const isReportTransactionThread = isReportTransactionThreadUtil(report); | ||
|
|
||
| const isReportArchived = useReportIsArchived(reportID); | ||
| const canPerformWriteAction = !!canUserPerformWriteAction(report, isReportArchived); | ||
|
|
||
| const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP); | ||
|
|
||
| const [reportPaginationState] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_PAGINATION_STATE}${reportID}`); | ||
|
|
||
| const {loadOlderChats, loadNewerChats} = useLoadReportActions({ | ||
| reportID, | ||
| reportActions, | ||
| allReportActionIDs, | ||
| transactionThreadReportID, | ||
| hasOlderActions, | ||
| hasNewerActions, | ||
| newestFetchedReportActionID: reportPaginationState?.newestFetchedReportActionID, | ||
| }); | ||
|
|
||
| const { | ||
| sortedReportActions, | ||
| sortedVisibleReportActions, | ||
| isConciergeMainDM, | ||
| isConciergeHiddenHistory, | ||
| showConciergeSidePanelWelcome, | ||
| showFullHistory, | ||
| hasPreviousMessages, | ||
| handleShowPreviousMessages, | ||
| } = useReportActionsVisibility({ | ||
| reportID, | ||
| reportActions, | ||
| allReportActions, | ||
| canPerformWriteAction, | ||
| hasOlderActions, | ||
| loadOlderChats, | ||
| mainDMSessionStartTime: sessionStartTime, | ||
| conciergeShowFullHistory: conciergeShowFullHistory || !!reportActionIDFromRoute || !!report?.hasOutstandingChildTask, | ||
| setConciergeShowFullHistory, | ||
| conciergeHadMessagesAtSessionStart, | ||
| setConciergeHadMessagesAtSessionStart, | ||
| }); | ||
|
|
||
| const isMissingReportActions = sortedVisibleReportActions.length === 0; | ||
| const isSingleExpenseReport = reportPreviewAction?.childMoneyRequestCount === 1; | ||
| // allReportActions excludes the synthetic CREATED action always injected for Concierge, so this is | ||
| // false only on a genuinely cold load with no cached history. | ||
| const hasCachedReportActions = allReportActions.length > 0; | ||
|
|
||
| // Readiness signals for the skeleton decision (some also read by the guard's effect hooks). Off the | ||
| // context so their churn (loading, app-load, concierge-session, navigation) never re-renders the list. | ||
| const readinessSignals = { | ||
| report, | ||
| reportResult, | ||
| isOffline, | ||
| reportActionIDFromRoute, | ||
| transactionThreadReport, | ||
| isReportArchived, | ||
| isReportTransactionThread, | ||
| isLoadingInitialReportActions, | ||
| hasOnceLoadedReportActions, | ||
| isLoadingApp, | ||
| reportActionsLength: reportActions.length, | ||
| oldestUnreadReportAction, | ||
| isSingleExpenseReport, | ||
| isMissingReportActions, | ||
| isConciergeHiddenHistory, | ||
| isConciergeMainDM, | ||
| hasCachedReportActions, | ||
| showConciergeSidePanelWelcome, | ||
| }; | ||
|
|
||
| // The render state slice on `ReportActionsListStateContext`; this is what drives list re-renders. | ||
| // Ambient state (network, route, archived, concierge session) is read locally in the content instead | ||
| // of carried here. | ||
| const state = { | ||
| report, | ||
| hasOnceLoadedReportActions, | ||
| hasNewerActions, | ||
| sortedAllReportActions, | ||
| oldestUnreadReportAction, | ||
| transactionThreadReport, | ||
| parentReportActionForTransactionThread, | ||
| treatAsNoPaginationAnchor, | ||
| parentReportAction, | ||
| sortedReportActions, | ||
| sortedVisibleReportActions, | ||
| isConciergeHiddenHistory, | ||
| showFullHistory, | ||
| hasPreviousMessages, | ||
| }; | ||
|
|
||
| // The command handles on `ReportActionsListActionsContext`. Referentially stable, so actions-only | ||
| // consumers don't re-render when the state slice churns. | ||
| const actions = { | ||
| setTreatAsNoPaginationAnchor, | ||
| handleShowPreviousMessages, | ||
| loadOlderChats, | ||
| loadNewerChats, | ||
| }; | ||
|
|
||
| return {readinessSignals, state, actions}; | ||
| } | ||
|
|
||
| type ReportActionsListModel = ReturnType<typeof useReportActionsListModel>; | ||
| type ReportActionsReadinessSignals = ReportActionsListModel['readinessSignals']; | ||
| type ReportActionsListState = ReportActionsListModel['state']; | ||
| type ReportActionsListActions = ReportActionsListModel['actions']; | ||
|
|
||
| export default useReportActionsListModel; | ||
| export type {ReportActionsReadinessSignals, ReportActionsListState, ReportActionsListActions}; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,11 @@ import useReportScrollManager from './useReportScrollManager'; | |
| import useScrollToEndOnNewMessageReceived from './useScrollToEndOnNewMessageReceived'; | ||
|
|
||
| type UseReportActionsScrollParams = { | ||
| /** The ID of the report currently being looked at */ | ||
| reportID: string; | ||
|
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. Why do we need to update this hook? Why don't we use
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. Same reasoning as the useMarkAsRead thread: we keep
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. maybe this is worth a comment. |
||
|
|
||
| /** The report currently being looked at */ | ||
| report: OnyxTypes.Report; | ||
| report: OnyxEntry<OnyxTypes.Report>; | ||
|
|
||
| /** The transaction thread report associated with the current report, if any */ | ||
| transactionThreadReport: OnyxEntry<OnyxTypes.Report>; | ||
|
|
@@ -112,6 +115,7 @@ type UseReportActionsScrollResult = { | |
| }; | ||
|
|
||
| function useReportActionsScroll({ | ||
| reportID, | ||
| report, | ||
| transactionThreadReport, | ||
| parentReportAction, | ||
|
|
@@ -127,7 +131,6 @@ function useReportActionsScroll({ | |
| treatAsNoPaginationAnchor, | ||
| setTreatAsNoPaginationAnchor, | ||
| }: UseReportActionsScrollParams): UseReportActionsScrollResult { | ||
| const reportID = report.reportID; | ||
| const reportScrollManager = useReportScrollManager(); | ||
| const {scrollOffsetRef} = useContext(ActionListContext); | ||
| const route = useRoute<PlatformStackRouteProp<ReportsSplitNavigatorParamList, typeof SCREENS.REPORT>>(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.