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
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6695,6 +6695,7 @@ const CONST = {
TO: this.TABLE_COLUMNS.TO,
CATEGORY: this.TABLE_COLUMNS.CATEGORY,
TAG: this.TABLE_COLUMNS.TAG,
STATUS: this.TABLE_COLUMNS.STATUS,
ACTION: this.TABLE_COLUMNS.ACTION,
},
EXPENSE_REPORT: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
const [lastSearchQuery] = useOnyx(ONYXKEYS.REPORT_NAVIGATION_LAST_SEARCH_QUERY, {canBeMissing: true});
const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${lastSearchQuery?.queryJSON?.hash}`, {canBeMissing: true});
const currentUserDetails = useCurrentUserPersonalDetails();
const {localeCompare, formatPhoneNumber} = useLocalize();
const {localeCompare, formatPhoneNumber, translate} = useLocalize();
const [isActionLoadingSet = new Set<string>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}`, {canBeMissing: true, selector: isActionLoadingSetSelector});

const [exportReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {
Expand All @@ -51,7 +51,7 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
archivedReportsIDList: archivedReportsIdSet,
isActionLoadingSet,
});
results = getSortedSections(type, status ?? '', searchData, localeCompare, sortBy, sortOrder, groupBy).map((value) => value.reportID);
results = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
}
const allReports = results;

Expand Down
4 changes: 2 additions & 2 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ function Search({

const sortedSelectedData = useMemo(
() =>
getSortedSections(type, status, filteredData, localeCompare, sortBy, sortOrder, validGroupBy).map((item) => {
getSortedSections(type, status, filteredData, localeCompare, translate, sortBy, sortOrder, validGroupBy).map((item) => {
const baseKey = isChat
? `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${(item as ReportActionListItemType).reportActionID}`
: `${ONYXKEYS.COLLECTION.TRANSACTION}${(item as TransactionListItemType).transactionID}`;
Expand All @@ -884,7 +884,7 @@ function Search({

return mapToItemWithAdditionalInfo(item, selectedTransactions, canSelectMultiple, shouldAnimateInHighlight, hash);
}),
[type, status, filteredData, sortBy, sortOrder, validGroupBy, isChat, newSearchResultKeys, selectedTransactions, canSelectMultiple, localeCompare, hash],
[type, status, filteredData, localeCompare, translate, sortBy, sortOrder, validGroupBy, isChat, newSearchResultKeys, selectedTransactions, canSelectMultiple, hash],
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ const getExpenseHeaders = (groupBy?: SearchGroupBy): SearchColumnConfig[] => [
columnName: CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT,
translationKey: groupBy ? 'common.total' : 'iou.amount',
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.STATUS,
translationKey: 'common.status',
canBeMissing: false,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.ACTION,
translationKey: 'common.action',
Expand Down
9 changes: 9 additions & 0 deletions src/components/TransactionItemRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import RadioButton from '@components/RadioButton';
import type {SearchColumnType, TableColumnSize} from '@components/Search/types';
import ActionCell from '@components/SelectionListWithSections/Search/ActionCell';
import DateCell from '@components/SelectionListWithSections/Search/DateCell';
import StatusCell from '@components/SelectionListWithSections/Search/StatusCell';
import UserInfoCell from '@components/SelectionListWithSections/Search/UserInfoCell';
import Text from '@components/Text';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
Expand Down Expand Up @@ -407,6 +408,14 @@ function TransactionItemRow({
/>
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.STATUS]: (
<View style={[StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.STATUS)]}>
<StatusCell
stateNum={transactionItem.report?.stateNum}
statusNum={transactionItem.report?.statusNum}
/>
</View>
),
}),
[
StyleUtils,
Expand Down
39 changes: 34 additions & 5 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,7 @@ function getSortedSections(
status: SearchStatus,
data: ListItemDataType<typeof type, typeof status>,
localeCompare: LocaleContextProps['localeCompare'],
translate: LocaleContextProps['translate'],
sortBy?: SearchColumnType,
sortOrder?: SortOrder,
groupBy?: SearchGroupBy,
Expand All @@ -1928,7 +1929,7 @@ function getSortedSections(
return getSortedTaskData(data as TaskListItemType[], localeCompare, sortBy, sortOrder);
}
if (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) {
return getSortedReportData(data as TransactionReportGroupListItemType[], localeCompare, sortBy, sortOrder);
return getSortedReportData(data as TransactionReportGroupListItemType[], localeCompare, translate, sortBy, sortOrder);
}

if (groupBy) {
Expand All @@ -1944,7 +1945,7 @@ function getSortedSections(
}
}

return getSortedTransactionData(data as TransactionListItemType[], localeCompare, sortBy, sortOrder);
return getSortedTransactionData(data as TransactionListItemType[], localeCompare, translate, sortBy, sortOrder);
}

/**
Expand Down Expand Up @@ -1985,13 +1986,34 @@ function compareValues(a: unknown, b: unknown, sortOrder: SortOrder, sortBy: str
* @private
* Sorts transaction sections based on a specified column and sort order.
*/
function getSortedTransactionData(data: TransactionListItemType[], localeCompare: LocaleContextProps['localeCompare'], sortBy?: SearchColumnType, sortOrder?: SortOrder) {
function getSortedTransactionData(
data: TransactionListItemType[],
localeCompare: LocaleContextProps['localeCompare'],
translate: LocaleContextProps['translate'],
sortBy?: SearchColumnType,
sortOrder?: SortOrder,
) {
if (!sortBy || !sortOrder) {
return data;
}

const sortingProperty = transactionColumnNamesToSortingProperty[sortBy];

if (sortBy === CONST.SEARCH.TABLE_COLUMNS.STATUS) {
return data.sort((a, b) => {
const aReport = a.report;
const bReport = b.report;

if (!aReport || !bReport) {
return 0;
}

const aValue = getReportStatusTranslation({stateNum: aReport.stateNum, statusNum: aReport.statusNum, translate});
const bValue = getReportStatusTranslation({stateNum: bReport.stateNum, statusNum: bReport.statusNum, translate});
return compareValues(aValue, bValue, sortOrder, sortBy, localeCompare);
});
}

if (!sortingProperty) {
return data;
}
Expand Down Expand Up @@ -2027,9 +2049,15 @@ function getSortedTaskData(data: TaskListItemType[], localeCompare: LocaleContex
* @private
* Sorts report sections based on a specified column and sort order.
*/
function getSortedReportData(data: TransactionReportGroupListItemType[], localeCompare: LocaleContextProps['localeCompare'], sortBy?: SearchColumnType, sortOrder?: SortOrder) {
function getSortedReportData(
data: TransactionReportGroupListItemType[],
localeCompare: LocaleContextProps['localeCompare'],
translate: LocaleContextProps['translate'],
sortBy?: SearchColumnType,
sortOrder?: SortOrder,
) {
for (const report of data) {
report.transactions = getSortedTransactionData(report.transactions, localeCompare, CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.SORT_ORDER.DESC);
report.transactions = getSortedTransactionData(report.transactions, localeCompare, translate, CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.SORT_ORDER.DESC);
}

if (!sortBy || !sortOrder) {
Expand Down Expand Up @@ -2659,6 +2687,7 @@ function getColumnsToShow(
[CONST.SEARCH.TABLE_COLUMNS.TAG]: false,
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: false,
[CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT]: true,
[CONST.SEARCH.TABLE_COLUMNS.STATUS]: false,
[CONST.SEARCH.TABLE_COLUMNS.ACTION]: true,
[CONST.SEARCH.TABLE_COLUMNS.TITLE]: true,
};
Expand Down
27 changes: 20 additions & 7 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type * as OnyxTypes from '@src/types/onyx';
import type {Connections} from '@src/types/onyx/Policy';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
import getOnyxValue from '../../utils/getOnyxValue';
import {formatPhoneNumber, localeCompare} from '../../utils/TestHelper';
import {formatPhoneNumber, localeCompare, translateLocal} from '../../utils/TestHelper';
import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates';

jest.mock('@src/components/ConfirmedRoute.tsx');
Expand Down Expand Up @@ -2022,6 +2022,7 @@ describe('SearchUIUtils', () => {
CONST.SEARCH.STATUS.EXPENSE.ALL,
reportActionListItems,
localeCompare,
translateLocal,
) as ReportActionListItemType[];
// Should return all report actions sorted by creation date in descending order (newest first)
expect(sortedActions).toHaveLength(5);
Expand All @@ -2030,36 +2031,47 @@ describe('SearchUIUtils', () => {
});

it('should return getSortedTransactionData result when groupBy is undefined', () => {
expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, '', transactionsListItems, localeCompare, 'date', 'asc', undefined)).toStrictEqual(transactionsListItems);
expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, '', transactionsListItems, localeCompare, translateLocal, 'date', 'asc', undefined)).toStrictEqual(
transactionsListItems,
);
});

it('should return getSortedReportData result when type is expense-report', () => {
expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT, '', transactionReportGroupListItems, localeCompare, 'date', 'asc')).toStrictEqual(
expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT, '', transactionReportGroupListItems, localeCompare, translateLocal, 'date', 'asc')).toStrictEqual(
transactionReportGroupListItems,
);
});

it('should return getSortedReportData result when type is TRIP and groupBy is report', () => {
expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.TRIP, '', transactionReportGroupListItems, localeCompare, 'date', 'asc')).toStrictEqual(
expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.TRIP, '', transactionReportGroupListItems, localeCompare, translateLocal, 'date', 'asc')).toStrictEqual(
transactionReportGroupListItems,
);
});

it('should return getSortedReportData result when type is INVOICE and groupBy is report', () => {
expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.INVOICE, '', transactionReportGroupListItems, localeCompare, 'date', 'asc')).toStrictEqual(
expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.INVOICE, '', transactionReportGroupListItems, localeCompare, translateLocal, 'date', 'asc')).toStrictEqual(
transactionReportGroupListItems,
);
});

it('should return getSortedMemberData result when type is EXPENSE and groupBy is member', () => {
expect(
SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, '', transactionMemberGroupListItems, localeCompare, 'date', 'asc', CONST.SEARCH.GROUP_BY.FROM),
SearchUIUtils.getSortedSections(
CONST.SEARCH.DATA_TYPES.EXPENSE,
'',
transactionMemberGroupListItems,
localeCompare,
translateLocal,
'date',
'asc',
CONST.SEARCH.GROUP_BY.FROM,
),
).toStrictEqual(transactionMemberGroupListItemsSorted);
});

it('should return getSortedCardData result when type is EXPENSE and groupBy is card', () => {
expect(
SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, '', transactionCardGroupListItems, localeCompare, 'date', 'asc', CONST.SEARCH.GROUP_BY.CARD),
SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, '', transactionCardGroupListItems, localeCompare, translateLocal, 'date', 'asc', CONST.SEARCH.GROUP_BY.CARD),
).toStrictEqual(transactionCardGroupListItemsSorted);
});

Expand All @@ -2070,6 +2082,7 @@ describe('SearchUIUtils', () => {
'',
transactionWithdrawalIDGroupListItems,
localeCompare,
translateLocal,
'date',
'asc',
CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID,
Expand Down
Loading