Merge branch '19183-refactor-sidebar-js' into 'master'
Refactor sidebar logic for more predictable behavior ## What does this MR do? Fixes a few bugs with the sidebar and "pin" functionality: 1. Pinned state would get reset when loading a page with a viewport smaller than 1024px (#19183) 2. Toggle buttons could occasionally end up in an invalid state in which the toggle is hidden from view at the same time the sidebar is collapsed. ![2016-09-03-09.39.07](/uploads/75d9a836ab58aae9f89f38cc29e90bbd/2016-09-03-09.39.07.gif) 3. Clicking outside the sidebar to trigger 'collapse' when below the 1024px breakpoint would work only if not pinned, even though pin status should only effect the sidebar above the 1024px breakpoint. 4. Code confusing with no single source of truth for the state of the sidebar. Sometimes pinned state is inferred from the cookie, sometimes from the DOM. Code to handle these functions was confusingly split across both `sidebar.js` and `application.js` for no apparent reason. I've created a singleton ES6 class to handle the sidebar DOM manipulations, using the properties `isExpanded` and `isPinned` as the canonical state and providing a `renderState` method to sync the DOM with this state whenever it needs updating. This avoids the possibility of invalid states caused by reliance on jQuery `toggleClass()` methods and makes the code much more readable/maintainable. ## Are there points in the code the reviewer needs to double check? It is a substantial rewrite, so I could use another set of eyes to make sure nothing was left behind from the original implementation. ## Why was this MR needed? I initially intended to just fix #19183 by modifying the code in place, but it proved to be a difficult mess and rather than add to the technical debt it made sense to write a more readable implementation of the sidebar functionality. ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - Tests - [ ] Added for this feature/bug - [x] All builds are passing - [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html) - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) ## What are the relevant issue numbers? Closes #19183 See merge request !6169
Showing
Please register or sign in to comment