Skip to content

Commit 758b1d7

Browse files
authored
Merge pull request #62286 from software-mansion-labs/feature/kuba-nowakowski/reuse_new_row_component_in_search
Use new transaction component inside reports in search
2 parents c42c98a + cf9c95f commit 758b1d7

File tree

10 files changed

+313
-83
lines changed

10 files changed

+313
-83
lines changed

src/CONST.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,17 @@ const CONST = {
14101410
TRANSACTION_LIST: {
14111411
COLUMNS: {
14121412
COMMENTS: 'comments',
1413+
RECEIPT: 'receipt',
1414+
DATE: 'date',
1415+
MERCHANT: 'merchant',
1416+
FROM: 'from',
1417+
TO: 'to',
1418+
CATEGORY: 'category',
1419+
TAG: 'tag',
1420+
TOTAL_AMOUNT: 'amount',
1421+
TYPE: 'type',
1422+
ACTION: 'action',
1423+
TAX: 'tax',
14131424
},
14141425
},
14151426
CANCEL_PAYMENT_REASONS: {

src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ const sortableColumnNames = [
6767
CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT,
6868
];
6969

70+
const allReportColumns = [
71+
CONST.REPORT.TRANSACTION_LIST.COLUMNS.RECEIPT,
72+
CONST.REPORT.TRANSACTION_LIST.COLUMNS.TYPE,
73+
CONST.REPORT.TRANSACTION_LIST.COLUMNS.DATE,
74+
CONST.REPORT.TRANSACTION_LIST.COLUMNS.MERCHANT,
75+
CONST.REPORT.TRANSACTION_LIST.COLUMNS.CATEGORY,
76+
CONST.REPORT.TRANSACTION_LIST.COLUMNS.TAG,
77+
CONST.REPORT.TRANSACTION_LIST.COLUMNS.COMMENTS,
78+
CONST.REPORT.TRANSACTION_LIST.COLUMNS.TOTAL_AMOUNT,
79+
];
80+
7081
type SortableColumnName = TupleToUnion<typeof sortableColumnNames>;
7182

7283
type SortedTransactions = {
@@ -260,6 +271,7 @@ function MoneyRequestReportTransactionList({report, transactions, reportActions,
260271
shouldUseNarrowLayout={shouldUseNarrowLayout || isMediumScreenWidth}
261272
shouldShowCheckbox={!!selectionMode?.isEnabled || isMediumScreenWidth}
262273
onCheckboxPress={toggleTransaction}
274+
columns={allReportColumns}
263275
/>
264276
</PressableWithFeedback>
265277
);

src/components/SelectionList/Search/ReportListItem.tsx

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
import React from 'react';
1+
import React, {useMemo} from 'react';
22
import {View} from 'react-native';
33
import {useOnyx} from 'react-native-onyx';
4+
import type {ValueOf} from 'type-fest';
45
import BaseListItem from '@components/SelectionList/BaseListItem';
56
import type {ListItem, ReportListItemProps, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
67
import Text from '@components/Text';
8+
import TransactionItemRow from '@components/TransactionItemRow';
79
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
810
import useLocalize from '@hooks/useLocalize';
911
import usePermissions from '@hooks/usePermissions';
12+
import useResponsiveLayout from '@hooks/useResponsiveLayout';
1013
import useTheme from '@hooks/useTheme';
1114
import useThemeStyles from '@hooks/useThemeStyles';
1215
import Navigation from '@libs/Navigation/Navigation';
16+
import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear';
1317
import variables from '@styles/variables';
1418
import CONST from '@src/CONST';
1519
import ONYXKEYS from '@src/ONYXKEYS';
1620
import ROUTES from '@src/ROUTES';
1721
import ReportListItemHeader from './ReportListItemHeader';
18-
import TransactionListItemRow from './TransactionListItemRow';
1922

2023
function ReportListItem<TItem extends ListItem>({
2124
item,
@@ -38,6 +41,12 @@ function ReportListItem<TItem extends ListItem>({
3841
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportItem?.policyID}`];
3942
const isEmptyReport = reportItem.transactions.length === 0;
4043
const isDisabledOrEmpty = isEmptyReport || isDisabled;
44+
const {isLargeScreenWidth} = useResponsiveLayout();
45+
46+
const dateColumnSize = useMemo(() => {
47+
const shouldShowYearForSomeTransaction = reportItem.transactions.some((transaction) => shouldShowTransactionYear(transaction));
48+
return shouldShowYearForSomeTransaction ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL;
49+
}, [reportItem.transactions]);
4150

4251
const animatedHighlightStyle = useAnimatedHighlightStyle({
4352
borderRadius: variables.componentBorderRadius,
@@ -78,6 +87,23 @@ function ReportListItem<TItem extends ListItem>({
7887
return null;
7988
}
8089

90+
const sampleTransaction = reportItem.transactions.at(0);
91+
const {COLUMNS} = CONST.REPORT.TRANSACTION_LIST;
92+
93+
const columns = [
94+
COLUMNS.RECEIPT,
95+
COLUMNS.TYPE,
96+
COLUMNS.DATE,
97+
COLUMNS.MERCHANT,
98+
COLUMNS.FROM,
99+
COLUMNS.TO,
100+
...(sampleTransaction?.shouldShowCategory ? [COLUMNS.CATEGORY] : []),
101+
...(sampleTransaction?.shouldShowTag ? [COLUMNS.TAG] : []),
102+
...(sampleTransaction?.shouldShowTax ? [COLUMNS.TAX] : []),
103+
COLUMNS.TOTAL_AMOUNT,
104+
COLUMNS.ACTION,
105+
] as Array<ValueOf<typeof COLUMNS>>;
106+
81107
return (
82108
<BaseListItem
83109
item={item}
@@ -98,7 +124,7 @@ function ReportListItem<TItem extends ListItem>({
98124
hoverStyle={item.isSelected && styles.activeComponentBG}
99125
pressableWrapperStyle={[styles.mh5, animatedHighlightStyle]}
100126
>
101-
{(hovered?: boolean) => (
127+
{(hovered) => (
102128
<View style={[styles.flex1]}>
103129
<ReportListItemHeader
104130
report={reportItem}
@@ -122,23 +148,23 @@ function ReportListItem<TItem extends ListItem>({
122148
</View>
123149
) : (
124150
reportItem.transactions.map((transaction) => (
125-
<TransactionListItemRow
126-
key={transaction.transactionID}
127-
parentAction={reportItem.action}
128-
item={transaction}
129-
showTooltip={showTooltip}
130-
onButtonPress={() => {
131-
openReportInRHP(transaction);
132-
}}
133-
onCheckboxPress={() => onCheckboxPress?.(transaction as unknown as TItem)}
134-
showItemHeaderOnNarrowLayout={false}
135-
containerStyle={[transaction.isSelected && styles.activeComponentBG, styles.ph3, styles.pv1half]}
136-
isChildListItem
137-
isDisabled={!!isDisabled}
138-
canSelectMultiple={!!canSelectMultiple}
139-
isButtonSelected={transaction.isSelected}
140-
shouldShowTransactionCheckbox
141-
/>
151+
<View>
152+
<TransactionItemRow
153+
transactionItem={transaction}
154+
isSelected={!!transaction.isSelected}
155+
dateColumnSize={dateColumnSize}
156+
shouldShowTooltip={showTooltip}
157+
shouldUseNarrowLayout={!isLargeScreenWidth}
158+
shouldShowCheckbox={!!canSelectMultiple}
159+
onCheckboxPress={() => onCheckboxPress?.(transaction as unknown as TItem)}
160+
columns={columns}
161+
onButtonPress={() => {
162+
openReportInRHP(transaction);
163+
}}
164+
isParentHovered={hovered}
165+
columnWrapperStyles={[styles.ph3, styles.pv1half]}
166+
/>
167+
</View>
142168
))
143169
)}
144170
</View>

src/components/TransactionItemRow/DataCells/MerchantCell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {getMerchant} from '@libs/TransactionUtils';
55
import CONST from '@src/CONST';
66
import type TransactionDataCellProps from './TransactionDataCellProps';
77

8-
function MerchantCell({transactionItem, shouldShowTooltip}: TransactionDataCellProps) {
8+
function MerchantCell({transactionItem, shouldShowTooltip, shouldUseNarrowLayout}: TransactionDataCellProps) {
99
const styles = useThemeStyles();
1010

1111
const merchantName = getMerchant(transactionItem);
@@ -15,7 +15,7 @@ function MerchantCell({transactionItem, shouldShowTooltip}: TransactionDataCellP
1515
<TextWithTooltip
1616
shouldShowTooltip={shouldShowTooltip}
1717
text={merchantToDisplay}
18-
style={[styles.pre, styles.justifyContentCenter, styles.flex1]}
18+
style={[!shouldUseNarrowLayout ? styles.lineHeightLarge : styles.lh20, styles.pre, styles.justifyContentCenter]}
1919
/>
2020
);
2121
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import TextWithTooltip from '@components/TextWithTooltip';
2+
import useThemeStyles from '@hooks/useThemeStyles';
3+
import {convertToDisplayString} from '@libs/CurrencyUtils';
4+
import {getTaxAmount, getCurrency as getTransactionCurrency} from '@libs/TransactionUtils';
5+
import type TransactionDataCellProps from './TransactionDataCellProps';
6+
7+
function TaxCell({transactionItem, shouldShowTooltip}: TransactionDataCellProps) {
8+
const styles = useThemeStyles();
9+
10+
const taxAmount = getTaxAmount(transactionItem, true);
11+
const currency = getTransactionCurrency(transactionItem);
12+
13+
return (
14+
<TextWithTooltip
15+
shouldShowTooltip={shouldShowTooltip}
16+
text={convertToDisplayString(taxAmount, currency)}
17+
style={[styles.optionDisplayName, styles.lineHeightLarge, styles.pre, styles.justifyContentCenter, styles.textAlignRight]}
18+
/>
19+
);
20+
}
21+
22+
TaxCell.displayName = 'TaxCell';
23+
export default TaxCell;

src/components/TransactionItemRow/DataCells/TransactionDataCellProps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type Transaction from '@src/types/onyx/Transaction';
1+
import type {TransactionWithOptionalSearchFields} from '..';
22

33
type TransactionDataCellProps = {
4-
transactionItem: Transaction;
4+
transactionItem: TransactionWithOptionalSearchFields;
55
shouldShowTooltip: boolean;
66
shouldUseNarrowLayout?: boolean;
77
};

src/components/TransactionItemRow/DataCells/TypeCell.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const getTypeIcon = (type?: string) => {
2424
switch (type) {
2525
case CONST.SEARCH.TRANSACTION_TYPE.CARD:
2626
return Expensicons.CreditCard;
27+
case CONST.SEARCH.TRANSACTION_TYPE.DISTANCE:
28+
return Expensicons.Car;
2729
case CONST.SEARCH.TRANSACTION_TYPE.CASH:
2830
default:
2931
return Expensicons.Cash;
@@ -32,6 +34,8 @@ const getTypeIcon = (type?: string) => {
3234

3335
const getTypeText = (type?: string): TranslationPaths => {
3436
switch (type) {
37+
case CONST.SEARCH.TRANSACTION_TYPE.DISTANCE:
38+
return 'common.distance';
3539
case CONST.SEARCH.TRANSACTION_TYPE.CARD:
3640
return 'iou.card';
3741
case CONST.SEARCH.TRANSACTION_TYPE.CASH:
@@ -43,7 +47,7 @@ const getTypeText = (type?: string): TranslationPaths => {
4347
function TypeCell({transactionItem, shouldUseNarrowLayout, shouldShowTooltip}: TransactionDataCellProps) {
4448
const {translate} = useLocalize();
4549
const theme = useTheme();
46-
const type = getType(transactionItem.cardName);
50+
const type = transactionItem.transactionType ?? getType(transactionItem.cardName);
4751
const typeIcon = getTypeIcon(type);
4852
const typeText = getTypeText(type);
4953
const styles = useThemeStyles();

0 commit comments

Comments
 (0)