debian-mirror-gitlab/app/assets/javascripts/issues/new/components/title_suggestions.vue

95 lines
2 KiB
Vue
Raw Normal View History

2019-02-15 15:39:39 +05:30
<script>
2020-11-24 15:15:51 +05:30
import { GlTooltipDirective, GlIcon } from '@gitlab/ui';
2019-02-15 15:39:39 +05:30
import { __ } from '~/locale';
2019-09-30 21:07:59 +05:30
import query from '../queries/issues.query.graphql';
2022-01-26 12:08:38 +05:30
import TitleSuggestionsItem from './title_suggestions_item.vue';
2019-02-15 15:39:39 +05:30
export default {
components: {
2020-11-24 15:15:51 +05:30
GlIcon,
2022-01-26 12:08:38 +05:30
TitleSuggestionsItem,
2019-02-15 15:39:39 +05:30
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
projectPath: {
type: String,
required: true,
},
search: {
type: String,
required: true,
},
},
apollo: {
issues: {
query,
debounce: 1000,
skip() {
return this.isSearchEmpty;
},
2021-03-08 18:12:59 +05:30
update: (data) => data.project.issues.edges.map(({ node }) => node),
2019-02-15 15:39:39 +05:30
variables() {
return {
fullPath: this.projectPath,
search: this.search,
};
},
},
},
data() {
return {
issues: [],
loading: 0,
};
},
computed: {
isSearchEmpty() {
2020-04-08 14:13:33 +05:30
return !this.search.length;
2019-02-15 15:39:39 +05:30
},
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>
2022-01-26 12:08:38 +05:30
<div v-show="showSuggestions" class="form-group row">
2019-02-15 15:39:39 +05:30
<div v-once class="col-form-label col-sm-2 pt-0">
{{ __('Similar issues') }}
2020-11-24 15:15:51 +05:30
<gl-icon
2019-02-15 15:39:39 +05:30
v-gl-tooltip.bottom
:title="$options.helpText"
:aria-label="$options.helpText"
name="question-o"
2021-11-18 22:05:49 +05:30
class="text-secondary gl-cursor-help"
2019-02-15 15:39:39 +05:30
/>
</div>
<div class="col-sm-10">
<ul class="list-unstyled m-0">
<li
v-for="(suggestion, index) in issues"
:key="suggestion.id"
:class="{
2020-07-28 23:09:34 +05:30
'gl-mb-3': index !== issues.length - 1,
2019-02-15 15:39:39 +05:30
}"
>
2022-01-26 12:08:38 +05:30
<title-suggestions-item :suggestion="suggestion" />
2019-02-15 15:39:39 +05:30
</li>
</ul>
</div>
</div>
</template>