From f8a9b73e8e134772d62dab1e80e774217f73cffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kapa=C5=82a?= Date: Fri, 22 Sep 2023 11:37:01 +0200 Subject: [PATCH 1/6] compare strings instead of dates --- src/libs/SidebarUtils.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index f645697690e6..61d0394e3cdc 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -186,10 +186,32 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p draftReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); if (isInDefaultMode) { nonArchivedReports.sort( - (a, b) => new Date(b.lastVisibleActionCreated) - new Date(a.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()), + (a, b) => { + const stringA = a.lastVisibleActionCreated; + const stringB = b.lastVisibleActionCreated; + if (stringA < stringB) { + return -1; + } + if (stringA > stringB) { + return 1; + } + return a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()); + } ); // For archived reports ensure that most recent reports are at the top by reversing the order - archivedReports.sort((a, b) => new Date(a.lastVisibleActionCreated) - new Date(b.lastVisibleActionCreated)); + archivedReports.sort( + (a, b) => { + const stringA = a.lastVisibleActionCreated; + const stringB = b.lastVisibleActionCreated; + if (stringA < stringB) { + return -1; + } + if (stringA > stringB) { + return 1; + } + return 0; + } + ); } else { nonArchivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); archivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); From 4ffde032a9737078cc4dace02e0b327cdca33679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kapa=C5=82a?= Date: Fri, 22 Sep 2023 12:53:26 +0200 Subject: [PATCH 2/6] fix order --- src/libs/SidebarUtils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 61d0394e3cdc..ffbe72075099 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -190,10 +190,10 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p const stringA = a.lastVisibleActionCreated; const stringB = b.lastVisibleActionCreated; if (stringA < stringB) { - return -1; + return 1; } if (stringA > stringB) { - return 1; + return -1; } return a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()); } @@ -204,10 +204,10 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p const stringA = a.lastVisibleActionCreated; const stringB = b.lastVisibleActionCreated; if (stringA < stringB) { - return -1; + return 1; } if (stringA > stringB) { - return 1; + return -1; } return 0; } From 5245335cda6aef187a32d30140ce4fa6edf7926f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kapa=C5=82a?= Date: Fri, 22 Sep 2023 12:56:41 +0200 Subject: [PATCH 3/6] linting --- src/libs/SidebarUtils.js | 44 ++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index ffbe72075099..79bec62a1155 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -185,33 +185,29 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p outstandingIOUReports.sort((a, b) => b.iouReportAmount - a.iouReportAmount || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); draftReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); if (isInDefaultMode) { - nonArchivedReports.sort( - (a, b) => { - const stringA = a.lastVisibleActionCreated; - const stringB = b.lastVisibleActionCreated; - if (stringA < stringB) { - return 1; - } - if (stringA > stringB) { - return -1; - } - return a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()); + nonArchivedReports.sort((a, b) => { + const stringA = a.lastVisibleActionCreated; + const stringB = b.lastVisibleActionCreated; + if (stringA < stringB) { + return 1; } - ); + if (stringA > stringB) { + return -1; + } + return a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()); + }); // For archived reports ensure that most recent reports are at the top by reversing the order - archivedReports.sort( - (a, b) => { - const stringA = a.lastVisibleActionCreated; - const stringB = b.lastVisibleActionCreated; - if (stringA < stringB) { - return 1; - } - if (stringA > stringB) { - return -1; - } - return 0; + archivedReports.sort((a, b) => { + const stringA = a.lastVisibleActionCreated; + const stringB = b.lastVisibleActionCreated; + if (stringA < stringB) { + return 1; } - ); + if (stringA > stringB) { + return -1; + } + return 0; + }); } else { nonArchivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); archivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); From 7483d2dd952d1af12f6132628f2e3d5009ccbbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kapa=C5=82a?= Date: Fri, 22 Sep 2023 13:11:21 +0200 Subject: [PATCH 4/6] applysuggestions --- src/libs/SidebarUtils.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 79bec62a1155..76e96de8542e 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -184,29 +184,22 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p pinnedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); outstandingIOUReports.sort((a, b) => b.iouReportAmount - a.iouReportAmount || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); draftReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); + const compareStringDates = (stringA, stringB) => { + if (stringA < stringB) { + return 1; + } + if (stringA > stringB) { + return -1; + } + return 0; + }; if (isInDefaultMode) { nonArchivedReports.sort((a, b) => { - const stringA = a.lastVisibleActionCreated; - const stringB = b.lastVisibleActionCreated; - if (stringA < stringB) { - return 1; - } - if (stringA > stringB) { - return -1; - } - return a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()); + return compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()); }); // For archived reports ensure that most recent reports are at the top by reversing the order archivedReports.sort((a, b) => { - const stringA = a.lastVisibleActionCreated; - const stringB = b.lastVisibleActionCreated; - if (stringA < stringB) { - return 1; - } - if (stringA > stringB) { - return -1; - } - return 0; + return compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated); }); } else { nonArchivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); From 53c0f76ae8b26c10eea71bbe73083e94c912ee9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kapa=C5=82a?= Date: Fri, 22 Sep 2023 13:23:12 +0200 Subject: [PATCH 5/6] fx linting --- src/libs/SidebarUtils.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 76e96de8542e..0366a6820970 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -194,13 +194,11 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p return 0; }; if (isInDefaultMode) { - nonArchivedReports.sort((a, b) => { - return compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()); - }); + nonArchivedReports.sort( + (a, b) => compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()), + ); // For archived reports ensure that most recent reports are at the top by reversing the order - archivedReports.sort((a, b) => { - return compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated); - }); + archivedReports.sort((a, b) => compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated)); } else { nonArchivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); archivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); From 9c823823afc38b8e6505a5502ff051e3244b33ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kapa=C5=82a?= Date: Sat, 23 Sep 2023 10:57:56 +0200 Subject: [PATCH 6/6] apply suggestions --- src/libs/SidebarUtils.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 0366a6820970..c87ea042e580 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -71,6 +71,16 @@ function isSidebarLoadedReady() { return sidebarIsReadyPromise; } +function compareStringDates(stringA, stringB) { + if (stringA < stringB) { + return -1; + } + if (stringA > stringB) { + return 1; + } + return 0; +} + function setIsSidebarLoadedReady() { resolveSidebarIsReadyPromise(); } @@ -184,21 +194,13 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p pinnedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); outstandingIOUReports.sort((a, b) => b.iouReportAmount - a.iouReportAmount || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); draftReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); - const compareStringDates = (stringA, stringB) => { - if (stringA < stringB) { - return 1; - } - if (stringA > stringB) { - return -1; - } - return 0; - }; + if (isInDefaultMode) { nonArchivedReports.sort( - (a, b) => compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()), + (a, b) => compareStringDates(b.lastVisibleActionCreated, a.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()), ); // For archived reports ensure that most recent reports are at the top by reversing the order - archivedReports.sort((a, b) => compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated)); + archivedReports.sort((a, b) => compareStringDates(b.lastVisibleActionCreated, a.lastVisibleActionCreated)); } else { nonArchivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase())); archivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()));