From 46e7f62426b3403df19a529739f3cdeb5e30d0c3 Mon Sep 17 00:00:00 2001 From: "alberto@expensify.com" Date: Tue, 10 Nov 2020 11:14:32 +0100 Subject: [PATCH 1/6] Keep chats with draft comments in the LHN --- src/pages/home/sidebar/SidebarLinks.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pages/home/sidebar/SidebarLinks.js b/src/pages/home/sidebar/SidebarLinks.js index ddf6dd5e82c7..d89860801952 100644 --- a/src/pages/home/sidebar/SidebarLinks.js +++ b/src/pages/home/sidebar/SidebarLinks.js @@ -12,6 +12,7 @@ import ChatSwitcherView from './ChatSwitcherView'; import SafeAreaInsetPropTypes from '../../SafeAreaInsetPropTypes'; import compose from '../../../libs/compose'; import {withRouter} from '../../../libs/Router'; +import get from 'lodash.get'; const propTypes = { // These are from withRouter @@ -38,9 +39,13 @@ const propTypes = { reportName: PropTypes.string, unreadActionCount: PropTypes.number, })), + + // List of draft comments + comments: PropTypes.object, }; const defaultProps = { reports: {}, + comments: {}, }; class SidebarLinks extends React.Component { @@ -62,10 +67,9 @@ class SidebarLinks extends React.Component { 'desc', 'asc' ]); - // Filter the reports so that the only reports shown are pinned, unread, and the one matching the URL // eslint-disable-next-line max-len - const reportsToDisplay = _.filter(sortedReports, report => (report.isPinned || (report.unreadActionCount > 0) || report.reportID === reportIDInUrl)); + const reportsToDisplay = _.filter(sortedReports, report => (report.isPinned || (report.unreadActionCount > 0) || report.reportID === reportIDInUrl || get(this.props.comments, `${IONKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, '').length > 0)); // Update styles to hide the report links if they should not be visible const sidebarLinksStyle = this.state.areReportLinksVisible @@ -125,6 +129,9 @@ export default compose( withIon({ reports: { key: IONKEYS.COLLECTION.REPORT, + }, + comments: { + key: IONKEYS.COLLECTION.REPORT_DRAFT_COMMENT, } }), )(SidebarLinks); From f0b353167e35ca8ed423359febc0296bd8a2f91e Mon Sep 17 00:00:00 2001 From: "alberto@expensify.com" Date: Mon, 23 Nov 2020 12:18:05 +0100 Subject: [PATCH 2/6] cleanup style --- src/pages/home/sidebar/SidebarLinks.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/home/sidebar/SidebarLinks.js b/src/pages/home/sidebar/SidebarLinks.js index fcab45d30d5f..4c16b4fdb166 100644 --- a/src/pages/home/sidebar/SidebarLinks.js +++ b/src/pages/home/sidebar/SidebarLinks.js @@ -35,8 +35,7 @@ const propTypes = { })), // List of draft comments. We don't know the shape, since the keys include the report numbers - // eslint-disable-next-line react/forbid-prop-types - comments: PropTypes.object, + comments: PropTypes.objectOf(PropTypes.string), isChatSwitcherActive: PropTypes.bool, @@ -55,6 +54,7 @@ const defaultProps = { personalDetails: {}, }; + const SidebarLinks = (props) => { const {onLinkClick} = props; const reportIDInUrl = parseInt(props.match.params.reportID, 10); @@ -65,11 +65,13 @@ const SidebarLinks = (props) => { 'desc', 'asc' ]); + const hasComment = reportID => get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, '').length > 0; // Filter the reports so that the only reports shown are pinned, unread, have draft // comments (but are not the open one), and the one matching the URL - // eslint-disable-next-line max-len - const reportsToDisplay = _.filter(sortedReports, report => (report.isPinned || (report.unreadActionCount > 0) || report.reportID === reportIDInUrl || (report.reportID !== reportIDInUrl && get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, '').length > 0))); + const reportsToDisplay = _.filter(sortedReports, report => (report.isPinned || (report.unreadActionCount > 0) + || report.reportID === reportIDInUrl + || (report.reportID !== reportIDInUrl && hasComment(report.reportID)))); // Update styles to hide the report links if they should not be visible const sidebarLinksStyle = !props.isChatSwitcherActive @@ -110,9 +112,7 @@ const SidebarLinks = (props) => { login: participantDetails ? participantDetails.login : '', reportID: report.reportID, isUnread: report.unreadActionCount > 0, - - // eslint-disable-next-line max-len - hasDraftComment: report.reportID !== reportIDInUrl && get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, '').length > 0 + hasDraftComment: report.reportID !== reportIDInUrl && hasComment(report.reportID) }} onSelectRow={onLinkClick} optionIsFocused={report.reportID === reportIDInUrl} From ee45cb470eb9162cc36f4bf19e44f6e43343f0a5 Mon Sep 17 00:00:00 2001 From: "alberto@expensify.com" Date: Tue, 24 Nov 2020 11:05:40 +0100 Subject: [PATCH 3/6] split line --- src/pages/home/sidebar/SidebarLinks.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarLinks.js b/src/pages/home/sidebar/SidebarLinks.js index 4cbdc0f40063..1095a134a29a 100644 --- a/src/pages/home/sidebar/SidebarLinks.js +++ b/src/pages/home/sidebar/SidebarLinks.js @@ -64,7 +64,10 @@ const SidebarLinks = (props) => { 'desc', 'asc' ]); - const hasComment = reportID => get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, '').length > 0; + function hasComment (reportID) { + const reportComments = get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, ''); + return reportComments.length > 0; + } // Filter the reports so that the only reports shown are pinned, unread, have draft // comments (but are not the open one), and the one matching the URL From 34f5d480bcaaa6af28c1a55073a2cc95761863b8 Mon Sep 17 00:00:00 2001 From: "alberto@expensify.com" Date: Tue, 24 Nov 2020 11:47:00 +0100 Subject: [PATCH 4/6] remove extra space --- src/pages/home/sidebar/SidebarLinks.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/sidebar/SidebarLinks.js b/src/pages/home/sidebar/SidebarLinks.js index 1095a134a29a..882aa386158c 100644 --- a/src/pages/home/sidebar/SidebarLinks.js +++ b/src/pages/home/sidebar/SidebarLinks.js @@ -64,9 +64,9 @@ const SidebarLinks = (props) => { 'desc', 'asc' ]); - function hasComment (reportID) { - const reportComments = get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, ''); - return reportComments.length > 0; + function hasComment(reportID) { + const allComments = get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, ''); + return allComments.length > 0; } // Filter the reports so that the only reports shown are pinned, unread, have draft From 4859ab67fbe9002e0e53e0a1cbdea2c86d822def Mon Sep 17 00:00:00 2001 From: "alberto@expensify.com" Date: Thu, 26 Nov 2020 11:25:40 +0100 Subject: [PATCH 5/6] add comment --- src/pages/home/sidebar/SidebarLinks.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pages/home/sidebar/SidebarLinks.js b/src/pages/home/sidebar/SidebarLinks.js index 882aa386158c..252994adc1fa 100644 --- a/src/pages/home/sidebar/SidebarLinks.js +++ b/src/pages/home/sidebar/SidebarLinks.js @@ -64,6 +64,13 @@ const SidebarLinks = (props) => { 'desc', 'asc' ]); + + /** + * Check if the report has a draft comment + * + * @param {number} reportID + * @returns {boolean} + */ function hasComment(reportID) { const allComments = get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, ''); return allComments.length > 0; From 974e2e33e212fc19f36816afd0dff0843d9a5a96 Mon Sep 17 00:00:00 2001 From: "alberto@expensify.com" Date: Fri, 27 Nov 2020 11:11:52 +0100 Subject: [PATCH 6/6] Do not add second text line if we don't have it --- src/pages/home/sidebar/ChatLinkRow.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/sidebar/ChatLinkRow.js b/src/pages/home/sidebar/ChatLinkRow.js index f5aca4f64523..579e73851e9a 100644 --- a/src/pages/home/sidebar/ChatLinkRow.js +++ b/src/pages/home/sidebar/ChatLinkRow.js @@ -88,9 +88,9 @@ const ChatLinkRow = ({ ) } - {option.text === option.alternateText ? ( + {(option.text === option.alternateText || option.alternateText.length === 0) ? ( - {option.alternateText} + {option.text} ) : ( <>