Skip to content

Refactor table view report loading state #62363

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

Merged
5 changes: 3 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import type {PaymentMethod} from './KYCWall/types';
import LoadingBar from './LoadingBar';
import Modal from './Modal';
import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar';
import MoneyReportHeaderStatusBarSkeleton from './MoneyReportHeaderStatusBarSkeleton';
import type {MoneyRequestHeaderStatusBarProps} from './MoneyRequestHeaderStatusBar';
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
import {useMoneyRequestReportContext} from './MoneyRequestReportView/MoneyRequestReportContext';
Expand Down Expand Up @@ -280,7 +281,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const isSubmitterSameAsNextApprover = isReportOwner(moneyRequestReport) && nextApproverAccountID === moneyRequestReport?.ownerAccountID;
const optimisticNextStep = isSubmitterSameAsNextApprover && policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep;

const shouldShowNextStep = isFromPaidPolicy && !!optimisticNextStep?.message?.length && !shouldShowStatusBar;
const shouldShowNextStep = isFromPaidPolicy && !shouldShowStatusBar;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SzymczakJ shouldShowNextStep is also used for isMoreContentShown and shouldAddGapToContents. Does this change impact on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, from what I know(this knowledge comes from @trjExpensify) we are always showing the next steps in expense Reports(this kind of reports always has MoneyReportHeader) and never(at least for now) for the invoice reports(this is the only other report type that uses MoneyReportHeader).
I've added !isInvoiceReport check to reflect it.
So when the shouldShowNextStep is true, the isMoreContentShown is also true, and "more content" is either skeleton or real next steps and we don't need to worry about optimisticNextStep?.message?.length.

