avo icon indicating copy to clipboard operation
avo copied to clipboard

Fix sidebar default collapsed state

Open OlexYakov opened this issue 3 years ago • 3 comments
trafficstars

Description

The deafault collapsed option for menu sections was not working. The default state is correctly set, but incorrectly read in the Stimulus controller, the bug was introduced in #941.

Basically, on the first load (and if the user never interacted with the collapse feature) the this.userState will return null, because there is no such key in the local storage. this.userState === 'collapsed' will always return false if the user never toggled the collapse feature, making the default option useless.

The fix is using the defaultState if userState is unefined/null.

Checklist:

  • [x] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have added tests that prove my fix is effective or that my feature works

Manual review steps

  1. Create a section with collapsable: true, collapsed: true
  2. Delete local storage (clean cookies) to ensure there are no user preferences overriding the default
  3. Check if the section appears collapsed.

OlexYakov avatar Aug 09 '22 12:08 OlexYakov

Code Climate has analyzed commit 2b1efb63 and detected 0 issues on this pull request.

View more on Code Climate.

qlty-cloud-legacy[bot] avatar Aug 09 '22 12:08 qlty-cloud-legacy[bot]

Thanks for the fix!

adrianthedev avatar Aug 09 '22 12:08 adrianthedev

Codecov Report

Merging #1127 (2b1efb6) into main (90cc721) will increase coverage by 0.20%. The diff coverage is 88.48%.

@@            Coverage Diff             @@
##             main    #1127      +/-   ##
==========================================
+ Coverage   94.08%   94.29%   +0.20%     
==========================================
  Files         430      543     +113     
  Lines        7861    10779    +2918     
==========================================
+ Hits         7396    10164    +2768     
- Misses        465      615     +150     
Impacted Files Coverage Δ
.../avo/fields/common/single_file_viewer_component.rb 40.90% <0.00%> (ø)
app/controllers/avo/private_controller.rb 80.00% <0.00%> (-20.00%) :arrow_down:
lib/avo/configuration.rb 54.16% <44.44%> (-36.26%) :arrow_down:
app/controllers/avo/debug_controller.rb 46.15% <46.15%> (ø)
app/controllers/avo/actions_controller.rb 71.73% <57.14%> (-3.27%) :arrow_down:
lib/avo/app.rb 75.25% <60.78%> (-15.66%) :arrow_down:
app/components/avo/sidebar_component.rb 75.00% <66.66%> (-25.00%) :arrow_down:
lib/avo/base_action.rb 80.39% <66.66%> (-1.06%) :arrow_down:
app/controllers/avo/home_controller.rb 64.28% <75.00%> (+0.64%) :arrow_up:
lib/avo/concerns/has_editable_controls.rb 75.00% <75.00%> (ø)
... and 302 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov[bot] avatar Aug 09 '22 12:08 codecov[bot]