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: Draft messages jump around in the LHN #12313

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ function getOrderedReportIDs(reportIDFromRoute) {
pinnedReportOptions.push(report);
} else if (report.hasOutstandingIOU && !report.isIOUReportOwner) {
iouDebtReportOptions.push(report);

// If the active report has a draft, we do not put it in the group of draft reports because we want it to maintain it's current position. Otherwise the report's position
// jumps around in the LHN and it's kind of confusing to the user to see the LHN reorder when they start typing a comment on a report.
} else if (report.hasDraft && report.reportID !== reportIDFromRoute) {
} else if (report.hasDraft) {
draftReportOptions.push(report);
} else {
recentReportOptions.push(report);
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/LHNOrderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('Sidebar', () => {
});
});

it('doesn\'t change the order when adding a draft to the active report', () => {
it('changes the order when adding a draft to the active report', () => {
// Given three reports in the recently updated order of 3, 2, 1
// And the first report has a draft
// And the currently viewed report is the first report
Expand All @@ -147,17 +147,17 @@ describe('Sidebar', () => {
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))

// Then there should be a pencil icon and report one should still be the last one because putting a draft on the active report should not change it's location
// Then there should be a pencil icon and report one should be the first one because putting a draft on the active report should change its location
// in the ordered list
.then(() => {
const pencilIcon = sidebarLinks.getAllByAccessibilityHint('Pencil Icon');
expect(pencilIcon).toHaveLength(1);

const displayNames = sidebarLinks.queryAllByA11yLabel('Chat user display names');
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two'); // this has `hasDraft` flag enabled so it will be on top
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
});
});

Expand Down