Skip to content
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

Display Done and Paid badges in Search #43951

Merged
merged 15 commits into from
Jun 24, 2024
77 changes: 41 additions & 36 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,20 +943,6 @@ const CONST = {
RESIZE_DEBOUNCE_TIME: 100,
UNREAD_UPDATE_DEBOUNCE_TIME: 300,
},
SEARCH_TABLE_COLUMNS: {
RECEIPT: 'receipt',
DATE: 'date',
MERCHANT: 'merchant',
DESCRIPTION: 'description',
FROM: 'from',
TO: 'to',
CATEGORY: 'category',
TAG: 'tag',
TOTAL_AMOUNT: 'amount',
TYPE: 'type',
ACTION: 'action',
TAX_AMOUNT: 'taxAmount',
},
PRIORITY_MODE: {
GSD: 'gsd',
DEFAULT: 'default',
Expand Down Expand Up @@ -3526,12 +3512,7 @@ const CONST = {
SCAN: 'scan',
DISTANCE: 'distance',
},
TAB_SEARCH: {
ALL: 'all',
SHARED: 'shared',
DRAFTS: 'drafts',
FINISHED: 'finished',
},

STATUS_TEXT_MAX_LENGTH: 100,

DROPDOWN_BUTTON_SIZE: {
Expand Down Expand Up @@ -4832,28 +4813,52 @@ const CONST = {
ADHOC: ' AdHoc',
},

SEARCH_TRANSACTION_TYPE: {
CASH: 'cash',
CARD: 'card',
DISTANCE: 'distance',
},

SEARCH_RESULTS_PAGE_SIZE: 50,

SEARCH_DATA_TYPES: {
TRANSACTION: 'transaction',
REPORT: 'report',
SEARCH: {
RESULTS_PAGE_SIZE: 50,
DATA_TYPES: {
TRANSACTION: 'transaction',
REPORT: 'report',
},
ACTION_TYPES: {
DONE: 'done',
PAID: 'paid',
VIEW: 'view',
},
TRANSACTION_TYPE: {
CASH: 'cash',
CARD: 'card',
DISTANCE: 'distance',
},
SORT_ORDER: {
ASC: 'asc',
DESC: 'desc',
},
TAB: {
ALL: 'all',
SHARED: 'shared',
DRAFTS: 'drafts',
FINISHED: 'finished',
},
TABLE_COLUMNS: {
RECEIPT: 'receipt',
DATE: 'date',
MERCHANT: 'merchant',
DESCRIPTION: 'description',
FROM: 'from',
TO: 'to',
CATEGORY: 'category',
TAG: 'tag',
TOTAL_AMOUNT: 'amount',
TYPE: 'type',
ACTION: 'action',
TAX_AMOUNT: 'taxAmount',
},
},

REFERRER: {
NOTIFICATION: 'notification',
},

SORT_ORDER: {
ASC: 'asc',
DESC: 'desc',
},

SUBSCRIPTION_SIZE_LIMIT: 20000,

PAYMENT_CARD_CURRENCY: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type SearchProps = {
sortOrder?: SortOrder;
};

const sortableSearchTabs: SearchQuery[] = [CONST.TAB_SEARCH.ALL];
const sortableSearchTabs: SearchQuery[] = [CONST.SEARCH.TAB.ALL];
const transactionItemMobileHeight = 100;
const reportItemTransactionHeight = 52;
const listItemPadding = 12; // this is equivalent to 'mb3' on every transaction/report list item
Expand Down Expand Up @@ -125,7 +125,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) {
return;
}
const currentOffset = searchResults?.search?.offset ?? 0;
SearchActions.search({hash, query, offset: currentOffset + CONST.SEARCH_RESULTS_PAGE_SIZE, sortBy, sortOrder});
SearchActions.search({hash, query, offset: currentOffset + CONST.SEARCH.RESULTS_PAGE_SIZE, sortBy, sortOrder});
};

const type = SearchUtils.getSearchType(searchResults?.search);
Expand Down
62 changes: 62 additions & 0 deletions src/components/SelectionList/Search/ActionCell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';
import {View} from 'react-native';
import Badge from '@components/Badge';
import Button from '@components/Button';
import * as Expensicons from '@components/Icon/Expensicons';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';

type ActionCellProps = {
onButtonPress: () => void;
action?: string;
isLargeScreenWidth?: boolean;
};

function ActionCell({onButtonPress, action = CONST.SEARCH.ACTION_TYPES.VIEW, isLargeScreenWidth = true}: ActionCellProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const theme = useTheme();
const StyleUtils = useStyleUtils();

if (action === CONST.SEARCH.ACTION_TYPES.PAID || action === CONST.SEARCH.ACTION_TYPES.DONE) {
const buttonTextKey = action === CONST.SEARCH.ACTION_TYPES.PAID ? 'iou.settledExpensify' : 'common.done';
return (
<View style={[StyleUtils.getHeight(variables.h28), styles.justifyContentCenter]}>
<Badge
text={translate(buttonTextKey)}
icon={Expensicons.Checkmark}
badgeStyles={[
styles.ml0,
styles.ph2,
styles.gap1,
isLargeScreenWidth ? styles.alignSelfCenter : styles.alignSelfEnd,
StyleUtils.getBorderColorStyle(theme.border),
StyleUtils.getHeight(variables.h20),
StyleUtils.getMinimumHeight(variables.h20),
]}
textStyles={StyleUtils.getFontSizeStyle(variables.fontSizeExtraSmall)}
iconStyles={styles.mr0}
success
/>
</View>
);
}

return (
<Button
text={translate('common.view')}
onPress={onButtonPress}
small
pressOnEnter
style={[styles.w100]}
/>
);
}

ActionCell.displayName = 'ActionCell';

export default ActionCell;
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import React, {memo} from 'react';
import {View} from 'react-native';
import Button from '@components/Button';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import type {SearchAccountDetails} from '@src/types/onyx/SearchResults';
import ActionCell from './ActionCell';
import UserInfoCell from './UserInfoCell';

type ExpenseItemHeaderNarrowProps = {
participantFrom: SearchAccountDetails;
participantTo: SearchAccountDetails;
participantFromDisplayName: string;
participantToDisplayName: string;
buttonText: string;
onButtonPress: () => void;
action?: string;
};

function ExpenseItemHeaderNarrow({participantFrom, participantFromDisplayName, participantTo, participantToDisplayName, buttonText, onButtonPress}: ExpenseItemHeaderNarrowProps) {
function ExpenseItemHeaderNarrow({participantFrom, participantFromDisplayName, participantTo, participantToDisplayName, onButtonPress, action}: ExpenseItemHeaderNarrowProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const theme = useTheme();
Expand Down Expand Up @@ -47,12 +47,10 @@ function ExpenseItemHeaderNarrow({participantFrom, participantFromDisplayName, p
</View>
</View>
<View style={[StyleUtils.getWidthStyle(variables.w80)]}>
<Button
text={buttonText}
onPress={onButtonPress}
small
pressOnEnter
style={[styles.p0]}
<ActionCell
onButtonPress={onButtonPress}
action={action}
isLargeScreenWidth={false}
/>
</View>
</View>
Expand Down
31 changes: 6 additions & 25 deletions src/components/SelectionList/Search/ReportListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {View} from 'react-native';
import Button from '@components/Button';
import BaseListItem from '@components/SelectionList/BaseListItem';
import type {ListItem, ReportListItemProps, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
import Text from '@components/Text';
Expand All @@ -14,6 +13,7 @@ import Navigation from '@libs/Navigation/Navigation';
import {getSearchParams} from '@libs/SearchUtils';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import ActionCell from './ActionCell';
import ExpenseItemHeaderNarrow from './ExpenseItemHeaderNarrow';
import TransactionListItem from './TransactionListItem';
import TransactionListItemRow from './TransactionListItemRow';
Expand All @@ -29,10 +29,6 @@ type ReportCellProps = {
reportItem: ReportListItemType;
} & CellProps;

type ActionCellProps = {
onButtonPress: () => void;
} & CellProps;

function TotalCell({showTooltip, isLargeScreenWidth, reportItem}: ReportCellProps) {
const styles = useThemeStyles();

Expand All @@ -45,21 +41,6 @@ function TotalCell({showTooltip, isLargeScreenWidth, reportItem}: ReportCellProp
);
}

function ActionCell({onButtonPress}: ActionCellProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();

return (
<Button
text={translate('common.view')}
onPress={onButtonPress}
small
pressOnEnter
style={[styles.w100]}
/>
);
}

function ReportListItem<TItem extends ListItem>({
item,
isFocused,
Expand Down Expand Up @@ -90,7 +71,7 @@ function ReportListItem<TItem extends ListItem>({

const openReportInRHP = (transactionItem: TransactionListItemType) => {
const searchParams = getSearchParams();
const currentQuery = searchParams?.query ?? CONST.TAB_SEARCH.ALL;
const currentQuery = searchParams?.query ?? CONST.SEARCH.TAB.ALL;
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute(currentQuery, transactionItem.transactionThreadReportID));
};

Expand Down Expand Up @@ -150,7 +131,7 @@ function ReportListItem<TItem extends ListItem>({
participantFromDisplayName={participantFromDisplayName}
participantTo={participantTo}
participantToDisplayName={participantToDisplayName}
buttonText={translate('common.view')}
action={reportItem.action}
onButtonPress={handleOnButtonPress}
/>
)}
Expand All @@ -173,12 +154,12 @@ function ReportListItem<TItem extends ListItem>({
{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)}>
<View style={StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TYPE)} />
<View style={StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.ACTION)}>
<ActionCell
showTooltip={showTooltip}
isLargeScreenWidth={isLargeScreenWidth}
onButtonPress={handleOnButtonPress}
action={reportItem.action}
/>
</View>
</>
Expand Down
Loading
Loading