Skip to content

Commit 4041963

Browse files
committed
use simple solution
1 parent 3442ae8 commit 4041963

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/libs/SearchUtils.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const columnNamesToSortingProperty = {
2626
[CONST.SEARCH.TABLE_COLUMNS.CATEGORY]: 'category' as const,
2727
[CONST.SEARCH.TABLE_COLUMNS.TYPE]: 'type' as const,
2828
[CONST.SEARCH.TABLE_COLUMNS.ACTION]: 'action' as const,
29-
[CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: 'comment.comment' as const,
29+
[CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: 'comment' as const,
3030
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: null,
3131
[CONST.SEARCH.TABLE_COLUMNS.RECEIPT]: null,
3232
};
@@ -242,10 +242,6 @@ function getQueryHash(query: string, policyID?: string, sortBy?: string, sortOrd
242242
return UserUtils.hashText(textToHash, 2 ** 32);
243243
}
244244

245-
const getNestedValue = (obj: any, path: string) => {
246-
return path.split('.').reduce((acc, part) => acc && acc[part], obj);
247-
};
248-
249245
function getSortedTransactionData(data: TransactionListItemType[], sortBy?: SearchColumnType, sortOrder?: SortOrder) {
250246
if (!sortBy || !sortOrder) {
251247
return data;
@@ -258,8 +254,8 @@ function getSortedTransactionData(data: TransactionListItemType[], sortBy?: Sear
258254
}
259255

260256
return data.sort((a, b) => {
261-
const aValue = getNestedValue(a, sortingProperty);
262-
const bValue = getNestedValue(b, sortingProperty);
257+
const aValue = sortingProperty === 'comment' ? a.comment.comment : a[sortingProperty];
258+
const bValue = sortingProperty === 'comment' ? b.comment.comment : b[sortingProperty];
263259

264260
if (aValue === undefined || bValue === undefined) {
265261
return 0;

0 commit comments

Comments
 (0)