summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/filtered_search/dropdown_label.js.es6
blob: af47ad2a1f8ce8bcb7a3853af9e8ee758e1d5b44 (plain)
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
/* eslint-disable no-param-reassign */
/*= require filtered_search/filtered_search_dropdown */

((global) => {
  class DropdownLabel extends gl.FilteredSearchDropdown {
    constructor(droplab, dropdown, input) {
      super(droplab, dropdown, input);
      this.listId = 'js-dropdown-label';
      this.filterSymbol = '~';
    }

    itemClicked(e) {
      const dataValueSet = this.setDataValueIfSelected(e.detail.selected);

      if (!dataValueSet) {
        const labelTitle = e.detail.selected.querySelector('.label-title').innerText.trim();
        const labelName = `~${this.getEscapedText(labelTitle)}`;
        gl.FilteredSearchManager.addWordToInput(labelName);
      }

      this.dismissDropdown();
    }

    renderContent() {
      // TODO: Pass elements instead of querySelectors
      // TODO: Don't bind filterWithSymbol to (this), just pass the symbol
      this.droplab.changeHookList(this.hookId, '#js-dropdown-label', [droplabAjax, droplabFilter], {
        droplabAjax: {
          endpoint: 'labels.json',
          method: 'setData',
        },
        droplabFilter: {
          filterFunction: this.filterWithSymbol.bind(this),
        }
      });
    }
  }

  global.DropdownLabel = DropdownLabel;
})(window.gl || (window.gl = {}));