Welcome to mirror list, hosted at ThFree Co, Russian Federation.

weight_token.vue « tokens « filtered_search_bar « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 280fb23457609350f16ccb74c1a69c317a62ce30 (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
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
<script>
import { GlFilteredSearchSuggestion } from '@gitlab/ui';
import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_token.vue';
import { DEFAULT_NONE_ANY, WEIGHT_TOKEN_SUGGESTIONS_SIZE } from '../constants';

const weights = Array.from(Array(WEIGHT_TOKEN_SUGGESTIONS_SIZE), (_, index) => index.toString());

export default {
  components: {
    BaseToken,
    GlFilteredSearchSuggestion,
  },
  props: {
    active: {
      type: Boolean,
      required: true,
    },
    config: {
      type: Object,
      required: true,
    },
    value: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      weights,
    };
  },
  computed: {
    defaultWeights() {
      return this.config.defaultWeights || DEFAULT_NONE_ANY;
    },
  },
  methods: {
    getActiveWeight(weightSuggestions, data) {
      return weightSuggestions.find((weight) => weight === data);
    },
    updateWeights(searchTerm) {
      const weight = parseInt(searchTerm, 10);
      this.weights = Number.isNaN(weight) ? weights : [String(weight)];
    },
  },
};
</script>

<template>
  <base-token
    :active="active"
    :config="config"
    :value="value"
    :default-suggestions="defaultWeights"
    :suggestions="weights"
    :get-active-token-value="getActiveWeight"
    @fetch-suggestions="updateWeights"
    v-on="$listeners"
  >
    <template #suggestions-list="{ suggestions }">
      <gl-filtered-search-suggestion v-for="weight of suggestions" :key="weight" :value="weight">
        {{ weight }}
      </gl-filtered-search-suggestion>
    </template>
  </base-token>
</template>