All files / ee/app/assets/javascripts/epic sidebar_context.js

18.75% Statements 3/16
0% Branches 0/9
25% Functions 1/4
20% Lines 3/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43            3x   3x                                                 3x                  
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import $ from 'jquery';
import { setCookie } from '~/lib/utils/common_utils';
 
export default class SidebarContext {
  constructor() {
    const $issuableSidebar = $('.js-issuable-update');
 
    $issuableSidebar
      .off('click', '.js-sidebar-dropdown-toggle')
      .on('click', '.js-sidebar-dropdown-toggle', function onClickEdit(e) {
        e.preventDefault();
        const $block = $(this).parents('.js-labels-block');
        const $selectbox = $block.find('.js-selectbox');
 
        // We use `:visible` to detect element visibility
        // since labels dropdown itself is handled by
        // labels_select.js which internally uses
        // $.hide() & $.show() to toggle elements
        // which requires us to use `display: none;`
        // in `labels_select/base.vue` as well.
        // see: https://gitlab.com/gitlab-org/gitlab/merge_requests/4773#note_61844731
        if ($selectbox.length) {
          const isVisible = Boolean($selectbox.get(0).offsetParent);
          $selectbox.toggle(!isVisible);
          $block.find('.js-value').toggle(isVisible);
 
          if ($selectbox.get(0).offsetParent) {
            setTimeout(() => $block.find('.js-label-select').trigger('click'), 0);
          }
        }
      });
 
    window.addEventListener('beforeunload', () => {
      // collapsed_gutter cookie hides the sidebar
      const bpBreakpoint = bp.getBreakpointSize();
      if (bpBreakpoint === 'xs' || bpBreakpoint === 'sm' || bpBreakpoint === 'md') {
        setCookie('collapsed_gutter', true);
      }
    });
  }
}