Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ const CONST = {
RECEIPT: 'receipt',
DATE: 'date',
MERCHANT: 'merchant',
DESCRIPTION: 'description',
FROM: 'from',
TO: 'to',
CATEGORY: 'category',
Expand Down Expand Up @@ -6487,6 +6488,9 @@ const CONST = {
UNAPPROVED_CASH: 'unapprovedCash',
UNAPPROVED_CARD: 'unapprovedCard',
},
ANIMATION: {
FADE_DURATION: 200,
},
},

EXPENSE: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@ type ColumnConfig = {
isColumnSortable?: boolean;
};

const shouldShowColumnConfig: Record<SortableColumnName, (isIOUReport: boolean) => boolean> = {
[CONST.SEARCH.TABLE_COLUMNS.RECEIPT]: () => true,
[CONST.SEARCH.TABLE_COLUMNS.TYPE]: () => true,
[CONST.SEARCH.TABLE_COLUMNS.DATE]: () => true,
[CONST.SEARCH.TABLE_COLUMNS.MERCHANT]: () => true,
[CONST.SEARCH.TABLE_COLUMNS.CATEGORY]: (isIOUReport) => !isIOUReport,
[CONST.SEARCH.TABLE_COLUMNS.TAG]: (isIOUReport) => !isIOUReport,
[CONST.REPORT.TRANSACTION_LIST.COLUMNS.COMMENTS]: () => true,
[CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT]: () => true,
[CONST.SEARCH.TABLE_COLUMNS.IN]: () => false,
[CONST.SEARCH.TABLE_COLUMNS.FROM]: () => false,
[CONST.SEARCH.TABLE_COLUMNS.TO]: () => false,
[CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: () => false,
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: () => false,
[CONST.SEARCH.TABLE_COLUMNS.ACTION]: () => false,
[CONST.SEARCH.TABLE_COLUMNS.TITLE]: () => false,
[CONST.SEARCH.TABLE_COLUMNS.ASSIGNEE]: () => false,
};

const columnConfig: ColumnConfig[] = [
{
columnName: CONST.SEARCH.TABLE_COLUMNS.RECEIPT,
Expand All @@ -51,6 +32,10 @@ const columnConfig: ColumnConfig[] = [
columnName: CONST.SEARCH.TABLE_COLUMNS.MERCHANT,
translationKey: 'common.merchant',
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION,
translationKey: 'common.description',
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.CATEGORY,
translationKey: 'common.category',
Expand Down Expand Up @@ -78,22 +63,19 @@ type SearchTableHeaderProps = {
amountColumnSize: TableColumnSize;
taxAmountColumnSize: TableColumnSize;
shouldShowSorting: boolean;
isIOUReport: boolean;
columns: SortableColumnName[];
};

function MoneyRequestReportTableHeader({sortBy, sortOrder, onSortPress, dateColumnSize, shouldShowSorting, isIOUReport, amountColumnSize, taxAmountColumnSize}: SearchTableHeaderProps) {
function MoneyRequestReportTableHeader({sortBy, sortOrder, onSortPress, dateColumnSize, shouldShowSorting, amountColumnSize, taxAmountColumnSize, columns}: SearchTableHeaderProps) {
const styles = useThemeStyles();

const shouldShowColumn = useCallback(
(columnName: SortableColumnName) => {
const shouldShowFun = shouldShowColumnConfig[columnName];
if (!shouldShowFun) {
return false;
}
return shouldShowFun(isIOUReport);
return columns.includes(columnName);
},
[isIOUReport],
[columns],
);

return (
<View style={[styles.dFlex, styles.flex5]}>
<SortableTableHeader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, {useEffect, useRef} from 'react';
import type {View} from 'react-native';
import type {ValueOf} from 'type-fest';
import {getButtonRole} from '@components/Button/utils';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {PressableWithFeedback} from '@components/Pressable';
import type {TableColumnSize} from '@components/Search/types';
import type {SortableColumnName} from '@components/SelectionList/types';
import TransactionItemRow from '@components/TransactionItemRow';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -18,17 +20,6 @@ import CONST from '@src/CONST';
import type {Report} from '@src/types/onyx';
import type {TransactionWithOptionalHighlight} from './MoneyRequestReportTransactionList';

const allReportColumns = [
CONST.REPORT.TRANSACTION_LIST.COLUMNS.RECEIPT,
CONST.REPORT.TRANSACTION_LIST.COLUMNS.TYPE,
CONST.REPORT.TRANSACTION_LIST.COLUMNS.DATE,
CONST.REPORT.TRANSACTION_LIST.COLUMNS.MERCHANT,
CONST.REPORT.TRANSACTION_LIST.COLUMNS.CATEGORY,
CONST.REPORT.TRANSACTION_LIST.COLUMNS.TAG,
CONST.REPORT.TRANSACTION_LIST.COLUMNS.COMMENTS,
CONST.REPORT.TRANSACTION_LIST.COLUMNS.TOTAL_AMOUNT,
];

type MoneyRequestReportTransactionItemProps = {
/** The transaction that is being displayed */
transaction: TransactionWithOptionalHighlight;
Expand Down Expand Up @@ -60,12 +51,16 @@ type MoneyRequestReportTransactionItemProps = {
/** The size of the tax amount column */
taxAmountColumnSize: TableColumnSize;

/** Columns to show */
columns: SortableColumnName[];

/** Callback function that scrolls to this transaction in case it is newly added */
scrollToNewTransaction?: (offset: number) => void;
};

function MoneyRequestReportTransactionItem({
transaction,
columns,
report,
isSelectionModeEnabled,
toggleTransaction,
Expand Down Expand Up @@ -138,7 +133,7 @@ function MoneyRequestReportTransactionItem({
shouldUseNarrowLayout={shouldUseNarrowLayout || isMediumScreenWidth}
shouldShowCheckbox={!!isSelectionModeEnabled || !isSmallScreenWidth}
onCheckboxPress={toggleTransaction}
columns={allReportColumns}
columns={columns as Array<ValueOf<typeof CONST.REPORT.TRANSACTION_LIST.COLUMNS>>}
isDisabled={isPendingDelete}
/>
</PressableWithFeedback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {convertToDisplayString} from '@libs/CurrencyUtils';
import {getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils';
import {navigationRef} from '@libs/Navigation/Navigation';
import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils';
import {getMoneyRequestSpendBreakdown, isIOUReport} from '@libs/ReportUtils';
import {compareValues, isTransactionAmountTooLong, isTransactionTaxAmountTooLong} from '@libs/SearchUIUtils';
import {getMoneyRequestSpendBreakdown} from '@libs/ReportUtils';
import {compareValues, getColumnsToShow, isTransactionAmountTooLong, isTransactionTaxAmountTooLong} from '@libs/SearchUIUtils';
import {getTransactionPendingAction, isTransactionPendingDelete} from '@libs/TransactionUtils';
import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear';
import Navigation from '@navigation/Navigation';
Expand Down Expand Up @@ -160,6 +160,11 @@ function MoneyRequestReportTransactionList({
}));
}, [newTransactions, sortBy, sortOrder, transactions, localeCompare]);

const columnsToShow = useMemo(() => {
const columns = getColumnsToShow(transactions, true);
return (Object.keys(columns) as SortableColumnName[]).filter((column) => columns[column]);
}, [transactions]);

const navigateToTransaction = useCallback(
(activeTransactionID: string) => {
const iouAction = getIOUActionForTransactionID(reportActions, activeTransactionID);
Expand Down Expand Up @@ -262,6 +267,7 @@ function MoneyRequestReportTransactionList({
shouldShowSorting
sortBy={sortBy}
sortOrder={sortOrder}
columns={columnsToShow}
dateColumnSize={dateColumnSize}
amountColumnSize={amountColumnSize}
taxAmountColumnSize={taxAmountColumnSize}
Expand All @@ -272,7 +278,6 @@ function MoneyRequestReportTransactionList({

setSortConfig((prevState) => ({...prevState, sortBy: selectedSortBy, sortOrder: selectedSortOrder}));
}}
isIOUReport={isIOUReport(report)}
/>
)}
</View>
Expand All @@ -283,6 +288,7 @@ function MoneyRequestReportTransactionList({
<MoneyRequestReportTransactionItem
key={transaction.transactionID}
transaction={transaction}
columns={columnsToShow}
report={report}
isSelectionModeEnabled={isMobileSelectionModeEnabled}
toggleTransaction={toggleTransaction}
Expand Down
17 changes: 15 additions & 2 deletions src/components/Search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import type ChatListItem from '@components/SelectionList/ChatListItem';
import type TaskListItem from '@components/SelectionList/Search/TaskListItem';
import type TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem';
import type TransactionListItem from '@components/SelectionList/Search/TransactionListItem';
import type {ExtendedTargetedEvent, ReportActionListItemType, TaskListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types';
import type {
ExtendedTargetedEvent,
ReportActionListItemType,
SortableColumnName,
TaskListItemType,
TransactionGroupListItemType,
TransactionListItemType,
} from '@components/SelectionList/types';
import Text from '@components/Text';
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import useInitialWindowDimensions from '@hooks/useInitialWindowDimensions';
Expand Down Expand Up @@ -80,6 +87,9 @@ type SearchListProps = Pick<FlashListProps<SearchListItem>, 'onScroll' | 'conten
/** The search query */
queryJSON: SearchQueryJSON;

/** Columns to show */
columns: SortableColumnName[];

/** Called when the viewability of rows changes, as defined by the viewabilityConfig prop. */
onViewableItemsChanged?: (info: {changed: ViewToken[]; viewableItems: ViewToken[]}) => void;

Expand Down Expand Up @@ -124,6 +134,7 @@ function SearchList(
shouldPreventDefaultFocusOnSelectRow,
shouldPreventLongPressRow,
queryJSON,
columns,
onViewableItemsChanged,
onLayout,
estimatedItemSize = ITEM_HEIGHTS.NARROW_WITHOUT_DRAWER.STANDARD,
Expand Down Expand Up @@ -339,6 +350,7 @@ function SearchList(
}}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
queryJSONHash={hash}
columns={columns}
policies={policies}
isDisabled={isDisabled}
allReports={allReports}
Expand All @@ -359,6 +371,7 @@ function SearchList(
onCheckboxPress,
onSelectRow,
policies,
columns,
hash,
groupBy,
setFocusedIndex,
Expand Down Expand Up @@ -460,7 +473,7 @@ function SearchList(
onScroll={onScroll}
showsVerticalScrollIndicator={false}
ref={listRef}
extraData={[focusedIndex, isFocused]}
extraData={[focusedIndex, isFocused, columns]}
onEndReached={onEndReached}
onEndReachedThreshold={onEndReachedThreshold}
ListFooterComponent={ListFooterComponent}
Expand Down
Loading
Loading