From ccb8619ed1ec7f8a4617b718c6415aa115f61502 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 31 Dec 2021 21:49:08 +0530 Subject: [PATCH 1/6] fix: Search Page Order --- src/libs/OptionsListUtils.js | 41 ++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index e8c17a932ef9f..1384a016a4682 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -352,6 +352,8 @@ function getOptions(reports, personalDetails, activeReportID, { includeRecentReports = false, prioritizePinnedReports = false, prioritizeDefaultRoomsInSearch = false, + + // When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well. sortByReportTypeInSearch = false, sortByLastMessageTimestamp = false, searchValue = '', @@ -507,19 +509,6 @@ function getOptions(reports, personalDetails, activeReportID, { recentReportOptions = reportsSplitByDefaultChatRoom[0].concat(reportsSplitByDefaultChatRoom[1]); } - // If we are prioritizing 1:1 chats in search, do it only once we started searching - if (sortByReportTypeInSearch && searchValue !== '') { - recentReportOptions = lodashOrderBy(recentReportOptions, [(option) => { - if (option.isDefaultChatRoom || option.isArchivedRoom) { - return 3; - } - if (!option.login) { - return 2; - } - return 1; - }], ['asc']); - } - if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats _.each(allPersonalDetailsOptions, (personalDetailOption) => { @@ -537,6 +526,21 @@ function getOptions(reports, personalDetails, activeReportID, { }); } + // If we are prioritizing 1:1 chats in search, do it only once we started searching + if (sortByReportTypeInSearch && searchValue !== '') { + // When sortByReportTypeInSearch is true, recentReports will be returned with all the reports including personalDetailsOptions in the correct Order. + recentReportOptions.push(...personalDetailsOptions); + recentReportOptions = lodashOrderBy(recentReportOptions, [(option) => { + if (option.isDefaultChatRoom || option.isArchivedRoom) { + return 3; + } + if (!option.login) { + return 2; + } + return 1; + }], ['asc']); + } + let userToInvite = null; if (searchValue && recentReportOptions.length === 0 @@ -581,7 +585,7 @@ function getSearchOptions( searchValue = '', betas, ) { - return getOptions(reports, personalDetails, 0, { + const {recentReports, userToInvite} = getOptions(reports, personalDetails, 0, { betas, searchValue, includeRecentReports: true, @@ -597,6 +601,15 @@ function getSearchOptions( forcePolicyNamePreview: true, prioritizeIOUDebts: false, }); + + return { + recentReports, + userToInvite, + + // When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well. + // So return [] value for consistentency + personalDetails: [], + }; } /** From 0af57ea61107143f0497491c3381ab53dba1cd35 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 31 Dec 2021 21:51:25 +0530 Subject: [PATCH 2/6] Clean the getSearchOptions interface --- src/libs/OptionsListUtils.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 1384a016a4682..b600dc99dd744 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -603,12 +603,9 @@ function getSearchOptions( }); return { + // When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well. recentReports, userToInvite, - - // When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well. - // So return [] value for consistentency - personalDetails: [], }; } From 22d69576c99beedddea61fa9338cb36c76c8ba35 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 31 Dec 2021 21:51:43 +0530 Subject: [PATCH 3/6] Remove extra personalDetails from the SearchPage --- src/pages/SearchPage.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 664af9ad0415d..30bf5450d83e4 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -59,7 +59,6 @@ class SearchPage extends Component { const { recentReports, - personalDetails, userToInvite, } = OptionsListUtils.getSearchOptions( props.reports, @@ -71,7 +70,6 @@ class SearchPage extends Component { this.state = { searchValue: '', recentReports, - personalDetails, userToInvite, }; } @@ -92,7 +90,7 @@ class SearchPage extends Component { getSections() { const sections = [{ title: this.props.translate('common.recents'), - data: this.state.recentReports.concat(this.state.personalDetails), + data: this.state.recentReports, shouldShow: true, indexOffset: 0, }]; @@ -112,7 +110,6 @@ class SearchPage extends Component { updateOptions() { const { recentReports, - personalDetails, userToInvite, } = OptionsListUtils.getSearchOptions( this.props.reports, @@ -123,7 +120,6 @@ class SearchPage extends Component { this.setState({ userToInvite, recentReports, - personalDetails, }); } @@ -154,7 +150,7 @@ class SearchPage extends Component { render() { const sections = this.getSections(); const headerMessage = OptionsListUtils.getHeaderMessage( - (this.state.recentReports.length + this.state.personalDetails.length) !== 0, + this.state.recentReports.length !== 0, Boolean(this.state.userToInvite), this.state.searchValue, ); From d85c860921cdc02786181d80e15bba8307343bf1 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 31 Dec 2021 23:10:49 +0530 Subject: [PATCH 4/6] Correctly return the personalDetails for search --- src/libs/OptionsListUtils.js | 41 ++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index b600dc99dd744..1e89c0276aaed 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -367,7 +367,7 @@ function getOptions(reports, personalDetails, activeReportID, { }) { let recentReportOptions = []; const pinnedReportOptions = []; - const personalDetailsOptions = []; + let personalDetailsOptions = []; const iouDebtReportOptions = []; const draftReportOptions = []; @@ -526,21 +526,6 @@ function getOptions(reports, personalDetails, activeReportID, { }); } - // If we are prioritizing 1:1 chats in search, do it only once we started searching - if (sortByReportTypeInSearch && searchValue !== '') { - // When sortByReportTypeInSearch is true, recentReports will be returned with all the reports including personalDetailsOptions in the correct Order. - recentReportOptions.push(...personalDetailsOptions); - recentReportOptions = lodashOrderBy(recentReportOptions, [(option) => { - if (option.isDefaultChatRoom || option.isArchivedRoom) { - return 3; - } - if (!option.login) { - return 2; - } - return 1; - }], ['asc']); - } - let userToInvite = null; if (searchValue && recentReportOptions.length === 0 @@ -563,6 +548,22 @@ function getOptions(reports, personalDetails, activeReportID, { userToInvite.icons = [defaultAvatarForUserToInvite]; } + // If we are prioritizing 1:1 chats in search, do it only once we started searching + if (sortByReportTypeInSearch && searchValue !== '') { + // When sortByReportTypeInSearch is true, recentReports will be returned with all the reports including personalDetailsOptions in the correct Order. + recentReportOptions.push(...personalDetailsOptions); + personalDetailsOptions = []; + recentReportOptions = lodashOrderBy(recentReportOptions, [(option) => { + if (option.isDefaultChatRoom || option.isArchivedRoom) { + return 3; + } + if (!option.login) { + return 2; + } + return 1; + }], ['asc']); + } + return { personalDetails: personalDetailsOptions, recentReports: recentReportOptions, @@ -585,7 +586,7 @@ function getSearchOptions( searchValue = '', betas, ) { - const {recentReports, userToInvite} = getOptions(reports, personalDetails, 0, { + return getOptions(reports, personalDetails, 0, { betas, searchValue, includeRecentReports: true, @@ -601,12 +602,6 @@ function getSearchOptions( forcePolicyNamePreview: true, prioritizeIOUDebts: false, }); - - return { - // When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well. - recentReports, - userToInvite, - }; } /** From b9f68687d82e2f79a23d53afa588a372228a8292 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 31 Dec 2021 23:14:59 +0530 Subject: [PATCH 5/6] Correct SearchPage logic for sections --- src/pages/SearchPage.js | 44 +++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 30bf5450d83e4..1fc76da9c3be9 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -59,6 +59,7 @@ class SearchPage extends Component { const { recentReports, + personalDetails, userToInvite, } = OptionsListUtils.getSearchOptions( props.reports, @@ -70,6 +71,7 @@ class SearchPage extends Component { this.state = { searchValue: '', recentReports, + personalDetails, userToInvite, }; } @@ -88,12 +90,18 @@ class SearchPage extends Component { * @returns {Array} */ getSections() { - const sections = [{ - title: this.props.translate('common.recents'), - data: this.state.recentReports, - shouldShow: true, - indexOffset: 0, - }]; + const sections = [ + { + data: this.state.recentReports, + shouldShow: true, + indexOffset: 0, + }, + { + data: this.state.personalDetails, + shouldShow: true, + indexOffset: this.state.recentReports.length, + }, + ]; if (this.state.userToInvite) { sections.push(({ @@ -110,6 +118,7 @@ class SearchPage extends Component { updateOptions() { const { recentReports, + personalDetails, userToInvite, } = OptionsListUtils.getSearchOptions( this.props.reports, @@ -120,6 +129,7 @@ class SearchPage extends Component { this.setState({ userToInvite, recentReports, + personalDetails, }); } @@ -150,7 +160,7 @@ class SearchPage extends Component { render() { const sections = this.getSections(); const headerMessage = OptionsListUtils.getHeaderMessage( - this.state.recentReports.length !== 0, + (this.state.recentReports.length + this.state.personalDetails.length) !== 0, Boolean(this.state.userToInvite), this.state.searchValue, ); @@ -165,16 +175,16 @@ class SearchPage extends Component { {didScreenTransitionEnd && ( - + )} From 1c5154ce1981b263ef9d8a81f6402706c5bb174a Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Thu, 13 Jan 2022 21:16:41 +0530 Subject: [PATCH 6/6] move deleted rooms last in the list --- src/libs/OptionsListUtils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 9c923eecddf30..66f8912d0b5ed 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -385,7 +385,10 @@ function getOptions(reports, personalDetails, activeReportID, { sortProperty = ['reportName']; } const sortDirection = [sortByAlphaAsc ? 'asc' : 'desc']; - const orderedReports = lodashOrderBy(reports, sortProperty, sortDirection); + let orderedReports = lodashOrderBy(reports, sortProperty, sortDirection); + + // Move the archived Rooms to the last + orderedReports = _.sortBy(orderedReports, report => ReportUtils.isArchivedRoom(report)); const allReportOptions = []; _.each(orderedReports, (report) => {