Repository navigation
Improve MoneyRequestReportView #58903
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
mountiny
merged 24 commits into
Expensify:main
from
software-mansion-labs:kicu/57508-improve-money-report-view
Mar 31, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0a90b85
Improve MoneyRequestReportView
Kicu 022d3a3
Make SearchTypeMenu look correct with undefined Search query
Kicu 0512fc9
Improve SearchMoneyRequestReportPage loading and not found page
Kicu 228e7ab
Add navigating to transaction reportID
Kicu 1378cef
Add totals under table (#213)
jnowakow 20e5c22
Add navigation when clicking on Transaction row
Kicu 22606bc
Improve styling and types in MoneyRequestReportView
Kicu e2c3b27
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu 52710c4
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu 276b51c
Add styling tweaks
Kicu b2df980
Improve filtering out actions for MoneyRequestReportActionsList
Kicu 53da96d
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu fb78db2
Update styling of table headers
Kicu 7d01b19
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu 7267ab2
Update styling and skeleton loader of MoneyRequestReportView
Kicu aa76192
Add fixes after PR review
Kicu fec3a79
Fix linting and TS for MoneyRequestReportPage
Kicu eaf9379
Fix undefined routes and openReport call
Kicu 36290e1
Improve comments around openReport calling new flag
Kicu fca1657
Fix code style
Kicu 659d7e1
Merge branch 'main' into kicu/57508-improve-money-report-view
Kicu 91f6b5c
Handle EmptyState in MoneyRequestReportActionsList after merge conflicts
Kicu 8d628fe
Add tests for MoneyRequestReportTransactionList
Kicu 739e58d
Fix lint
Kicu 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
284 changes: 231 additions & 53 deletions
284
src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
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
| 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 = [ | ||
|
|
@@ -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; | ||
|
|
@@ -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); | ||
| 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; | ||
|
|
@@ -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> | ||
|
Member
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. The comments subheader should have been moved outside the 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 /> | ||
|
|
||
116 changes: 116 additions & 0 deletions
116
src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx
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,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; |
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.
We need to filter out pending delete transactions to avoid issue of navigating to those transactions.