diff options
author | Fatih Acet <acetfatih@gmail.com> | 2016-09-07 23:54:49 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-09-07 23:54:49 +0300 |
commit | f9d5cb1340ad9ac5e6567a4ce64e898801bca9bd (patch) | |
tree | cc9626a18c3d323cd0dbf2c624cb2788d8641ab6 /spec/helpers | |
parent | b94d0bc8a3f488e60926a98c90f921fd058ecc4f (diff) | |
parent | 9b8ee45c87588c16337d2b1c3cff1fc52aec1571 (diff) |
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
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/nav_helper_spec.rb | 25 |
1 files changed, 0 insertions, 25 deletions
diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb deleted file mode 100644 index e4d18d8bfc6..00000000000 --- a/spec/helpers/nav_helper_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the NavHelper. For example: -# -# describe NavHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -describe NavHelper do - describe '#nav_menu_collapsed?' do - it 'returns true when the nav is collapsed in the cookie' do - helper.request.cookies[:collapsed_nav] = 'true' - expect(helper.nav_menu_collapsed?).to eq true - end - - it 'returns false when the nav is not collapsed in the cookie' do - helper.request.cookies[:collapsed_nav] = 'false' - expect(helper.nav_menu_collapsed?).to eq false - end - end -end |