Skip to content

Commit

Permalink
fix sorting not working
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Nov 26, 2024
1 parent 48d4fa1 commit 65c770e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
7 changes: 2 additions & 5 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ function createOption(
policyID: undefined,
isOptimisticPersonalDetail: false,
lastMessageText: '',
lastVisibleActionCreated: undefined,
};

const personalDetailMap = getPersonalDetailsForAccountIDs(accountIDs, personalDetails);
Expand Down Expand Up @@ -677,6 +678,7 @@ function createOption(
result.policyID = report.policyID;
result.isSelfDM = ReportUtils.isSelfDM(report);
result.notificationPreference = ReportUtils.getReportNotificationPreference(report);
result.lastVisibleActionCreated = report.lastVisibleActionCreated;

const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true);

Expand Down Expand Up @@ -937,13 +939,8 @@ function orderReportOptions(
return lodashOrderBy(
options,
[
// Sort descending by lastVisibleActionCreated
(option) => option?.lastVisibleActionCreated ?? 0,
(option) => {
// TODO: what the fuck this is at the bottom already, is this even needed? i don't think so …
// if (option.private_isArchived) {
// return CONST.DATE.UNIX_EPOCH; // Keep archived at bottom
// }
if (option.isPolicyExpenseChat && preferPolicyExpenseChat && option.policyID === activePolicyID) {
return 0;
}
Expand Down
14 changes: 6 additions & 8 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,13 @@ describe('OptionsListUtils', () => {

const filteredOptions = OptionsListUtils.filterAndOrderOptions(options, searchText, {sortByReportTypeInSearch: true});

// When sortByReportTypeInSearch is true, we expect all options to be part of the recentReports list:
expect(filteredOptions.personalDetails.length).toBe(0);

// Expect to only find reports that matched our search text:
expect(filteredOptions.recentReports.length).toBe(4);

// This items should be ordered by most recent action (and other criteria such as whether they are archived):
expect(filteredOptions.recentReports.at(0)?.text).toBe('Invisible Woman');
expect(filteredOptions.recentReports.at(1)?.text).toBe('Spider-Man');
expect(filteredOptions.recentReports.at(2)?.text).toBe('Black Widow');
Expand Down Expand Up @@ -944,15 +950,7 @@ describe('OptionsListUtils', () => {
});

it('should return all matching reports and personal details (getOptions)', () => {
console.log({
reports: OPTIONS.reports.length,
personalDetails: OPTIONS.personalDetails.length,
});
const options = OptionsListUtils.getOptions({reports: OPTIONS.reports, personalDetails: OPTIONS.personalDetails});
console.log('after getOptions', {
reports: options.recentReports.length,
personalDetails: options.personalDetails.length,
});
const filteredOptions = OptionsListUtils.filterAndOrderOptions(options, '.com', {maxRecentReportsToShow: 5});

expect(filteredOptions.personalDetails.length).toBe(2);
Expand Down

0 comments on commit 65c770e

Please sign in to comment.