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

fix: do not update sidebar for active report drafts #5317

Merged
merged 6 commits into from
Oct 22, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,61 @@ const defaultProps = {
};

class SidebarLinks extends React.Component {
shouldComponentUpdate(nextProps) {
// We don't need to limit draft comment flashing for small screen widths as LHN is not visible.
if (nextProps.isSmallScreenWidth) {
return true;
}

const didActiveReportChange = this.props.currentlyViewedReportID !== nextProps.currentlyViewedReportID;
if (didActiveReportChange) {
return true;
}

const previousDraftComments = this.props.draftComments;
const nextDraftComments = nextProps.draftComments;
mountiny marked this conversation as resolved.
Show resolved Hide resolved

const previousDraftReports = Object.keys(previousDraftComments);
const nextDraftReports = Object.keys(nextDraftComments);

const reportsWithNewDraftComments = nextDraftReports.filter((report) => {
const isNewDraftComment = !previousDraftReports.includes(report);
const wasNonEmptyDraftComment = previousDraftComments[report] === '';
const hasDraftCommentChanged = previousDraftComments[report] !== nextDraftComments[report];

return isNewDraftComment || (hasDraftCommentChanged && wasNonEmptyDraftComment);
});
const reportsWithRemovedDraftComments = previousDraftReports.filter((report) => {
const isRemovedDraftComment = !nextDraftReports.includes(report);
const isEmptyDraftComment = nextDraftComments[report] === '';
const hasDraftCommentChanged = previousDraftComments[report] !== nextDraftComments[report];

return isRemovedDraftComment || (hasDraftCommentChanged && isEmptyDraftComment);
});
const reportsWithEditedDraftComments = nextDraftReports.filter((report) => {
const didDraftCommentExistPreviously = previousDraftReports.includes(report);
const hasDraftCommentChanged = previousDraftComments[report] !== nextDraftComments[report];
const isNotANewDraftComment = !reportsWithNewDraftComments.includes(report);
const isNotARemovedDraftComment = !reportsWithRemovedDraftComments.includes(report);

return didDraftCommentExistPreviously && hasDraftCommentChanged && isNotANewDraftComment && isNotARemovedDraftComment;
});

const allReportsWithDraftCommentChanges = [
...reportsWithNewDraftComments,
...reportsWithRemovedDraftComments,
...reportsWithEditedDraftComments,
];

const activeReportID = this.props.currentlyViewedReportID;
const reportKey = `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${activeReportID}`;

if (allReportsWithDraftCommentChanges.length === 1 && allReportsWithDraftCommentChanges.includes(reportKey)) {
return false;
}
return true;
}

showSearchPage() {
Navigation.navigate(ROUTES.SEARCH);
}
Expand Down