2020-06-01 02:08:21 -04:00
|
|
|
<script>
|
|
|
|
import { mapActions, mapGetters, mapState } from 'vuex';
|
2020-09-16 20:09:34 -04:00
|
|
|
import { GlButton, GlLoadingIcon, GlIcon } from '@gitlab/ui';
|
2020-06-01 02:08:21 -04:00
|
|
|
import { sprintf, n__ } from '~/locale';
|
|
|
|
import DraftsCount from './drafts_count.vue';
|
|
|
|
import PublishButton from './publish_button.vue';
|
|
|
|
import PreviewItem from './preview_item.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2020-08-24 14:10:19 -04:00
|
|
|
GlButton,
|
2020-09-16 20:09:34 -04:00
|
|
|
GlLoadingIcon,
|
2020-08-24 11:10:11 -04:00
|
|
|
GlIcon,
|
2020-06-01 02:08:21 -04:00
|
|
|
DraftsCount,
|
|
|
|
PublishButton,
|
|
|
|
PreviewItem,
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters(['isNotesFetched']),
|
|
|
|
...mapGetters('batchComments', ['draftsCount', 'sortedDrafts']),
|
|
|
|
...mapState('batchComments', ['showPreviewDropdown']),
|
|
|
|
dropdownTitle() {
|
|
|
|
return sprintf(
|
|
|
|
n__('%{count} pending comment', '%{count} pending comments', this.draftsCount),
|
|
|
|
{ count: this.draftsCount },
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
showPreviewDropdown() {
|
|
|
|
if (this.showPreviewDropdown && this.$refs.dropdown) {
|
2020-08-24 14:10:19 -04:00
|
|
|
this.$nextTick(() => this.$refs.dropdown.$el.focus());
|
2020-06-01 02:08:21 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('click', this.onClickDocument);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
document.removeEventListener('click', this.onClickDocument);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('batchComments', ['toggleReviewDropdown']),
|
|
|
|
isLast(index) {
|
|
|
|
return index === this.sortedDrafts.length - 1;
|
|
|
|
},
|
|
|
|
onClickDocument({ target }) {
|
|
|
|
if (
|
|
|
|
this.showPreviewDropdown &&
|
|
|
|
!target.closest('.review-preview-dropdown, .js-publish-draft-button')
|
|
|
|
) {
|
|
|
|
this.toggleReviewDropdown();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
class="dropdown float-right review-preview-dropdown"
|
|
|
|
:class="{
|
|
|
|
show: showPreviewDropdown,
|
|
|
|
}"
|
|
|
|
>
|
2020-08-24 14:10:19 -04:00
|
|
|
<gl-button
|
2020-06-01 02:08:21 -04:00
|
|
|
ref="dropdown"
|
|
|
|
type="button"
|
2020-08-24 14:10:19 -04:00
|
|
|
category="primary"
|
|
|
|
variant="success"
|
|
|
|
class="review-preview-dropdown-toggle qa-review-preview-toggle"
|
2020-06-01 02:08:21 -04:00
|
|
|
@click="toggleReviewDropdown"
|
|
|
|
>
|
|
|
|
{{ __('Finish review') }}
|
|
|
|
<drafts-count />
|
2020-08-24 11:10:11 -04:00
|
|
|
<gl-icon name="angle-up" />
|
2020-08-24 14:10:19 -04:00
|
|
|
</gl-button>
|
2020-06-01 02:08:21 -04:00
|
|
|
<div
|
|
|
|
class="dropdown-menu dropdown-menu-large dropdown-menu-right dropdown-open-top"
|
|
|
|
:class="{
|
|
|
|
show: showPreviewDropdown,
|
|
|
|
}"
|
|
|
|
>
|
2020-09-16 20:09:34 -04:00
|
|
|
<div class="dropdown-title gl-display-flex gl-align-items-center">
|
|
|
|
<span class="gl-ml-auto">{{ dropdownTitle }}</span>
|
|
|
|
<gl-button
|
2020-06-01 02:08:21 -04:00
|
|
|
:aria-label="__('Close')"
|
|
|
|
type="button"
|
2020-09-16 20:09:34 -04:00
|
|
|
category="tertiary"
|
|
|
|
size="small"
|
|
|
|
class="dropdown-title-button gl-ml-auto gl-p-0!"
|
|
|
|
icon="close"
|
2020-06-01 02:08:21 -04:00
|
|
|
@click="toggleReviewDropdown"
|
2020-09-16 20:09:34 -04:00
|
|
|
/>
|
2020-06-01 02:08:21 -04:00
|
|
|
</div>
|
|
|
|
<div class="dropdown-content">
|
|
|
|
<ul v-if="isNotesFetched">
|
|
|
|
<li v-for="(draft, index) in sortedDrafts" :key="draft.id">
|
|
|
|
<preview-item :draft="draft" :is-last="isLast(index)" />
|
|
|
|
</li>
|
|
|
|
</ul>
|
2020-06-26 02:09:03 -04:00
|
|
|
<gl-loading-icon v-else size="lg" class="gl-mt-3 gl-mb-3" />
|
2020-06-01 02:08:21 -04:00
|
|
|
</div>
|
|
|
|
<div class="dropdown-footer">
|
|
|
|
<publish-button
|
|
|
|
:show-count="false"
|
|
|
|
:should-publish="true"
|
|
|
|
:label="__('Submit review')"
|
2020-06-01 11:08:16 -04:00
|
|
|
class="float-right gl-mr-3"
|
2020-06-01 02:08:21 -04:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|