Commit a34a2a77 authored by Phil Hughes's avatar Phil Hughes Committed by Kushal Pandya

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 ca421dc9
...@@ -45,7 +45,7 @@ export default { ...@@ -45,7 +45,7 @@ export default {
}, },
}, },
computed: { computed: {
...mapGetters(['getDiscussion']), ...mapGetters(['getDiscussion', 'suggestionsCount']),
discussion() { discussion() {
if (!this.note.isDraft) return {}; if (!this.note.isDraft) return {};
...@@ -125,6 +125,7 @@ export default { ...@@ -125,6 +125,7 @@ export default {
<suggestions <suggestions
v-if="hasSuggestion && !isEditing" v-if="hasSuggestion && !isEditing"
:suggestions="note.suggestions" :suggestions="note.suggestions"
:suggestions-count="suggestionsCount"
:batch-suggestions-info="batchSuggestionsInfo" :batch-suggestions-info="batchSuggestionsInfo"
:note-html="note.note_html" :note-html="note.note_html"
:line-type="lineType" :line-type="lineType"
......
...@@ -231,3 +231,6 @@ export const getDiscussion = state => discussionId => ...@@ -231,3 +231,6 @@ export const getDiscussion = state => discussionId =>
state.discussions.find(discussion => discussion.id === discussionId); state.discussions.find(discussion => discussion.id === discussionId);
export const commentsDisabled = state => state.commentsDisabled; export const commentsDisabled = state => state.commentsDisabled;
export const suggestionsCount = (state, getters) =>
Object.values(getters.notesById).filter(n => n.suggestions.length).length;
...@@ -27,6 +27,11 @@ export default { ...@@ -27,6 +27,11 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
}, },
computed: { computed: {
batchSuggestionsCount() { batchSuggestionsCount() {
...@@ -62,6 +67,7 @@ export default { ...@@ -62,6 +67,7 @@ export default {
<div class="md-suggestion"> <div class="md-suggestion">
<suggestion-diff-header <suggestion-diff-header
class="qa-suggestion-diff-header js-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" :can-apply="suggestion.appliable && suggestion.current_user.can_apply && !disabled"
:is-applied="suggestion.applied" :is-applied="suggestion.applied"
:is-batched="isBatched" :is-batched="isBatched"
......
...@@ -42,6 +42,11 @@ export default { ...@@ -42,6 +42,11 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
}, },
data() { data() {
return { return {
...@@ -127,7 +132,7 @@ export default { ...@@ -127,7 +132,7 @@ export default {
</div> </div>
<div v-else class="d-flex align-items-center"> <div v-else class="d-flex align-items-center">
<gl-button <gl-button
v-if="canBeBatched && !isDisableButton" v-if="suggestionsCount > 1 && canBeBatched && !isDisableButton"
class="btn-inverted js-add-to-batch-btn btn-grouped" class="btn-inverted js-add-to-batch-btn btn-grouped"
:disabled="isDisableButton" :disabled="isDisableButton"
@click="addSuggestionToBatch" @click="addSuggestionToBatch"
......
...@@ -38,6 +38,11 @@ export default { ...@@ -38,6 +38,11 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
}, },
data() { data() {
return { return {
...@@ -77,12 +82,12 @@ export default { ...@@ -77,12 +82,12 @@ export default {
this.isRendered = true; this.isRendered = true;
}, },
generateDiff(suggestionIndex) { generateDiff(suggestionIndex) {
const { suggestions, disabled, batchSuggestionsInfo, helpPagePath } = this; const { suggestions, disabled, batchSuggestionsInfo, helpPagePath, suggestionsCount } = this;
const suggestion = const suggestion =
suggestions && suggestions[suggestionIndex] ? suggestions[suggestionIndex] : {}; suggestions && suggestions[suggestionIndex] ? suggestions[suggestionIndex] : {};
const SuggestionDiffComponent = Vue.extend(SuggestionDiff); const SuggestionDiffComponent = Vue.extend(SuggestionDiff);
const suggestionDiff = new SuggestionDiffComponent({ const suggestionDiff = new SuggestionDiffComponent({
propsData: { disabled, suggestion, batchSuggestionsInfo, helpPagePath }, propsData: { disabled, suggestion, batchSuggestionsInfo, helpPagePath, suggestionsCount },
}); });
suggestionDiff.$on('apply', ({ suggestionId, callback }) => { suggestionDiff.$on('apply', ({ suggestionId, callback }) => {
......
---
title: Hides batch suggestions button if there is only 1 suggestion
merge_request: 42681
author:
type: fixed
...@@ -130,7 +130,9 @@ RSpec.describe 'User comments on a diff', :js do ...@@ -130,7 +130,9 @@ RSpec.describe 'User comments on a diff', :js do
wait_for_requests wait_for_requests
end end
end end
end
files.each_with_index do |file, index|
page.within("[id='#{file[:hash]}']") do page.within("[id='#{file[:hash]}']") do
expect(page).not_to have_content('Applied') expect(page).not_to have_content('Applied')
......
...@@ -10,6 +10,7 @@ exports[`Suggestion Diff component matches snapshot 1`] = ` ...@@ -10,6 +10,7 @@ exports[`Suggestion Diff component matches snapshot 1`] = `
helppagepath="path_to_docs" helppagepath="path_to_docs"
isapplyingbatch="true" isapplyingbatch="true"
isbatched="true" isbatched="true"
suggestionscount="0"
/> />
<table <table
......
...@@ -57,7 +57,9 @@ describe('Suggestion Diff component', () => { ...@@ -57,7 +57,9 @@ describe('Suggestion Diff component', () => {
}); });
it('renders apply suggestion and add to batch buttons', () => { it('renders apply suggestion and add to batch buttons', () => {
createComponent(); createComponent({
suggestionsCount: 2,
});
const applyBtn = findApplyButton(); const applyBtn = findApplyButton();
const addToBatchBtn = findAddToBatchButton(); const addToBatchBtn = findAddToBatchButton();
...@@ -104,7 +106,9 @@ describe('Suggestion Diff component', () => { ...@@ -104,7 +106,9 @@ describe('Suggestion Diff component', () => {
describe('when add to batch is clicked', () => { describe('when add to batch is clicked', () => {
it('emits addToBatch', () => { it('emits addToBatch', () => {
createComponent(); createComponent({
suggestionsCount: 2,
});
findAddToBatchButton().vm.$emit('click'); findAddToBatchButton().vm.$emit('click');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment