Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix description sort #44472

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
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
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.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 @@
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 @@
}

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
Loading