const bankAccountRoute = getBankAccountRoute(chatReport);
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton);
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID);
Expand Down Expand Up @@ -883,7 +884,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
/>
</View>
)}
{shouldShowNextStep && <MoneyReportHeaderStatusBar nextStep={optimisticNextStep} />}
{shouldShowNextStep && (optimisticNextStep?.message?.length ? <MoneyReportHeaderStatusBar nextStep={optimisticNextStep} /> : <MoneyReportHeaderStatusBarSkeleton />)}
{!!statusBarProps && (
<MoneyRequestHeaderStatusBar
icon={statusBarProps.icon}
Expand Down
36 changes: 36 additions & 0 deletions src/components/MoneyReportHeaderStatusBarSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import {View} from 'react-native';
import {Rect} from 'react-native-svg';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import SkeletonViewContentLoader from './SkeletonViewContentLoader';

function MoneyReportHeaderStatusBarSkeleton() {
const styles = useThemeStyles();
const theme = useTheme();

return (
<View style={[styles.dFlex, styles.flexRow, styles.overflowHidden, styles.w100, {height: 28}]}>
<SkeletonViewContentLoader
height={28}
backgroundColor={theme.skeletonLHNIn}
foregroundColor={theme.skeletonLHNOut}
>
<Rect
x={0}
y={12}
width={16}
height={8}
/>
<Rect
x={24}
y={12}
width={120}
height={8}
/>
</SkeletonViewContentLoader>
</View>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

displayName


export default MoneyReportHeaderStatusBarSkeleton;
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import type * as OnyxTypes from '@src/types/onyx';
import {useMoneyRequestReportContext} from './MoneyRequestReportContext';
import MoneyRequestReportTransactionList from './MoneyRequestReportTransactionList';
import MoneyRequestViewReportFields from './MoneyRequestViewReportFields';
import ReportActionsListLoadingSkeleton from './ReportActionsListLoadingSkeleton';
import SearchMoneyRequestReportEmptyState from './SearchMoneyRequestReportEmptyState';

/**
Expand Down Expand Up @@ -82,6 +83,9 @@ type MoneyRequestReportListProps = {

/** If the report has older actions to load */
hasOlderActions: boolean;

/** If the report has older actions to load */
isLoadingReportActions?: boolean;
};

function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportActions>, parentReportActionID: string | undefined): OnyxEntry<OnyxTypes.ReportAction> {
Expand All @@ -91,7 +95,7 @@ function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportAc
return parentReportActions[parentReportActionID];
}

function MoneyRequestReportActionsList({report, policy, reportActions = [], transactions = [], hasNewerActions, hasOlderActions}: MoneyRequestReportListProps) {
function MoneyRequestReportActionsList({report, policy, reportActions = [], transactions = [], hasNewerActions, hasOlderActions, isLoadingReportActions}: MoneyRequestReportListProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {preferredLocale} = useLocalize();
Expand Down Expand Up @@ -516,12 +520,14 @@ function MoneyRequestReportActionsList({report, policy, reportActions = [], tran
transactions={transactions}
reportActions={reportActions}
hasComments={reportHasComments}
isLoadingReportActions={isLoadingReportActions && !reportHasComments}
/>
</>
}
keyboardShouldPersistTaps="handled"
onScroll={trackVerticalScrolling}
ref={reportScrollManager.ref}
ListEmptyComponent={isLoadingReportActions ? <ReportActionsListLoadingSkeleton /> : undefined} // this empty component is only used for loading state, real empty state is handled by SearchMoneyRequestReportEmptyState
/>
)}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useFocusEffect} from '@react-navigation/native';
import isEmpty from 'lodash/isEmpty';
import React, {memo, useCallback, useMemo, useState} from 'react';
import {View} from 'react-native';
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated';
import type {TupleToUnion} from 'type-fest';
import {getButtonRole} from '@components/Button/utils';
import Checkbox from '@components/Checkbox';
Expand Down Expand Up @@ -52,6 +53,9 @@ type MoneyRequestReportTransactionListProps = {

/** Whether the report that these transactions belong to has any chat comments */
hasComments: boolean;

/** Whether the report actions are being loaded, used to show 'Comments' during loading state */
isLoadingReportActions?: boolean;
};

type TransactionWithOptionalHighlight = OnyxTypes.Transaction & {
Expand Down Expand Up @@ -81,7 +85,7 @@ const getTransactionKey = (transaction: OnyxTypes.Transaction, key: SortableColu
return key === CONST.SEARCH.TABLE_COLUMNS.DATE ? dateKey : key;
};

function MoneyRequestReportTransactionList({report, transactions, reportActions, hasComments}: MoneyRequestReportTransactionListProps) {
function MoneyRequestReportTransactionList({report, transactions, reportActions, hasComments, isLoadingReportActions}: MoneyRequestReportTransactionListProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
Expand Down Expand Up @@ -289,7 +293,13 @@ function MoneyRequestReportTransactionList({report, transactions, reportActions,
</View>
)}
<View style={[styles.dFlex, styles.flexRow, listHorizontalPadding, styles.justifyContentBetween, styles.mb2]}>
<Text style={[styles.textLabelSupporting]}>{hasComments ? translate('common.comments') : ''}</Text>
<Animated.Text
style={[styles.textLabelSupporting]}
entering={FadeIn}
exiting={FadeOut}
>
{hasComments || isLoadingReportActions ? translate('common.comments') : ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to hasComments condition?

Copy link
Contributor Author

@SzymczakJ SzymczakJ May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, we didn't show the comments string when there were no comments, so this condition comes from the past.

</Animated.Text>
<View style={[styles.dFlex, styles.flexRow, styles.alignItemsCenter, styles.pr3]}>
<Text style={[styles.mr3, styles.textLabelSupporting]}>{translate('common.total')}</Text>
<Text style={[shouldUseNarrowLayout ? styles.mnw64p : styles.mnw100p, styles.textAlignRight, styles.textBold]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
reportActions={reportActions}
hasOlderActions={hasOlderActions}
hasNewerActions={hasNewerActions}
isLoadingReportActions={isLoadingInitialReportActions}
/>
) : (
<ReportActionsView
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated';
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView';

function ReportActionsListLoadingSkeleton() {
return (
<Animated.View
entering={FadeIn}
exiting={FadeOut}
>
<ReportActionsSkeletonView possibleVisibleContentItems={3} />
</Animated.View>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Display name


export default ReportActionsListLoadingSkeleton;
1 change: 1 addition & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
transactions={reportTransactions}
hasOlderActions={hasOlderActions}
hasNewerActions={hasNewerActions}
isLoadingReportActions={reportMetadata?.isLoadingInitialReportActions}
/>
) : null}
{isCurrentReportLoadedFromOnyx ? (
Expand Down
Loading