Skip to content

Commit

Permalink
Merge pull request #44674 from dominictb/fix/44131
Browse files Browse the repository at this point in the history
fix: update grouped expense on search page
  • Loading branch information
luacmartins authored Jul 12, 2024
2 parents ec19663 + 422e6fe commit ac64d44
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 45 deletions.
14 changes: 13 additions & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useIsFocused} from '@react-navigation/native';
import type {ForwardedRef} from 'react';
import React, {useCallback, useMemo} from 'react';
import React, {useCallback, useMemo, useState} from 'react';
import type {GestureResponderEvent, StyleProp, TextStyle, ViewStyle} from 'react-native';
import {ActivityIndicator, View} from 'react-native';
import Icon from '@components/Icon';
Expand Down Expand Up @@ -89,6 +89,9 @@ type ButtonProps = Partial<ChildrenProps> & {
/** Whether we should use the danger theme color */
danger?: boolean;

/** Whether we should display the button as a link */
link?: boolean;

/** Should we remove the right border radius top + bottom? */
shouldRemoveRightBorderRadius?: boolean;

Expand Down Expand Up @@ -205,6 +208,7 @@ function Button(
id = '',
accessibilityLabel = '',
isSplitButton = false,
link = false,
isContentCentered = false,
...rest
}: ButtonProps,
Expand All @@ -213,6 +217,7 @@ function Button(
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const [isHovered, setIsHovered] = useState(false);

const renderContent = () => {
if ('children' in rest) {
Expand All @@ -233,6 +238,10 @@ function Button(
danger && styles.buttonDangerText,
!!icon && styles.textAlignLeft,
textStyles,
link && styles.link,
link && isHovered && StyleUtils.getColorStyle(theme.linkHover),
link && styles.fontWeightNormal,
link && styles.fontSizeLabel,
]}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
>
Expand Down Expand Up @@ -343,6 +352,7 @@ function Button(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
text && shouldShowRightIcon ? styles.alignItemsStretch : undefined,
innerStyles,
link && styles.bgTransparent,
]}
hoverStyle={[
shouldUseDefaultHover && !isDisabled ? styles.buttonDefaultHovered : undefined,
Expand All @@ -353,6 +363,8 @@ function Button(
accessibilityLabel={accessibilityLabel}
role={CONST.ROLE.BUTTON}
hoverDimmingValue={1}
onHoverIn={() => setIsHovered(true)}
onHoverOut={() => setIsHovered(false)}
>
{renderContent()}
{isLoading && (
Expand Down
38 changes: 30 additions & 8 deletions src/components/SelectionList/Search/ActionCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ type ActionCellProps = {
isLargeScreenWidth?: boolean;
isSelected?: boolean;
goToItem: () => void;
isChildListItem?: boolean;
parentAction?: string;
};

function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, transactionID, isLargeScreenWidth = true, isSelected = false, goToItem}: ActionCellProps) {
function ActionCell({
action = CONST.SEARCH.ACTION_TYPES.VIEW,
transactionID,
isLargeScreenWidth = true,
isSelected = false,
goToItem,
isChildListItem = false,
parentAction = '',
}: ActionCellProps) {
const {translate} = useLocalize();
const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -53,13 +63,11 @@ function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, transactionID, isL
}
}, [action, currentSearchHash, transactionID]);

if (!isLargeScreenWidth) {
return null;
}

const text = translate(actionTranslationsMap[action]);

if (action === CONST.SEARCH.ACTION_TYPES.PAID || action === CONST.SEARCH.ACTION_TYPES.DONE) {
const shouldUseViewAction = action === CONST.SEARCH.ACTION_TYPES.VIEW || (parentAction === CONST.SEARCH.ACTION_TYPES.PAID && action === CONST.SEARCH.ACTION_TYPES.PAID);

if ((parentAction !== CONST.SEARCH.ACTION_TYPES.PAID && action === CONST.SEARCH.ACTION_TYPES.PAID) || action === CONST.SEARCH.ACTION_TYPES.DONE) {
return (
<View style={[StyleUtils.getHeight(variables.h28), styles.justifyContentCenter]}>
<Badge
Expand All @@ -84,7 +92,22 @@ function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, transactionID, isL

const buttonInnerStyles = isSelected ? styles.buttonDefaultHovered : {};

if (action === CONST.SEARCH.ACTION_TYPES.VIEW || action === CONST.SEARCH.ACTION_TYPES.REVIEW) {
if (action === CONST.SEARCH.ACTION_TYPES.VIEW || shouldUseViewAction) {
return isLargeScreenWidth ? (
<Button
text={translate(actionTranslationsMap[CONST.SEARCH.ACTION_TYPES.VIEW])}
onPress={goToItem}
small
pressOnEnter
style={[styles.w100]}
innerStyles={buttonInnerStyles}
link={isChildListItem}
shouldUseDefaultHover={!isChildListItem}
/>
) : null;
}

if (action === CONST.SEARCH.ACTION_TYPES.REVIEW) {
return (
<Button
text={text}
Expand All @@ -96,7 +119,6 @@ function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, transactionID, isL
/>
);
}

return (
<Button
text={text}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function ExpenseItemHeaderNarrow({
action={action}
transactionID={transactionID}
goToItem={onButtonPress}
isLargeScreenWidth={false}
/>
</View>
</View>
Expand Down
27 changes: 10 additions & 17 deletions src/components/SelectionList/Search/ReportListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import BaseListItem from '@components/SelectionList/BaseListItem';
import type {ListItem, ReportListItemProps, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
import Text from '@components/Text';
import TextWithTooltip from '@components/TextWithTooltip';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand Down Expand Up @@ -65,15 +64,14 @@ function ReportListItem<TItem extends ListItem>({
const reportItem = item as unknown as ReportListItemType;

const styles = useThemeStyles();
const {translate} = useLocalize();
const {isLargeScreenWidth} = useWindowDimensions();
const StyleUtils = useStyleUtils();

if (reportItem.transactions.length === 0) {
return;
}

const listItemPressableStyle = [styles.selectionListPressableItemWrapper, styles.pv3, item.isSelected && styles.activeComponentBG, isFocused && styles.sidebarLinkActive];
const listItemPressableStyle = [styles.selectionListPressableItemWrapper, styles.pv3, item.isSelected && styles.activeComponentBG, isFocused && styles.sidebarLinkActive, styles.ph3];

const handleOnButtonPress = () => {
onSelectRow(item);
Expand Down Expand Up @@ -148,7 +146,7 @@ function ReportListItem<TItem extends ListItem>({
onButtonPress={handleOnButtonPress}
/>
)}
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter, styles.gap3]}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter, styles.gap3, styles.mnh40]}>
<View style={[styles.flexRow, styles.flex1, styles.alignItemsCenter, styles.justifyContentBetween]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.flex2]}>
{canSelectMultiple && (
Expand All @@ -163,7 +161,6 @@ function ReportListItem<TItem extends ListItem>({
)}
<View style={[styles.flexShrink1, isLargeScreenWidth && styles.ph4]}>
<Text style={[styles.reportListItemTitle]}>{reportItem?.reportName}</Text>
<Text style={[styles.textMicroSupporting]}>{`${reportItem.transactions.length} ${translate('search.groupedExpenses')}`}</Text>
</View>
</View>
<View style={[styles.flexRow, styles.flex1, styles.justifyContentEnd]}>
Expand All @@ -175,22 +172,18 @@ function ReportListItem<TItem extends ListItem>({
</View>
</View>
{isLargeScreenWidth && (
<>
{/** We add an empty view with type style to align the total with the table header */}
<View style={StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TYPE)} />
<View style={StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.ACTION)}>
<ActionCell
action={reportItem.action}
goToItem={handleOnButtonPress}
isSelected={item.isSelected}
/>
</View>
</>
<View style={StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.ACTION)}>
<ActionCell
action={reportItem.action}
goToItem={handleOnButtonPress}
isSelected={item.isSelected}
/>
</View>
)}
</View>
<View style={[styles.mt3, styles.reportListItemSeparator]} />
{reportItem.transactions.map((transaction) => (
<TransactionListItemRow
parentAction={reportItem.action}
item={transaction}
showTooltip={showTooltip}
onButtonPress={() => {
Expand Down
18 changes: 11 additions & 7 deletions src/components/SelectionList/Search/TransactionListItemRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type TransactionListItemRowProps = {
isDisabled: boolean;
canSelectMultiple: boolean;
isButtonSelected?: boolean;
parentAction?: string;
shouldShowTransactionCheckbox?: boolean;
};

Expand Down Expand Up @@ -242,6 +243,7 @@ function TransactionListItemRow({
containerStyle,
isChildListItem = false,
isButtonSelected = false,
parentAction = '',
shouldShowTransactionCheckbox,
}: TransactionListItemRowProps) {
const styles = useThemeStyles();
Expand Down Expand Up @@ -356,6 +358,13 @@ function TransactionListItemRow({
showTooltip={false}
/>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TYPE)]}>
<TypeCell
transactionItem={item}
isLargeScreenWidth={isLargeScreenWidth}
showTooltip={false}
/>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.DATE, item.shouldShowYear)]}>
<DateCell
transactionItem={item}
Expand Down Expand Up @@ -418,18 +427,13 @@ function TransactionListItemRow({
isChildListItem={isChildListItem}
/>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TYPE)]}>
<TypeCell
transactionItem={item}
isLargeScreenWidth
showTooltip={false}
/>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.ACTION)]}>
<ActionCell
action={item.action}
transactionID={item.transactionID}
isSelected={isButtonSelected}
isChildListItem={isChildListItem}
parentAction={parentAction}
goToItem={onButtonPress}
/>
</View>
Expand Down
12 changes: 6 additions & 6 deletions src/components/SelectionList/SearchTableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const SearchColumns: SearchColumnConfig[] = [
shouldShow: () => true,
isColumnSortable: false,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.TYPE,
translationKey: 'common.type',
shouldShow: () => true,
isColumnSortable: false,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.DATE,
translationKey: 'common.date',
Expand Down Expand Up @@ -71,12 +77,6 @@ const SearchColumns: SearchColumnConfig[] = [
translationKey: 'common.total',
shouldShow: () => true,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.TYPE,
translationKey: 'common.type',
shouldShow: () => true,
isColumnSortable: false,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.ACTION,
translationKey: 'common.action',
Expand Down
9 changes: 3 additions & 6 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ const styles = (theme: ThemeColors) =>
appBG: {
backgroundColor: theme.appBG,
},
fontSizeLabel: {
fontSize: variables.fontSizeLabel,
},

h4: {
fontFamily: FontUtils.fontFamily.platform.EXP_NEUE_BOLD,
Expand Down Expand Up @@ -5078,15 +5081,9 @@ const styles = (theme: ThemeColors) =>
height: 172,
},

reportListItemSeparator: {
borderBottomWidth: 1,
borderBottomColor: theme.activeComponentBG,
},

reportListItemTitle: {
color: theme.text,
fontSize: variables.fontSizeNormal,
fontWeight: FontUtils.fontWeight.bold,
},

skeletonBackground: {
Expand Down
3 changes: 3 additions & 0 deletions src/styles/utils/sizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export default {
mnh20: {
minHeight: 80,
},
mnh40: {
minHeight: 40,
},

mnh0: {
minHeight: 0,
Expand Down

0 comments on commit ac64d44

Please sign in to comment.