summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/merge_requests/list.vue
blob: 04b3848f3e29d39f237ff064f5f262a0fc0519d4 (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
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
<script>
import _ from 'underscore';
import LoadingIcon from '../../../vue_shared/components/loading_icon.vue';
import Item from './item.vue';

export default {
  components: {
    LoadingIcon,
    Item,
  },
  props: {
    isLoading: {
      type: Boolean,
      required: true,
    },
    items: {
      type: Array,
      required: true,
    },
    currentId: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      search: '',
    };
  },
  watch: {
    isLoading() {
      this.focusSearch();
    },
  },
  methods: {
    viewMergeRequest(item) {
      this.$router.push(`/project/${item.projectPathWithNamespace}/merge_requests/${item.iid}`);
    },
    searchMergeRequests: _.debounce(function debounceSearch() {
      this.$emit('search', this.search);
    }, 250),
    focusSearch() {
      if (!this.isLoading) {
        this.$nextTick(() => {
          this.$refs.searchInput.focus();
        });
      }
    },
  },
};
</script>

<template>
  <div>
    <loading-icon
      class="mt-3 mb-3"
      v-if="isLoading"
      size="2"
    />
    <template v-else>
      <div class="dropdown-input mt-3 pb-3 mb-3 border-bottom">
        <input
          type="search"
          class="dropdown-input-field"
          placeholder="Search merge requests"
          v-model="search"
          @input="searchMergeRequests"
          ref="searchInput"
        />
        <i
          aria-hidden="true"
          class="fa fa-search dropdown-input-search"
        ></i>
      </div>
      <div class="dropdown-content">
        <ul class="mb-3">
          <li
            v-for="item in items"
            :key="item.id"
          >
            <item
              :item="item"
              :current-id="currentId"
              @click="viewMergeRequest"
            />
          </li>
        </ul>
      </div>
    </template>
  </div>
</template>