diff --git a/app/assets/javascripts/vue_shared/components/markdown/suggestion_diff_header.vue b/app/assets/javascripts/vue_shared/components/markdown/suggestion_diff_header.vue index d5434c63d63a4134228c869342cba26b01236e36..e26ff51e01e35d4820965b754d0ccd69413ffae6 100644 --- a/app/assets/javascripts/vue_shared/components/markdown/suggestion_diff_header.vue +++ b/app/assets/javascripts/vue_shared/components/markdown/suggestion_diff_header.vue @@ -2,10 +2,12 @@ import { GlDeprecatedButton, GlLoadingIcon, GlTooltipDirective } from '@gitlab/ui'; import Icon from '~/vue_shared/components/icon.vue'; import { __ } from '~/locale'; +import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; export default { components: { Icon, GlDeprecatedButton, GlLoadingIcon }, directives: { 'gl-tooltip': GlTooltipDirective }, + mixins: [glFeatureFlagsMixin()], props: { batchSuggestionsCount: { type: Number, @@ -43,6 +45,9 @@ export default { }; }, computed: { + canBeBatched() { + return Boolean(this.glFeatures.batchSuggestions); + }, isApplying() { return this.isApplyingSingle || this.isApplyingBatch; }, @@ -51,6 +56,11 @@ export default { ? __('This also resolves the discussion') : __("Can't apply as this line has changed or the suggestion already matches its content."); }, + tooltipMessageBatch() { + return !this.canBeBatched + ? __("Suggestions that change line count can't be added to batches, yet.") + : this.tooltipMessage; + }, isDisableButton() { return this.isApplying || !this.canApply; }, @@ -97,7 +107,7 @@ export default { <gl-loading-icon class="d-flex-center mr-2" /> <span>{{ applyingSuggestionsMessage }}</span> </div> - <div v-else-if="canApply && isBatched" class="d-flex align-items-center"> + <div v-else-if="canApply && canBeBatched && isBatched" class="d-flex align-items-center"> <gl-deprecated-button class="btn-inverted js-remove-from-batch-btn btn-grouped" :disabled="isApplying" @@ -119,13 +129,15 @@ export default { </gl-deprecated-button> </div> <div v-else class="d-flex align-items-center"> - <gl-deprecated-button - class="btn-inverted js-add-to-batch-btn btn-grouped" - :disabled="isDisableButton" - @click="addSuggestionToBatch" - > - {{ __('Add suggestion to batch') }} - </gl-deprecated-button> + <span v-if="canBeBatched" v-gl-tooltip.viewport="tooltipMessageBatch" tabindex="0"> + <gl-deprecated-button + class="btn-inverted js-add-to-batch-btn btn-grouped" + :disabled="isDisableButton" + @click="addSuggestionToBatch" + > + {{ __('Add suggestion to batch') }} + </gl-deprecated-button> + </span> <span v-gl-tooltip.viewport="tooltipMessage" tabindex="0"> <gl-deprecated-button class="btn-inverted js-apply-btn btn-grouped" diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index d3c6a6f6f4ae0fe7d2f45b3cbd3fe9a7a2e97616..55556ea7d3173639d5caf0e16267047286505f09 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -35,6 +35,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo push_frontend_feature_flag(:mr_commit_neighbor_nav, @project, default_enabled: true) push_frontend_feature_flag(:multiline_comments, @project) push_frontend_feature_flag(:file_identifier_hash) + push_frontend_feature_flag(:batch_suggestions, @project) end before_action do diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 8a062a719e9ce8d9b846bfa853cfa95df5ad9296..9b343c7f013ad5bef3f85ad136c332ab6606ec1f 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -21877,6 +21877,9 @@ msgstr "" msgid "Suggestions must all be on the same branch." msgstr "" +msgid "Suggestions that change line count can't be added to batches, yet." +msgstr "" + msgid "Suggestions:" msgstr "" diff --git a/spec/frontend/vue_shared/components/markdown/suggestion_diff_header_spec.js b/spec/frontend/vue_shared/components/markdown/suggestion_diff_header_spec.js index a31b923a71903aafd31d30bc2d7f2c041f485a30..9a5b95b555f1f7ae702e1d72f3a3fda7967096ab 100644 --- a/spec/frontend/vue_shared/components/markdown/suggestion_diff_header_spec.js +++ b/spec/frontend/vue_shared/components/markdown/suggestion_diff_header_spec.js @@ -14,12 +14,18 @@ const DEFAULT_PROPS = { describe('Suggestion Diff component', () => { let wrapper; - const createComponent = props => { + const createComponent = (props, glFeatures = {}) => { wrapper = shallowMount(SuggestionDiffHeader, { propsData: { ...DEFAULT_PROPS, ...props, }, + provide: { + glFeatures: { + batchSuggestions: true, + ...glFeatures, + }, + }, }); }; @@ -204,6 +210,18 @@ describe('Suggestion Diff component', () => { }); }); + describe('batchSuggestions feature flag is set to false', () => { + beforeEach(() => { + createComponent({}, { batchSuggestions: false }); + }); + + it('disables add to batch buttons but keeps apply suggestion enabled', () => { + expect(findApplyButton().exists()).toBe(true); + expect(findAddToBatchButton().exists()).toBe(false); + expect(findApplyButton().attributes('disabled')).not.toBe('true'); + }); + }); + describe('canApply is set to false', () => { beforeEach(() => { createComponent({ canApply: false });