All files / app/assets/javascripts/filtered_search dropdown_user.js

81.81% Statements 9/11
80% Branches 4/5
85.71% Functions 6/7
81.81% Lines 9/11

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 44 45 46 47 48 49 50 51 52 53 54 55            7x               7x                               2x       4x       4x       7x 7x 7x         7x          
import { ACTIVE_AND_BLOCKED_USER_STATES } from '~/users_select/constants';
import { addClassIfElementExists } from '../lib/utils/dom_utils';
import DropdownAjaxFilter from './dropdown_ajax_filter';
 
export default class DropdownUser extends DropdownAjaxFilter {
  constructor(options = {}) {
    super({
      ...options,
      endpoint: `${gon.relative_url_root || ''}/-/autocomplete/users.json`,
      symbol: '@',
    });
  }
 
  ajaxFilterConfig() {
    return {
      ...super.ajaxFilterConfig(),
      params: {
        states: ACTIVE_AND_BLOCKED_USER_STATES,
        group_id: this.getGroupId(),
        project_id: this.getProjectId(),
        current_user: true,
        ...this.projectOrGroupId(),
      },
      onLoadingFinished: () => {
        this.hideCurrentUser();
      },
    };
  }
 
  hideCurrentUser() {
    addClassIfElementExists(this.dropdown.querySelector('.js-current-user'), 'hidden');
  }
 
  getGroupId() {
    return this.input.dataset.groupId;
  }
 
  getProjectId() {
    return this.input.dataset.projectId;
  }
 
  projectOrGroupId() {
    const projectId = this.getProjectId();
    const groupId = this.getGroupId();
    Iif (groupId) {
      return {
        group_id: groupId,
      };
    }
    return {
      project_id: projectId,
    };
  }
}