From 3442ae805745530ecd2819c3581973c98bcb2fe5 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 26 Jun 2024 09:14:27 -0600 Subject: [PATCH 1/2] fix description sort --- src/libs/SearchUtils.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 6e6a541ccdff..a1238f5aca8b 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -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]: null, + [CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: 'comment.comment' as const, [CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: null, [CONST.SEARCH.TABLE_COLUMNS.RECEIPT]: null, }; @@ -242,6 +242,10 @@ 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; @@ -254,8 +258,8 @@ function getSortedTransactionData(data: TransactionListItemType[], sortBy?: Sear } return data.sort((a, b) => { - const aValue = a[sortingProperty]; - const bValue = b[sortingProperty]; + const aValue = getNestedValue(a, sortingProperty); + const bValue = getNestedValue(b, sortingProperty); if (aValue === undefined || bValue === undefined) { return 0; From 4041963dbdd093369745b796eadd763201c7c092 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 26 Jun 2024 11:39:05 -0600 Subject: [PATCH 2/2] use simple solution --- src/libs/SearchUtils.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index a1238f5aca8b..460a686766a7 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -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, }; @@ -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; @@ -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;