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 {
},
},
computed: {
...mapGetters(['getDiscussion']),
...mapGetters(['getDiscussion', 'suggestionsCount']),
discussion() {
if (!this.note.isDraft) return {};
......@@ -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"
......
......@@ -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;
......@@ -27,6 +27,11 @@ export default {
type: String,
required: true,
},
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
},
computed: {
batchSuggestionsCount() {
......@@ -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"
......
......@@ -42,6 +42,11 @@ export default {
required: false,
default: null,
},
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
},
data() {
return {
......@@ -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"
......
......@@ -38,6 +38,11 @@ export default {
type: String,
required: true,
},
suggestionsCount: {
type: Number,
required: false,
default: 0,
},
},
data() {
return {
......@@ -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 }) => {
......
---
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
wait_for_requests
end
end
end
files.each_with_index do |file, index|
page.within("[id='#{file[:hash]}']") do
expect(page).not_to have_content('Applied')
......
......@@ -10,6 +10,7 @@ exports[`Suggestion Diff component matches snapshot 1`] = `
helppagepath="path_to_docs"
isapplyingbatch="true"
isbatched="true"
suggestionscount="0"
/>
<table
......
......@@ -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();
......@@ -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');
......
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