diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-25 18:12:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-25 18:12:14 +0300 |
commit | 5f85444a43df1c5f025b520fdbc682cbf95d3ca0 (patch) | |
tree | a224ff70de072fe19ff19c0bfec2c5cafe966cc5 /app/assets/javascripts/batch_comments | |
parent | 73507eaf1a77c5c05ae17c9f7ac29bbeb8bf5be1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/batch_comments')
-rw-r--r-- | app/assets/javascripts/batch_comments/components/submit_dropdown.vue | 84 | ||||
-rw-r--r-- | app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js | 6 |
2 files changed, 68 insertions, 22 deletions
diff --git a/app/assets/javascripts/batch_comments/components/submit_dropdown.vue b/app/assets/javascripts/batch_comments/components/submit_dropdown.vue index 54b9953270b..c5b713b5447 100644 --- a/app/assets/javascripts/batch_comments/components/submit_dropdown.vue +++ b/app/assets/javascripts/batch_comments/components/submit_dropdown.vue @@ -1,7 +1,16 @@ <script> import $ from 'jquery'; -import { GlDropdown, GlButton, GlIcon, GlForm, GlFormGroup, GlLink } from '@gitlab/ui'; +import { + GlDropdown, + GlButton, + GlIcon, + GlForm, + GlFormGroup, + GlLink, + GlFormCheckbox, +} from '@gitlab/ui'; import { mapGetters, mapActions } from 'vuex'; +import { createAlert } from '~/flash'; import MarkdownField from '~/vue_shared/components/markdown/field.vue'; import { scrollToElement } from '~/lib/utils/common_utils'; import Autosave from '~/autosave'; @@ -15,29 +24,46 @@ export default { GlForm, GlFormGroup, GlLink, + GlFormCheckbox, MarkdownField, + ApprovalPassword: () => import('ee_component/batch_comments/components/approval_password.vue'), }, data() { return { isSubmitting: false, - note: '', + noteData: { + noteable_type: '', + noteable_id: '', + note: '', + approve: false, + approval_password: '', + }, }; }, computed: { ...mapGetters(['getNotesData', 'getNoteableData', 'noteableType', 'getCurrentUserLastNote']), }, + watch: { + 'noteData.approve': function noteDataApproveWatch() { + setTimeout(() => { + this.repositionDropdown(); + }); + }, + }, mounted() { this.autosave = new Autosave( $(this.$refs.textarea), `submit_review_dropdown/${this.getNoteableData.id}`, ); + this.noteData.noteable_type = this.noteableType; + this.noteData.noteable_id = this.getNoteableData.id; // We override the Bootstrap Vue click outside behaviour // to allow for clicking in the autocomplete dropdowns // without this override the submit dropdown will close // whenever a item in the autocomplete dropdown is clicked - const originalClickOutHandler = this.$refs.dropdown.$refs.dropdown.clickOutHandler; - this.$refs.dropdown.$refs.dropdown.clickOutHandler = (e) => { + const originalClickOutHandler = this.$refs.submitDropdown.$refs.dropdown.clickOutHandler; + this.$refs.submitDropdown.$refs.dropdown.clickOutHandler = (e) => { if (!e.target.closest('.atwho-container')) { originalClickOutHandler(e); } @@ -45,26 +71,29 @@ export default { }, methods: { ...mapActions('batchComments', ['publishReview']), + repositionDropdown() { + this.$refs.submitDropdown?.$refs.dropdown?.updatePopper(); + }, async submitReview() { - const noteData = { - noteable_type: this.noteableType, - noteable_id: this.getNoteableData.id, - note: this.note, - }; - this.isSubmitting = true; - await this.publishReview(noteData); + try { + await this.publishReview(this.noteData); - this.autosave.reset(); + this.autosave.reset(); - if (window.mrTabs && this.note) { - window.location.hash = `note_${this.getCurrentUserLastNote.id}`; - window.mrTabs.tabShown('show'); + if (window.mrTabs && this.note) { + window.location.hash = `note_${this.getCurrentUserLastNote.id}`; + window.mrTabs.tabShown('show'); - setTimeout(() => - scrollToElement(document.getElementById(`note_${this.getCurrentUserLastNote.id}`)), - ); + setTimeout(() => + scrollToElement(document.getElementById(`note_${this.getCurrentUserLastNote.id}`)), + ); + } + } catch (e) { + if (e.data?.message) { + createAlert({ message: e.data.message, captureError: true }); + } } this.isSubmitting = false; @@ -79,8 +108,9 @@ export default { <template> <gl-dropdown - ref="dropdown" + ref="submitDropdown" right + dropup class="submit-review-dropdown" data-qa-selector="submit_review_dropdown" variant="info" @@ -110,7 +140,7 @@ export default { <markdown-field :is-submitting="isSubmitting" :add-spacing-classes="false" - :textarea-value="note" + :textarea-value="noteData.note" :markdown-preview-path="getNoteableData.preview_note_path" :markdown-docs-path="getNotesData.markdownDocsPath" :quick-actions-docs-path="getNotesData.quickActionsDocsPath" @@ -122,7 +152,7 @@ export default { <textarea id="review-note-body" ref="textarea" - v-model="note" + v-model="noteData.note" dir="auto" :disabled="isSubmitting" name="review[note]" @@ -139,6 +169,18 @@ export default { </div> </div> </gl-form-group> + <template v-if="getNoteableData.current_user.can_approve"> + <gl-form-checkbox v-model="noteData.approve" data-testid="approve_merge_request"> + {{ __('Approve merge request') }} + </gl-form-checkbox> + <approval-password + v-if="getNoteableData.require_password_to_approve" + v-show="noteData.approve" + v-model="noteData.approval_password" + class="gl-mt-3" + data-testid="approve_password" + /> + </template> <div class="gl-display-flex gl-justify-content-start gl-mt-5"> <gl-button :loading="isSubmitting" diff --git a/app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js b/app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js index a44b9827fe9..2b0aaa74e83 100644 --- a/app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js +++ b/app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js @@ -84,7 +84,11 @@ export const publishReview = ({ commit, dispatch, getters }, noteData = {}) => { .publish(getters.getNotesData.draftsPublishPath, noteData) .then(() => dispatch('updateDiscussionsAfterPublish')) .then(() => commit(types.RECEIVE_PUBLISH_REVIEW_SUCCESS)) - .catch(() => commit(types.RECEIVE_PUBLISH_REVIEW_ERROR)); + .catch((e) => { + commit(types.RECEIVE_PUBLISH_REVIEW_ERROR); + + throw e.response; + }); }; export const updateDiscussionsAfterPublish = async ({ dispatch, getters, rootGetters }) => { |