1
- import React from 'react' ;
1
+ import React , { useMemo } from 'react' ;
2
2
import { View } from 'react-native' ;
3
3
import { useOnyx } from 'react-native-onyx' ;
4
+ import type { ValueOf } from 'type-fest' ;
4
5
import BaseListItem from '@components/SelectionList/BaseListItem' ;
5
6
import type { ListItem , ReportListItemProps , ReportListItemType , TransactionListItemType } from '@components/SelectionList/types' ;
6
7
import Text from '@components/Text' ;
8
+ import TransactionItemRow from '@components/TransactionItemRow' ;
7
9
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle' ;
8
10
import useLocalize from '@hooks/useLocalize' ;
9
11
import usePermissions from '@hooks/usePermissions' ;
12
+ import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
10
13
import useTheme from '@hooks/useTheme' ;
11
14
import useThemeStyles from '@hooks/useThemeStyles' ;
12
15
import Navigation from '@libs/Navigation/Navigation' ;
16
+ import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear' ;
13
17
import variables from '@styles/variables' ;
14
18
import CONST from '@src/CONST' ;
15
19
import ONYXKEYS from '@src/ONYXKEYS' ;
16
20
import ROUTES from '@src/ROUTES' ;
17
21
import ReportListItemHeader from './ReportListItemHeader' ;
18
- import TransactionListItemRow from './TransactionListItemRow' ;
19
22
20
23
function ReportListItem < TItem extends ListItem > ( {
21
24
item,
@@ -38,6 +41,12 @@ function ReportListItem<TItem extends ListItem>({
38
41
const policy = policies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ reportItem ?. policyID } ` ] ;
39
42
const isEmptyReport = reportItem . transactions . length === 0 ;
40
43
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 ] ) ;
41
50
42
51
const animatedHighlightStyle = useAnimatedHighlightStyle ( {
43
52
borderRadius : variables . componentBorderRadius ,
@@ -78,6 +87,23 @@ function ReportListItem<TItem extends ListItem>({
78
87
return null ;
79
88
}
80
89
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
+
81
107
return (
82
108
< BaseListItem
83
109
item = { item }
@@ -98,7 +124,7 @@ function ReportListItem<TItem extends ListItem>({
98
124
hoverStyle = { item . isSelected && styles . activeComponentBG }
99
125
pressableWrapperStyle = { [ styles . mh5 , animatedHighlightStyle ] }
100
126
>
101
- { ( hovered ?: boolean ) => (
127
+ { ( hovered ) => (
102
128
< View style = { [ styles . flex1 ] } >
103
129
< ReportListItemHeader
104
130
report = { reportItem }
@@ -122,23 +148,23 @@ function ReportListItem<TItem extends ListItem>({
122
148
</ View >
123
149
) : (
124
150
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 >
142
168
) )
143
169
) }
144
170
</ View >
0 commit comments