Skip to content

Commit

Permalink
fix description sort
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Jun 26, 2024
1 parent 060160e commit 3442ae8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 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]: null,
[CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: 'comment.comment' as const,
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: null,
[CONST.SEARCH.TABLE_COLUMNS.RECEIPT]: null,
};
Expand Down Expand Up @@ -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) => {

Check failure on line 245 in src/libs/SearchUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected any. Specify a different type

Check failure on line 245 in src/libs/SearchUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return path.split('.').reduce((acc, part) => acc && acc[part], obj);

Check failure on line 246 in src/libs/SearchUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe return of an `any` typed value

Check failure on line 246 in src/libs/SearchUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer using an optional chain expression instead, as it's more concise and easier to read

Check failure on line 246 in src/libs/SearchUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe return of an `any` typed value

Check failure on line 246 in src/libs/SearchUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe member access [part] on an `any` value
};

function getSortedTransactionData(data: TransactionListItemType[], sortBy?: SearchColumnType, sortOrder?: SortOrder) {
if (!sortBy || !sortOrder) {
return data;
Expand All @@ -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;
Expand Down

0 comments on commit 3442ae8

Please sign in to comment.