-
Notifications
You must be signed in to change notification settings - Fork 3.9k
perf: Split ExpenseReportListItemRow, defer ActionCell, extract Avatar #89083
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
Changes from all commits
4ffed6f
6279e80
3e8322a
2b56c75
b564b4d
1c4c652
f9b16ac
5fa1f8d
1c041db
efbf5ab
43ff4a9
ecdac1b
a392ced
8995d26
83857e2
eb8038d
6fe075c
35dfdaa
2ee9f5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import React, {useDeferredValue} from 'react'; | ||
| import Button from '@components/Button'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
| import ActionCell from '.'; | ||
| import type {ActionCellProps} from '.'; | ||
| import actionTranslationsMap from './actionTranslationsMap'; | ||
|
|
||
| function DeferredActionCell(actionCellProps: ActionCellProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const shouldRender = useDeferredValue(true, false); | ||
|
|
||
| if (!shouldRender) { | ||
| const action = actionCellProps.action ?? CONST.SEARCH.ACTION_TYPES.VIEW; | ||
| const shouldUseViewAction = action === CONST.SEARCH.ACTION_TYPES.VIEW || action === CONST.SEARCH.ACTION_TYPES.PAID || action === CONST.SEARCH.ACTION_TYPES.DONE; | ||
| const isSuccess = !shouldUseViewAction && action !== CONST.SEARCH.ACTION_TYPES.UNDELETE; | ||
| const text = shouldUseViewAction ? translate(actionTranslationsMap[CONST.SEARCH.ACTION_TYPES.VIEW]) : translate(actionTranslationsMap[action]); | ||
|
|
||
| return ( | ||
| <Button | ||
| text={text} | ||
| small={!actionCellProps.extraSmall} | ||
| extraSmall={actionCellProps.extraSmall} | ||
| style={[styles.w100, styles.pointerEventsNone]} | ||
| isDisabled | ||
| success={isSuccess} | ||
| isNested | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| // Deferred wrapper intentionally forwards all props to the underlying component | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| return <ActionCell {...actionCellProps} />; | ||
| } | ||
|
|
||
| export default DeferredActionCell; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import SearchReportAvatar from '@components/ReportActionAvatars/SearchReportAvatar'; | ||
| import type {ExpenseReportListItemType} from '@components/Search/SearchList/ListItem/types'; | ||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| type ExpenseReportListItemAvatarProps = { | ||
| item: ExpenseReportListItemType; | ||
| showTooltip: boolean; | ||
| isHovered?: boolean; | ||
| isFocused?: boolean; | ||
| isLargeScreenWidth?: boolean; | ||
| }; | ||
|
|
||
| function ExpenseReportListItemAvatar({item, showTooltip, isHovered = false, isFocused = false, isLargeScreenWidth = false}: ExpenseReportListItemAvatarProps) { | ||
| const StyleUtils = useStyleUtils(); | ||
| const styles = useThemeStyles(); | ||
| const theme = useTheme(); | ||
|
|
||
| const finalAvatarBorderColor = | ||
| StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, isFocused || isHovered, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG)?.backgroundColor ?? | ||
| theme.highlightBG; | ||
|
|
||
| return ( | ||
| <View style={[StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.AVATAR), styles.alignItemsStretch]}> | ||
| <SearchReportAvatar | ||
| primaryAvatar={item.primaryAvatar} | ||
| secondaryAvatar={item.secondaryAvatar} | ||
| avatarType={item.avatarType} | ||
| shouldShowTooltip={showTooltip} | ||
| subscriptAvatarBorderColor={finalAvatarBorderColor} | ||
| reportID={item.reportID} | ||
| isLargeScreenWidth={isLargeScreenWidth} | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default ExpenseReportListItemAvatar; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import Checkbox from '@components/Checkbox'; | ||
| import Text from '@components/Text'; | ||
| import {useCurrencyListActions} from '@hooks/useCurrencyList'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import DateUtils from '@libs/DateUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import type {ExpenseReportListItemRowNarrowProps} from './types'; | ||
|
|
||
| function ExpenseReportListItemRowNarrow({item, onCheckboxPress = () => {}, canSelectMultiple, isSelectAllChecked, isIndeterminate, isDisabledCheckbox}: ExpenseReportListItemRowNarrowProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const {convertToDisplayString} = useCurrencyListActions(); | ||
|
|
||
| const currency = item.currency ?? CONST.CURRENCY.USD; | ||
| const {totalDisplaySpend = 0, isAllScanning: isScanning = false} = item; | ||
|
|
||
| const filteredTransactions = item.transactions?.filter((t) => t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); | ||
| const expenseCount = (filteredTransactions?.length ? filteredTransactions.length : undefined) ?? item.transactionCount ?? 0; | ||
| const expenseCountText = translate('iou.expenseCount', {count: expenseCount}); | ||
| const formattedDate = DateUtils.formatWithUTCTimeZone( | ||
| item.created ?? '', | ||
| DateUtils.doesDateBelongToAPastYear(item.created ?? '') ? CONST.DATE.MONTH_DAY_YEAR_ABBR_FORMAT : CONST.DATE.MONTH_DAY_ABBR_FORMAT, | ||
| ); | ||
|
|
||
| const amountText = isScanning ? translate('iou.receiptStatusTitle') : convertToDisplayString(totalDisplaySpend, currency); | ||
| const groupAccessibilityLabel = [item.reportName, amountText, formattedDate, expenseCountText].filter(Boolean).join(', '); | ||
|
|
||
| return ( | ||
| <View | ||
| style={[styles.flexRow, styles.alignItemsCenter, styles.gap3, styles.pt3]} | ||
|
Contributor
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. Why do we need to add styles.pt3? This style seems new compared to before.
Contributor
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. Before this PR |
||
| accessible | ||
| accessibilityLabel={groupAccessibilityLabel} | ||
| role={CONST.ROLE.BUTTON} | ||
| > | ||
| {!!canSelectMultiple && ( | ||
| <Checkbox | ||
| onPress={onCheckboxPress} | ||
| isChecked={isSelectAllChecked} | ||
| isIndeterminate={isIndeterminate} | ||
| containerStyle={styles.m0} | ||
| disabled={isDisabledCheckbox} | ||
| accessibilityLabel={item.text ?? ''} | ||
| shouldStopMouseDownPropagation | ||
| style={[styles.cursorUnset, isDisabledCheckbox && styles.cursorDisabled]} | ||
| sentryLabel={CONST.SENTRY_LABEL.SEARCH.EXPENSE_REPORT_CHECKBOX} | ||
| /> | ||
| )} | ||
| <View style={[styles.flexColumn, styles.gap1, styles.flex1]}> | ||
| <View style={[styles.flexRow, styles.gap2]}> | ||
| <Text | ||
| numberOfLines={2} | ||
| style={[styles.lh20, styles.flex1]} | ||
| > | ||
| {item.reportName ?? ''} | ||
| </Text> | ||
| <Text style={[styles.lh20, styles.flexShrink0, styles.textAlignRight]}>{amountText}</Text> | ||
| </View> | ||
| <View style={[styles.flexRow, styles.gap2]}> | ||
| <Text style={[styles.mutedNormalTextLabel, styles.flex1]}>{formattedDate}</Text> | ||
| <Text style={[styles.mutedNormalTextLabel, styles.flexShrink0, styles.textAlignRight]}>{expenseCountText}</Text> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default ExpenseReportListItemRowNarrow; | ||
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.
React compiler handles memoization