Skip to content
Merged
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 @@ -6696,6 +6696,8 @@ const CONST = {
TO: this.TABLE_COLUMNS.TO,
CATEGORY: this.TABLE_COLUMNS.CATEGORY,
TAG: this.TABLE_COLUMNS.TAG,
REIMBURSABLE: this.TABLE_COLUMNS.REIMBURSABLE,
BILLABLE: this.TABLE_COLUMNS.BILLABLE,
STATUS: this.TABLE_COLUMNS.STATUS,
ACTION: this.TABLE_COLUMNS.ACTION,
},
Expand Down Expand Up @@ -6789,6 +6791,8 @@ const CONST = {
TO: 'to',
CATEGORY: 'category',
TAG: 'tag',
REIMBURSABLE: 'reimbursable',
BILLABLE: 'billable',
TOTAL_AMOUNT: 'amount',
TOTAL: 'total',
TYPE: 'type',
Expand Down
10 changes: 10 additions & 0 deletions src/components/SelectionListWithSections/SearchTableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ const getExpenseHeaders = (groupBy?: SearchGroupBy): SearchColumnConfig[] => [
translationKey: 'common.tag',
canBeMissing: true,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE,
translationKey: 'common.reimbursable',
canBeMissing: true,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.BILLABLE,
translationKey: 'common.billable',
canBeMissing: true,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.WITHDRAWAL_ID,
translationKey: 'common.withdrawalID',
Expand Down
17 changes: 17 additions & 0 deletions src/components/TransactionItemRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,22 @@ function TransactionItemRow({
/>
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE}
style={[StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE)]}
>
<Text>{transactionItem.reimbursable ? translate('common.yes') : translate('common.no')}</Text>
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.BILLABLE]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.BILLABLE}
style={[StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.BILLABLE)]}
>
<Text>{transactionItem.billable ? translate('common.yes') : translate('common.no')}</Text>
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.ACTION]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.ACTION}
Expand Down Expand Up @@ -433,6 +449,7 @@ function TransactionItemRow({
),
}),
[
translate,
StyleUtils,
createdAt,
report?.submitted,
Expand Down
47 changes: 44 additions & 3 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ const transactionColumnNamesToSortingProperty: TransactionSorting = {
[CONST.SEARCH.TABLE_COLUMNS.MERCHANT]: 'formattedMerchant' as const,
[CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT]: 'formattedTotal' as const,
[CONST.SEARCH.TABLE_COLUMNS.CATEGORY]: 'category' as const,
[CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE]: 'reimbursable' as const,
[CONST.SEARCH.TABLE_COLUMNS.BILLABLE]: 'billable' as const,
[CONST.SEARCH.TABLE_COLUMNS.TYPE]: null,
[CONST.SEARCH.TABLE_COLUMNS.ACTION]: 'action' as const,
[CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: 'comment' as const,
Expand Down Expand Up @@ -2005,6 +2007,24 @@ function compareValues(a: unknown, b: unknown, sortOrder: SortOrder, sortBy: str
return 0;
}

/**
* @private
* Gets the value to use for sorting a transaction by a given property.
* Handles special cases like comments and boolean fields (reimbursable, billable).
*/
function getTransactionSortValue(transaction: TransactionListItemType, sortingProperty: string): unknown {
if (sortingProperty === 'comment') {
return transaction.comment?.comment;
}

if (sortingProperty === 'reimbursable' || sortingProperty === 'billable') {
const boolValue = transaction[sortingProperty as keyof TransactionListItemType];
return boolValue ? CONST.SEARCH.BOOLEAN.YES : CONST.SEARCH.BOOLEAN.NO;
}

return transaction[sortingProperty as keyof TransactionListItemType];
}

/**
* @private
* Sorts transaction sections based on a specified column and sort order.
Expand Down Expand Up @@ -2042,10 +2062,23 @@ function getSortedTransactionData(
}

return data.sort((a, b) => {
const aValue = sortingProperty === 'comment' ? a.comment?.comment : a[sortingProperty as keyof TransactionListItemType];
const bValue = sortingProperty === 'comment' ? b.comment?.comment : b[sortingProperty as keyof TransactionListItemType];
const aValue = getTransactionSortValue(a, sortingProperty);
const bValue = getTransactionSortValue(b, sortingProperty);

return compareValues(aValue, bValue, sortOrder, sortingProperty, localeCompare);
const primaryComparison = compareValues(aValue, bValue, sortOrder, sortingProperty, localeCompare);

if (primaryComparison !== 0) {
return primaryComparison;
}

// If we have a tie in the primary comparison, we add a tie breaker on date and/or transactionID as a last resort to make the sort deterministic
const createdComparison = compareValues(a.created, b.created, sortOrder, 'created', localeCompare);

if (createdComparison !== 0) {
return createdComparison;
}

return compareValues(a.transactionID, b.transactionID, sortOrder, 'transactionID', localeCompare);
});
}

Expand Down Expand Up @@ -2246,6 +2279,10 @@ function getSearchColumnTranslationKey(columnId: SearchCustomColumnIds): Transla
return 'common.receipt';
case CONST.SEARCH.TABLE_COLUMNS.TAG:
return 'common.tag';
case CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE:
return 'common.reimbursable';
case CONST.SEARCH.TABLE_COLUMNS.BILLABLE:
return 'common.billable';
case CONST.SEARCH.TABLE_COLUMNS.ACTION:
return 'common.action';
case CONST.SEARCH.TABLE_COLUMNS.TITLE:
Expand Down Expand Up @@ -2711,6 +2748,8 @@ function getColumnsToShow(
[CONST.SEARCH.TABLE_COLUMNS.TO]: false,
[CONST.SEARCH.TABLE_COLUMNS.CATEGORY]: false,
[CONST.SEARCH.TABLE_COLUMNS.TAG]: false,
[CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE]: false,
[CONST.SEARCH.TABLE_COLUMNS.BILLABLE]: false,
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: false,
[CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT]: true,
[CONST.SEARCH.TABLE_COLUMNS.STATUS]: false,
Expand Down Expand Up @@ -2920,6 +2959,8 @@ function getTableMinWidth(columns: SearchColumnType[]) {
minWidth += 72;
} else if (column === CONST.SEARCH.TABLE_COLUMNS.TYPE) {
minWidth += 20;
} else if (column === CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE || column === CONST.SEARCH.TABLE_COLUMNS.BILLABLE) {
minWidth += 92;
} else {
minWidth += 200;
}
Expand Down
4 changes: 4 additions & 0 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,10 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
case CONST.SEARCH.TABLE_COLUMNS.TYPE:
columnWidth = {...getWidthStyle(variables.w20), ...styles.alignItemsCenter};
break;
case CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE:
case CONST.SEARCH.TABLE_COLUMNS.BILLABLE:
columnWidth = {...getWidthStyle(variables.w92)};
break;
case CONST.SEARCH.TABLE_COLUMNS.ACTION:
columnWidth = {...getWidthStyle(variables.w80), ...styles.alignItemsCenter};
break;
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/SearchResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ type SearchTransaction = {
/** The group currency if the transaction is grouped. Defaults to the active policy currency if group has no target currency */
groupCurrency?: string;

/** Reimbursable status of the transaction */
reimbursable?: boolean;

/** Billable status of the transaction */
billable?: boolean;

/** The card transaction's posted date */
posted?: string;
};
Expand Down
Loading