All files / ee/app/assets/javascripts/filtered_search issuable_filtered_search_token_keys.js

94.11% Statements 16/17
100% Branches 0/0
83.33% Functions 5/6
93.33% Lines 14/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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166                                  5x                   5x                 5x                 5x                                                     5x                                                     5x                                                               15x 5x   5x                       4x     2x   2x 2x               4x          
import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys';
import {
  tokenKeys,
  alternativeTokenKeys,
  conditions,
} from '~/filtered_search/issuable_filtered_search_token_keys';
import { __ } from '~/locale';
import {
  TOKEN_TITLE_EPIC,
  TOKEN_TITLE_ITERATION,
  TOKEN_TITLE_WEIGHT,
  TOKEN_TYPE_ASSIGNEE,
  TOKEN_TYPE_EPIC,
  TOKEN_TYPE_ITERATION,
  TOKEN_TYPE_WEIGHT,
} from 'ee/vue_shared/components/filtered_search_bar/constants';
 
export const weightTokenKey = {
  formattedKey: TOKEN_TITLE_WEIGHT,
  key: TOKEN_TYPE_WEIGHT,
  type: 'string',
  param: '',
  symbol: '',
  icon: 'weight',
  tag: 'number',
};
 
export const epicTokenKey = {
  formattedKey: TOKEN_TITLE_EPIC,
  key: TOKEN_TYPE_EPIC,
  type: 'string',
  param: 'id',
  symbol: '&',
  icon: 'epic',
};
 
export const iterationTokenKey = {
  formattedKey: TOKEN_TITLE_ITERATION,
  key: TOKEN_TYPE_ITERATION,
  type: 'string',
  param: 'title',
  symbol: '',
  icon: 'iteration',
};
 
export const weightConditions = [
  {
    url: 'weight=None',
    operator: '=',
    tokenKey: TOKEN_TYPE_WEIGHT,
    value: __('None'),
  },
  {
    url: 'weight=Any',
    operator: '=',
    tokenKey: TOKEN_TYPE_WEIGHT,
    value: __('Any'),
  },
  {
    url: 'not[weight]=None',
    operator: '!=',
    tokenKey: TOKEN_TYPE_WEIGHT,
    value: __('None'),
  },
  {
    url: 'not[weight]=Any',
    operator: '!=',
    tokenKey: TOKEN_TYPE_WEIGHT,
    value: __('Any'),
  },
];
 
export const epicConditions = [
  {
    url: 'epic_id=None',
    operator: '=',
    tokenKey: TOKEN_TYPE_EPIC,
    value: __('None'),
  },
  {
    url: 'epic_id=Any',
    operator: '=',
    tokenKey: TOKEN_TYPE_EPIC,
    value: __('Any'),
  },
  {
    url: 'not[epic_id]=None',
    operator: '!=',
    tokenKey: TOKEN_TYPE_EPIC,
    value: __('None'),
  },
  {
    url: 'not[epic_id]=Any',
    operator: '!=',
    tokenKey: TOKEN_TYPE_EPIC,
    value: __('Any'),
  },
];
 
export const iterationConditions = [
  {
    url: 'iteration_id=None',
    operator: '=',
    tokenKey: TOKEN_TYPE_ITERATION,
    value: __('None'),
  },
  {
    url: 'iteration_id=Any',
    operator: '=',
    tokenKey: TOKEN_TYPE_ITERATION,
    value: __('Any'),
  },
  {
    url: 'iteration_id=Current',
    operator: '=',
    tokenKey: TOKEN_TYPE_ITERATION,
    value: __('Current'),
  },
  {
    url: 'not[iteration_id]=Current',
    operator: '!=',
    tokenKey: TOKEN_TYPE_ITERATION,
    value: __('Current'),
  },
];
 
/**
 * Filter tokens for issues in EE.
 */
class IssuesFilteredSearchTokenKeysEE extends FilteredSearchTokenKeys {
  constructor() {
    const milestoneTokenKeyIndex = tokenKeys.findIndex((tk) => tk.key === 'milestone');
    tokenKeys.splice(milestoneTokenKeyIndex + 1, 0, iterationTokenKey);
 
    super([...tokenKeys, epicTokenKey, weightTokenKey], alternativeTokenKeys, [
      ...conditions,
      ...weightConditions,
      ...epicConditions,
      ...iterationConditions,
    ]);
  }
 
  /**
   * Changes assignee token to accept multiple values.
   */
  enableMultipleAssignees() {
    const assigneeTokenKey = this.tokenKeys.find((tk) => tk.key === TOKEN_TYPE_ASSIGNEE);
 
    // Add the original as an alternative token key
    this.tokenKeysWithAlternative.push({ ...assigneeTokenKey });
 
    assigneeTokenKey.type = 'array';
    assigneeTokenKey.param = 'username[]';
  }
 
  removeEpicToken() {
    this.removeTokensForKeys(epicTokenKey.key);
  }
 
  removeIterationToken() {
    this.removeTokensForKeys(iterationTokenKey.key);
  }
}
 
export default new IssuesFilteredSearchTokenKeysEE();