2022-07-23 23:45:48 +05:30
|
|
|
<script>
|
2022-08-27 11:52:29 +05:30
|
|
|
import $ from 'jquery';
|
2022-10-11 01:57:18 +05:30
|
|
|
import {
|
|
|
|
GlDropdown,
|
|
|
|
GlButton,
|
|
|
|
GlIcon,
|
|
|
|
GlForm,
|
|
|
|
GlFormGroup,
|
|
|
|
GlLink,
|
|
|
|
GlFormCheckbox,
|
|
|
|
} from '@gitlab/ui';
|
2022-07-23 23:45:48 +05:30
|
|
|
import { mapGetters, mapActions } from 'vuex';
|
2022-10-11 01:57:18 +05:30
|
|
|
import { createAlert } from '~/flash';
|
2022-07-23 23:45:48 +05:30
|
|
|
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
|
|
|
|
import { scrollToElement } from '~/lib/utils/common_utils';
|
2022-08-27 11:52:29 +05:30
|
|
|
import Autosave from '~/autosave';
|
|
|
|
import { helpPagePath } from '~/helpers/help_page_helper';
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlDropdown,
|
|
|
|
GlButton,
|
|
|
|
GlIcon,
|
|
|
|
GlForm,
|
|
|
|
GlFormGroup,
|
2022-08-27 11:52:29 +05:30
|
|
|
GlLink,
|
2022-10-11 01:57:18 +05:30
|
|
|
GlFormCheckbox,
|
2022-07-23 23:45:48 +05:30
|
|
|
MarkdownField,
|
2022-10-11 01:57:18 +05:30
|
|
|
ApprovalPassword: () => import('ee_component/batch_comments/components/approval_password.vue'),
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isSubmitting: false,
|
2022-10-11 01:57:18 +05:30
|
|
|
noteData: {
|
|
|
|
noteable_type: '',
|
|
|
|
noteable_id: '',
|
|
|
|
note: '',
|
|
|
|
approve: false,
|
|
|
|
approval_password: '',
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters(['getNotesData', 'getNoteableData', 'noteableType', 'getCurrentUserLastNote']),
|
|
|
|
},
|
2022-10-11 01:57:18 +05:30
|
|
|
watch: {
|
|
|
|
'noteData.approve': function noteDataApproveWatch() {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.repositionDropdown();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2022-08-13 15:12:31 +05:30
|
|
|
mounted() {
|
2022-08-27 11:52:29 +05:30
|
|
|
this.autosave = new Autosave(
|
|
|
|
$(this.$refs.textarea),
|
|
|
|
`submit_review_dropdown/${this.getNoteableData.id}`,
|
|
|
|
);
|
2022-10-11 01:57:18 +05:30
|
|
|
this.noteData.noteable_type = this.noteableType;
|
|
|
|
this.noteData.noteable_id = this.getNoteableData.id;
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
// 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
|
2022-10-11 01:57:18 +05:30
|
|
|
const originalClickOutHandler = this.$refs.submitDropdown.$refs.dropdown.clickOutHandler;
|
|
|
|
this.$refs.submitDropdown.$refs.dropdown.clickOutHandler = (e) => {
|
2022-08-13 15:12:31 +05:30
|
|
|
if (!e.target.closest('.atwho-container')) {
|
|
|
|
originalClickOutHandler(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
methods: {
|
|
|
|
...mapActions('batchComments', ['publishReview']),
|
2022-10-11 01:57:18 +05:30
|
|
|
repositionDropdown() {
|
|
|
|
this.$refs.submitDropdown?.$refs.dropdown?.updatePopper();
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
async submitReview() {
|
|
|
|
this.isSubmitting = true;
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
try {
|
|
|
|
await this.publishReview(this.noteData);
|
|
|
|
|
|
|
|
this.autosave.reset();
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
if (window.mrTabs && (this.noteData.note || this.noteData.approve)) {
|
|
|
|
if (this.noteData.note) {
|
|
|
|
window.location.hash = `note_${this.getCurrentUserLastNote.id}`;
|
|
|
|
}
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
window.mrTabs.tabShown('show');
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
setTimeout(() =>
|
|
|
|
scrollToElement(document.getElementById(`note_${this.getCurrentUserLastNote.id}`)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
if (e.data?.message) {
|
|
|
|
createAlert({ message: e.data.message, captureError: true });
|
|
|
|
}
|
2022-07-23 23:45:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
this.isSubmitting = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
restrictedToolbarItems: ['full-screen'],
|
2022-08-27 11:52:29 +05:30
|
|
|
helpPagePath: helpPagePath('user/project/merge_requests/reviews/index.html', {
|
|
|
|
anchor: 'submit-a-review',
|
|
|
|
}),
|
2022-07-23 23:45:48 +05:30
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-08-13 15:12:31 +05:30
|
|
|
<gl-dropdown
|
2022-10-11 01:57:18 +05:30
|
|
|
ref="submitDropdown"
|
2022-08-13 15:12:31 +05:30
|
|
|
right
|
2022-10-11 01:57:18 +05:30
|
|
|
dropup
|
2022-08-13 15:12:31 +05:30
|
|
|
class="submit-review-dropdown"
|
2022-08-27 11:52:29 +05:30
|
|
|
data-qa-selector="submit_review_dropdown"
|
2022-08-13 15:12:31 +05:30
|
|
|
variant="info"
|
2022-08-27 11:52:29 +05:30
|
|
|
category="primary"
|
2022-08-13 15:12:31 +05:30
|
|
|
>
|
2022-07-23 23:45:48 +05:30
|
|
|
<template #button-content>
|
|
|
|
{{ __('Finish review') }}
|
|
|
|
<gl-icon class="dropdown-chevron" name="chevron-up" />
|
|
|
|
</template>
|
|
|
|
<gl-form data-testid="submit-gl-form" @submit.prevent="submitReview">
|
2022-08-27 11:52:29 +05:30
|
|
|
<gl-form-group label-for="review-note-body" label-class="gl-mb-2">
|
|
|
|
<template #label>
|
|
|
|
{{ __('Summary comment (optional)') }}
|
|
|
|
<gl-link
|
|
|
|
:href="$options.helpPagePath"
|
|
|
|
:aria-label="__('More information')"
|
|
|
|
target="_blank"
|
|
|
|
class="gl-ml-2"
|
|
|
|
>
|
|
|
|
<gl-icon name="question-o" />
|
|
|
|
</gl-link>
|
|
|
|
</template>
|
2022-07-23 23:45:48 +05:30
|
|
|
<div class="common-note-form gfm-form">
|
|
|
|
<div
|
|
|
|
class="comment-warning-wrapper gl-border-solid gl-border-1 gl-rounded-base gl-border-gray-100"
|
|
|
|
>
|
|
|
|
<markdown-field
|
|
|
|
:is-submitting="isSubmitting"
|
|
|
|
:add-spacing-classes="false"
|
2022-10-11 01:57:18 +05:30
|
|
|
:textarea-value="noteData.note"
|
2022-07-23 23:45:48 +05:30
|
|
|
:markdown-preview-path="getNoteableData.preview_note_path"
|
|
|
|
:markdown-docs-path="getNotesData.markdownDocsPath"
|
|
|
|
:quick-actions-docs-path="getNotesData.quickActionsDocsPath"
|
|
|
|
:restricted-tool-bar-items="$options.restrictedToolbarItems"
|
|
|
|
:force-autosize="false"
|
|
|
|
class="js-no-autosize"
|
|
|
|
>
|
|
|
|
<template #textarea>
|
|
|
|
<textarea
|
|
|
|
id="review-note-body"
|
|
|
|
ref="textarea"
|
2022-10-11 01:57:18 +05:30
|
|
|
v-model="noteData.note"
|
2022-07-23 23:45:48 +05:30
|
|
|
dir="auto"
|
|
|
|
:disabled="isSubmitting"
|
|
|
|
name="review[note]"
|
|
|
|
class="note-textarea js-gfm-input markdown-area"
|
|
|
|
data-supports-quick-actions="true"
|
|
|
|
data-testid="comment-textarea"
|
|
|
|
:aria-label="__('Comment')"
|
|
|
|
:placeholder="__('Write a comment or drag your files here…')"
|
|
|
|
@keydown.meta.enter="submitReview"
|
|
|
|
@keydown.ctrl.enter="submitReview"
|
|
|
|
></textarea>
|
|
|
|
</template>
|
|
|
|
</markdown-field>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</gl-form-group>
|
2022-10-11 01:57:18 +05:30
|
|
|
<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>
|
2022-08-27 11:52:29 +05:30
|
|
|
<div class="gl-display-flex gl-justify-content-start gl-mt-5">
|
2022-07-23 23:45:48 +05:30
|
|
|
<gl-button
|
|
|
|
:loading="isSubmitting"
|
|
|
|
variant="confirm"
|
|
|
|
type="submit"
|
|
|
|
class="js-no-auto-disable"
|
|
|
|
data-testid="submit-review-button"
|
2022-08-27 11:52:29 +05:30
|
|
|
data-qa-selector="submit_review_button"
|
2022-07-23 23:45:48 +05:30
|
|
|
>
|
|
|
|
{{ __('Submit review') }}
|
|
|
|
</gl-button>
|
|
|
|
</div>
|
|
|
|
</gl-form>
|
|
|
|
</gl-dropdown>
|
|
|
|
</template>
|