Skip to content
Snippets Groups Projects
Unverified Commit 07647a67 authored by Phil Hughes's avatar Phil Hughes
Browse files

Hide apply batch suggestion button for single suggestions

This only shows the apply batch suggestion when there is
more than 1 suggestion.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/224141
parent 893b2585
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -45,7 +45,7 @@ export default {
},
},
computed: {
...mapGetters(['getDiscussion']),
...mapGetters(['getDiscussion', 'suggestionsCount']),
discussion() {
if (!this.note.isDraft) return {};
 
Loading
Loading
@@ -125,6 +125,7 @@ export default {
<suggestions
v-if="hasSuggestion && !isEditing"
:suggestions="note.suggestions"
:suggestions-count="suggestionsCount"
:batch-suggestions-info="batchSuggestionsInfo"
:note-html="note.note_html"
:line-type="lineType"
Loading
Loading
Loading
Loading
@@ -231,3 +231,6 @@ export const getDiscussion = state => discussionId =>
state.discussions.find(discussion => discussion.id === discussionId);
 
export const commentsDisabled = state => state.commentsDisabled;
export const suggestionsCount = (state, getters) =>
Object.values(getters.notesById).filter(n => n.suggestions.length).length;
Loading
Loading
@@ -27,6 +27,11 @@ export default {
type: String,
required: true,
},
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
},
computed: {
batchSuggestionsCount() {
Loading
Loading
@@ -62,6 +67,7 @@ export default {
<div class="md-suggestion">
<suggestion-diff-header
class="qa-suggestion-diff-header js-suggestion-diff-header"
:suggestions-count="suggestionsCount"
:can-apply="suggestion.appliable && suggestion.current_user.can_apply && !disabled"
:is-applied="suggestion.applied"
:is-batched="isBatched"
Loading
Loading
Loading
Loading
@@ -42,6 +42,11 @@ export default {
required: false,
default: null,
},
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
},
data() {
return {
Loading
Loading
@@ -127,7 +132,7 @@ export default {
</div>
<div v-else class="d-flex align-items-center">
<gl-button
v-if="canBeBatched && !isDisableButton"
v-if="suggestionsCount > 1 && canBeBatched && !isDisableButton"
class="btn-inverted js-add-to-batch-btn btn-grouped"
:disabled="isDisableButton"
@click="addSuggestionToBatch"
Loading
Loading
Loading
Loading
@@ -38,6 +38,11 @@ export default {
type: String,
required: true,
},
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
},
data() {
return {
Loading
Loading
@@ -77,12 +82,12 @@ export default {
this.isRendered = true;
},
generateDiff(suggestionIndex) {
const { suggestions, disabled, batchSuggestionsInfo, helpPagePath } = this;
const { suggestions, disabled, batchSuggestionsInfo, helpPagePath, suggestionsCount } = this;
const suggestion =
suggestions && suggestions[suggestionIndex] ? suggestions[suggestionIndex] : {};
const SuggestionDiffComponent = Vue.extend(SuggestionDiff);
const suggestionDiff = new SuggestionDiffComponent({
propsData: { disabled, suggestion, batchSuggestionsInfo, helpPagePath },
propsData: { disabled, suggestion, batchSuggestionsInfo, helpPagePath, suggestionsCount },
});
 
suggestionDiff.$on('apply', ({ suggestionId, callback }) => {
Loading
Loading
---
title: Hides batch suggestions button if there is only 1 suggestion
merge_request:
author:
type: fixed
Loading
Loading
@@ -57,7 +57,9 @@ describe('Suggestion Diff component', () => {
});
 
it('renders apply suggestion and add to batch buttons', () => {
createComponent();
createComponent({
suggestionsCount: 2,
});
 
const applyBtn = findApplyButton();
const addToBatchBtn = findAddToBatchButton();
Loading
Loading
@@ -104,7 +106,9 @@ describe('Suggestion Diff component', () => {
 
describe('when add to batch is clicked', () => {
it('emits addToBatch', () => {
createComponent();
createComponent({
suggestionsCount: 2,
});
 
findAddToBatchButton().vm.$emit('click');
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment