Skip to content

Commit

Permalink
use simple solution
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Jun 26, 2024
1 parent 3442ae8 commit 4041963
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const columnNamesToSortingProperty = {
[CONST.SEARCH.TABLE_COLUMNS.CATEGORY]: 'category' as const,
[CONST.SEARCH.TABLE_COLUMNS.TYPE]: 'type' as const,
[CONST.SEARCH.TABLE_COLUMNS.ACTION]: 'action' as const,
[CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: 'comment.comment' as const,
[CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: 'comment' as const,
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: null,
[CONST.SEARCH.TABLE_COLUMNS.RECEIPT]: null,
};
Expand Down Expand Up @@ -242,10 +242,6 @@ function getQueryHash(query: string, policyID?: string, sortBy?: string, sortOrd
return UserUtils.hashText(textToHash, 2 ** 32);
}

const getNestedValue = (obj: any, path: string) => {
return path.split('.').reduce((acc, part) => acc && acc[part], obj);
};

function getSortedTransactionData(data: TransactionListItemType[], sortBy?: SearchColumnType, sortOrder?: SortOrder) {
if (!sortBy || !sortOrder) {
return data;
Expand All @@ -258,8 +254,8 @@ function getSortedTransactionData(data: TransactionListItemType[], sortBy?: Sear
}

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

if (aValue === undefined || bValue === undefined) {
return 0;
Expand Down

0 comments on commit 4041963

Please sign in to comment.