Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0a90b85
Improve MoneyRequestReportView
Kicu Mar 21, 2025
022d3a3
Make SearchTypeMenu look correct with undefined Search query
Kicu Mar 21, 2025
0512fc9
Improve SearchMoneyRequestReportPage loading and not found page
Kicu Mar 21, 2025
228e7ab
Add navigating to transaction reportID
Kicu Mar 24, 2025
1378cef
Add totals under table (#213)
jnowakow Mar 24, 2025
20e5c22
Add navigation when clicking on Transaction row
Kicu Mar 25, 2025
22606bc
Improve styling and types in MoneyRequestReportView
Kicu Mar 25, 2025
e2c3b27
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu Mar 25, 2025
52710c4
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu Mar 25, 2025
276b51c
Add styling tweaks
Kicu Mar 26, 2025
b2df980
Improve filtering out actions for MoneyRequestReportActionsList
Kicu Mar 27, 2025
53da96d
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu Mar 27, 2025
fb78db2
Update styling of table headers
Kicu Mar 27, 2025
7d01b19
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu Mar 27, 2025
7267ab2
Update styling and skeleton loader of MoneyRequestReportView
Kicu Mar 28, 2025
aa76192
Add fixes after PR review
Kicu Mar 28, 2025
fec3a79
Fix linting and TS for MoneyRequestReportPage
Kicu Mar 28, 2025
eaf9379
Fix undefined routes and openReport call
Kicu Mar 28, 2025
36290e1
Improve comments around openReport calling new flag
Kicu Mar 28, 2025
fca1657
Fix code style
Kicu Mar 31, 2025
659d7e1
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu Mar 31, 2025
91f6b5c
Handle EmptyState in MoneyRequestReportActionsList after merge conflicts
Kicu Mar 31, 2025
8d628fe
Add tests for MoneyRequestReportTransactionList
Kicu Mar 31, 2025
739e58d
Fix lint
Kicu Mar 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,9 @@ const CONST = {
},
},
THREAD_DISABLED: ['CREATED'],
// Used when displaying reportActions list to handle of unread messages icon/button
SCROLL_VERTICAL_OFFSET_THRESHOLD: 200,
ACTION_VISIBLE_THRESHOLD: 250,
},
TRANSACTION_LIST: {
COLUMNS: {
Expand Down Expand Up @@ -6434,6 +6437,10 @@ const CONST = {
GROUP_BY: {
REPORTS: 'reports',
},
TABLE_COLUMN_SIZES: {
NORMAL: 'normal',
WIDE: 'wide',
},
STATUS: {
EXPENSE: {
ALL: 'all',
Expand Down
3 changes: 3 additions & 0 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import * as Expensicons from './Icon/Expensicons';
import LoadingBar from './LoadingBar';
import type {MoneyRequestHeaderStatusBarProps} from './MoneyRequestHeaderStatusBar';
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
import MoneyRequestReportTransactionsNavigation from './MoneyRequestReportView/MoneyRequestReportTransactionsNavigation';

type MoneyRequestHeaderProps = {
/** The report currently being looked at */
Expand Down Expand Up @@ -79,6 +80,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre

const isReportInRHP = route.name === SCREENS.SEARCH.REPORT_RHP;
const shouldDisplaySearchRouter = !isReportInRHP || isSmallScreenWidth;
const shouldDisplayTransactionNavigation = !!(reportID && isReportInRHP);

const hasPendingRTERViolation = hasPendingRTERViolationTransactionUtils(transactionViolations);

Expand Down Expand Up @@ -184,6 +186,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
}}
/>
)}
{shouldDisplayTransactionNavigation && <MoneyRequestReportTransactionsNavigation currentReportID={reportID} />}
</HeaderWithBackButton>
{shouldShowMarkAsCashButton && shouldUseNarrowLayout && (
<View style={[styles.ph5, styles.pb3]}>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from 'react';
import {View} from 'react-native';
import type {SortOrder} from '@components/Search/types';
import type {SortOrder, TableColumnSize} from '@components/Search/types';
import SortableTableHeader from '@components/SelectionList/SortableTableHeader';
import type {SortableColumnName} from '@components/SelectionList/types';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';

Expand Down Expand Up @@ -57,22 +55,22 @@ type SearchTableHeaderProps = {
sortBy?: SortableColumnName;
sortOrder?: SortOrder;
onSortPress: (column: SortableColumnName, order: SortOrder) => void;
dateColumnSize: TableColumnSize;
shouldShowSorting: boolean;
};

// At this moment with new Report View we have no extra logic for displaying columns
const shouldShowColumn = () => true;

function MoneyRequestReportTableHeader({sortBy, sortOrder, onSortPress, shouldShowSorting}: SearchTableHeaderProps) {
function MoneyRequestReportTableHeader({sortBy, sortOrder, onSortPress, dateColumnSize, shouldShowSorting}: SearchTableHeaderProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

return (
<View style={[styles.pv3, StyleUtils.getPaddingLeft(variables.w28), StyleUtils.getPaddingRight(variables.w28)]}>
<View style={[styles.peopleRow, styles.listTableHeader, styles.pt4]}>
<SortableTableHeader
columns={columnConfig}
shouldShowColumn={shouldShowColumn}
dateColumnSize="normal"
dateColumnSize={dateColumnSize}
shouldShowSorting={shouldShowSorting}
sortBy={sortBy}
sortOrder={sortOrder}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
import isEmpty from 'lodash/isEmpty';
import React, {useEffect, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import type {TupleToUnion} from 'type-fest';
import {getButtonRole} from '@components/Button/utils';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import type {SortOrder} from '@components/Search/types';
import Text from '@components/Text';
import TransactionItemRow from '@components/TransactionItemRow';
import useHover from '@hooks/useHover';
import useLocalize from '@hooks/useLocalize';
import {useMouseContext} from '@hooks/useMouseContext';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import {getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils';
import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils';
import {getMoneyRequestSpendBreakdown} from '@libs/ReportUtils';
import {compareValues} from '@libs/SearchUIUtils';
import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear';
import Navigation from '@navigation/Navigation';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import MoneyRequestReportTableHeader from './MoneyRequestReportTableHeader';
import SearchMoneyRequestReportEmptyState from './SearchMoneyRequestReportEmptyState';
import {setActiveTransactionReportIDs} from './TransactionReportIDRepository';

type MoneyRequestReportTransactionListProps = {
report: OnyxTypes.Report;

/** List of transactions belonging to one report */
transactions: OnyxTypes.Transaction[];

/** Array of report actions for the report that these transactions belong to */
reportActions: OnyxTypes.ReportAction[];

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

const sortableColumnNames = [
Expand Down Expand Up @@ -50,15 +72,30 @@ const areTransactionValuesEqual = (transactions: OnyxTypes.Transaction[], key: S
return transactions.every((transaction) => transaction[getTransactionKey(transaction, key)] === firstValidTransaction[keyOfFirstValidTransaction]);
};

function MoneyRequestReportTransactionList({transactions}: MoneyRequestReportTransactionListProps) {
function MoneyRequestReportTransactionList({report, transactions, reportActions, hasComments}: MoneyRequestReportTransactionListProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {shouldUseNarrowLayout, isMediumScreenWidth} = useResponsiveLayout();
const displayNarrowVersion = isMediumScreenWidth || shouldUseNarrowLayout;

const {totalDisplaySpend, nonReimbursableSpend, reimbursableSpend} = getMoneyRequestSpendBreakdown(report);
const formattedOutOfPocketAmount = convertToDisplayString(reimbursableSpend, report?.currency);
const formattedCompanySpendAmount = convertToDisplayString(nonReimbursableSpend, report?.currency);
const shouldShowBreakdown = !!nonReimbursableSpend && !!reimbursableSpend;

const {bind} = useHover();
const {isMouseDownOnInput, setMouseUp} = useMouseContext();

const handleMouseLeave = (e: React.MouseEvent<Element, MouseEvent>) => {
bind.onMouseLeave();
e.stopPropagation();
setMouseUp();
};

const [sortedData, setSortedData] = useState<SortedTransactions>({
transactions,
sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
sortOrder: CONST.SEARCH.SORT_ORDER.DESC,
sortOrder: CONST.SEARCH.SORT_ORDER.ASC,
});

const {sortBy, sortOrder} = sortedData;
Expand All @@ -74,13 +111,43 @@ function MoneyRequestReportTransactionList({transactions}: MoneyRequestReportTra
}));
}, [sortBy, sortOrder, transactions]);

const navigateToTransaction = useCallback(
(activeTransaction: OnyxTypes.Transaction) => {
const iouAction = getIOUActionForTransactionID(reportActions, activeTransaction.transactionID);
const reportIDToNavigate = iouAction?.childReportID;
if (!reportIDToNavigate) {
return;
}

const backTo = Navigation.getActiveRoute();

// Single transaction report will open in RHP, and we need to find every other report ID for the rest of transactions
// to display prev/next arrows in RHP for navigating between transactions
const sortedSiblingTransactionReportIDs = getThreadReportIDsForTransactions(reportActions, sortedData.transactions);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need to filter out pending delete transactions to avoid issue of navigating to those transactions.

setActiveTransactionReportIDs(sortedSiblingTransactionReportIDs);

Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: reportIDToNavigate, backTo}));
},
[reportActions, sortedData.transactions],
);

const dateColumnSize = useMemo(() => {
const shouldShowYearForSomeTransaction = transactions.some((transaction) => shouldShowTransactionYear(transaction));
return shouldShowYearForSomeTransaction ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL;
}, [transactions]);

const pressableStyle = [styles.overflowHidden];

const listHorizontalPadding = styles.ph5;

return !isEmpty(transactions) ? (
<>
{!displayNarrowVersion && (
<MoneyRequestReportTableHeader
shouldShowSorting
sortBy={sortBy}
sortOrder={sortOrder}
dateColumnSize={dateColumnSize}
onSortPress={(selectedSortBy, selectedSortOrder) => {
if (!isSortableColumnName(selectedSortBy)) {
return;
Expand All @@ -90,21 +157,71 @@ function MoneyRequestReportTransactionList({transactions}: MoneyRequestReportTra
}}
/>
)}
<View style={[styles.pv2, styles.ph5]}>
<View style={[listHorizontalPadding, styles.gap2, styles.pb4, displayNarrowVersion && styles.pt4]}>
{sortedData.transactions.map((transaction) => {
return (
<View style={[styles.mb2]}>
<PressableWithFeedback
onPress={(e) => {
if (isMouseDownOnInput) {
e?.stopPropagation();
return;
}

navigateToTransaction(transaction);
}}
accessibilityLabel={translate('iou.viewDetails')}
role={getButtonRole(true)}
isNested
hoverDimmingValue={1}
onMouseDown={(e) => e.preventDefault()}
id={transaction.transactionID}
style={[pressableStyle]}
onMouseLeave={handleMouseLeave}
>
<TransactionItemRow
transactionItem={transaction}
isSelected={false}
shouldShowTooltip
dateColumnSize={dateColumnSize}
shouldUseNarrowLayout={displayNarrowVersion}
shouldShowChatBubbleComponent
/>
</View>
</PressableWithFeedback>
);
})}
</View>
{shouldShowBreakdown && (
<View style={[styles.dFlex, styles.alignItemsEnd, listHorizontalPadding, styles.gap2, styles.mb2]}>
{[
{text: translate('cardTransactions.outOfPocket'), value: formattedOutOfPocketAmount},
{text: translate('cardTransactions.companySpend'), value: formattedCompanySpendAmount},
].map(({text, value}) => (
<View style={[styles.dFlex, styles.flexRow, styles.alignItemsCenter, styles.pr3]}>
<Text
style={[styles.textLabelSupporting, styles.mr3]}
numberOfLines={1}
>
{text}
</Text>
<Text
numberOfLines={1}
style={[styles.textLabelSupporting, styles.textNormal, shouldUseNarrowLayout ? styles.mnw64p : styles.mnw100p, styles.textAlignRight]}
>
{value}
</Text>
</View>
))}
</View>
)}
<View style={[styles.dFlex, styles.flexRow, listHorizontalPadding, styles.justifyContentBetween, styles.mb2]}>
<Text style={[styles.textLabelSupporting]}>{hasComments ? translate('common.comments') : ''}</Text>

@s77rt s77rt Jun 15, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The comments subheader should have been moved outside the !isEmpty(transactions) condition so that it's displayed for reports with no transactions too.

Coming from #63076

<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]}>
{convertToDisplayString(totalDisplaySpend, report?.currency)}
</Text>
</View>
</View>
</>
) : (
<SearchMoneyRequestReportEmptyState />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import {findFocusedRoute} from '@react-navigation/native';
import React, {useMemo} from 'react';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {isFullScreenName} from '@navigation/helpers/isNavigatorName';
import Navigation from '@navigation/Navigation';
import navigationRef from '@navigation/navigationRef';
import type {RootNavigatorParamList, State} from '@navigation/types';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import {getActiveTransactionReportIDs} from './TransactionReportIDRepository';

type MoneyRequestReportRHPNavigationButtonsProps = {
currentReportID: string;
};

/**
* We only want to show the extra navigation for switching between transactions
* If a transaction was opened from MoneyRequestReportView
*/
function shouldShowTransactionNavigation(rootState?: State<RootNavigatorParamList>) {
const lastFullscreenNavigator = rootState?.routes.findLast((route) => isFullScreenName(route.name));
if (lastFullscreenNavigator?.state) {
const focusedRoute = findFocusedRoute(lastFullscreenNavigator.state);
return focusedRoute?.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT;
}
}

function MoneyRequestReportTransactionsNavigation({currentReportID}: MoneyRequestReportRHPNavigationButtonsProps) {
const styles = useThemeStyles();
const theme = useTheme();

const rootState = navigationRef.getRootState() as State<RootNavigatorParamList>;
const shouldShow = shouldShowTransactionNavigation(rootState);

const reportIDsList = getActiveTransactionReportIDs();
const {prevReportID, nextReportID} = useMemo(() => {
if (!reportIDsList) {
return {prevReportID: undefined, nextReportID: undefined};
}

const currentReportIndex = reportIDsList.findIndex((id) => id === currentReportID);

const prevID = currentReportIndex > 0 ? reportIDsList.at(currentReportIndex - 1) : undefined;
const nextID = currentReportIndex <= reportIDsList.length - 1 ? reportIDsList.at(currentReportIndex + 1) : undefined;

return {prevReportID: prevID, nextReportID: nextID};
}, [currentReportID, reportIDsList]);

const backTo = Navigation.getActiveRoute();

if (!shouldShow || reportIDsList.length < 2) {
return;
}

const pressableStyle = [
styles.ml1,
styles.alignItemsCenter,
styles.justifyContentCenter,
{
borderRadius: 50,
width: 28,
height: 28,
backgroundColor: theme.borderLighter,
},
];

return (
<>
<PressableWithFeedback
accessibilityRole={CONST.ROLE.BUTTON}
accessible
accessibilityLabel={CONST.ROLE.BUTTON}
disabled={!prevReportID}
style={pressableStyle}
onPress={(e) => {
e?.preventDefault();
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: prevReportID, backTo}), {forceReplace: true});
}}
>
<Icon
src={Expensicons.BackArrow}
small
fill={theme.icon}
isButtonIcon
/>
</PressableWithFeedback>
<PressableWithFeedback
accessibilityRole={CONST.ROLE.BUTTON}
accessible
accessibilityLabel={CONST.ROLE.BUTTON}
disabled={!nextReportID}
style={pressableStyle}
onPress={(e) => {
e?.preventDefault();
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: nextReportID, backTo}), {forceReplace: true});
}}
>
<Icon
src={Expensicons.ArrowRight}
small
fill={theme.icon}
isButtonIcon
/>
</PressableWithFeedback>
</>
);
}

MoneyRequestReportTransactionsNavigation.displayName = 'MoneyRequestReportTransactionsNavigation';

export default MoneyRequestReportTransactionsNavigation;
Loading