summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issuable_suggestions/components/app.vue
blob: ac5f04147d334c9c0903ea47c618c2c69f43d5cc (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
92
93
94
<script>
import { GlTooltipDirective, GlIcon } from '@gitlab/ui';
import { __ } from '~/locale';
import Suggestion from './item.vue';
import query from '../queries/issues.query.graphql';

export default {
  components: {
    Suggestion,
    GlIcon,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    projectPath: {
      type: String,
      required: true,
    },
    search: {
      type: String,
      required: true,
    },
  },
  apollo: {
    issues: {
      query,
      debounce: 1000,
      skip() {
        return this.isSearchEmpty;
      },
      update: (data) => data.project.issues.edges.map(({ node }) => node),
      variables() {
        return {
          fullPath: this.projectPath,
          search: this.search,
        };
      },
    },
  },
  data() {
    return {
      issues: [],
      loading: 0,
    };
  },
  computed: {
    isSearchEmpty() {
      return !this.search.length;
    },
    showSuggestions() {
      return !this.isSearchEmpty && this.issues.length && !this.loading;
    },
  },
  watch: {
    search() {
      if (this.isSearchEmpty) {
        this.issues = [];
      }
    },
  },
  helpText: __(
    'These existing issues have a similar title. It might be better to comment there instead of creating another similar issue.',
  ),
};
</script>

<template>
  <div v-show="showSuggestions" class="form-group row issuable-suggestions">
    <div v-once class="col-form-label col-sm-2 pt-0">
      {{ __('Similar issues') }}
      <gl-icon
        v-gl-tooltip.bottom
        :title="$options.helpText"
        :aria-label="$options.helpText"
        name="question-o"
        class="text-secondary suggestion-help-hover"
      />
    </div>
    <div class="col-sm-10">
      <ul class="list-unstyled m-0">
        <li
          v-for="(suggestion, index) in issues"
          :key="suggestion.id"
          :class="{
            'gl-mb-3': index !== issues.length - 1,
          }"
        >
          <suggestion :suggestion="suggestion" />
        </li>
      </ul>
    </div>
  </div>
</template>