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

Keep chats with draft comments in the LHN #781

Merged
merged 12 commits into from
Dec 1, 2020
14 changes: 7 additions & 7 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const propTypes = {
})),

// List of draft comments. We don't know the shape, since the keys include the report numbers

This comment was marked as resolved.

This comment was marked as resolved.

// eslint-disable-next-line react/forbid-prop-types
comments: PropTypes.object,
comments: PropTypes.objectOf(PropTypes.string),

isChatSwitcherActive: PropTypes.bool,

Expand All @@ -55,6 +54,7 @@ const defaultProps = {
personalDetails: {},
};


const SidebarLinks = (props) => {
const {onLinkClick} = props;
const reportIDInUrl = parseInt(props.match.params.reportID, 10);
Expand All @@ -65,11 +65,13 @@ const SidebarLinks = (props) => {
'desc',
'asc'
]);
const hasComment = reportID => get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, '').length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still having a lint warning for the line length. I have a few suggestions:

  1. Make it into a multi-line function like this:
function hasComment(reportID) {
    const reportComments = get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, '');
    return reportComments.length > 1;
}
  1. Define it outside the component and pass both reportID and props.comments as arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed


// 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
Expand Down Expand Up @@ -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}
Expand Down