debian-mirror-gitlab/app/assets/javascripts/batch_comments/components/preview_dropdown.vue

54 lines
1.4 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
2021-01-03 14:25:43 +05:30
import { GlDropdown, GlDropdownItem, GlIcon } from '@gitlab/ui';
2021-06-08 01:23:25 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2020-06-23 00:09:42 +05:30
import PreviewItem from './preview_item.vue';
export default {
components: {
2021-01-03 14:25:43 +05:30
GlDropdown,
GlDropdownItem,
2020-11-24 15:15:51 +05:30
GlIcon,
2020-06-23 00:09:42 +05:30
PreviewItem,
},
computed: {
2021-06-08 01:23:25 +05:30
...mapState('diffs', ['viewDiffsFileByFile']),
2020-06-23 00:09:42 +05:30
...mapGetters('batchComments', ['draftsCount', 'sortedDrafts']),
},
methods: {
2021-12-11 22:18:48 +05:30
...mapActions('diffs', ['setCurrentFileHash']),
2021-01-03 14:25:43 +05:30
...mapActions('batchComments', ['scrollToDraft']),
2020-06-23 00:09:42 +05:30
isLast(index) {
return index === this.sortedDrafts.length - 1;
},
2021-06-08 01:23:25 +05:30
async onClickDraft(draft) {
if (this.viewDiffsFileByFile && draft.file_hash) {
2021-12-11 22:18:48 +05:30
await this.setCurrentFileHash(draft.file_hash);
2021-06-08 01:23:25 +05:30
}
await this.scrollToDraft(draft);
},
2020-06-23 00:09:42 +05:30
},
};
</script>
<template>
2021-01-03 14:25:43 +05:30
<gl-dropdown
:header-text="n__('%d pending comment', '%d pending comments', draftsCount)"
dropup
2021-06-08 01:23:25 +05:30
data-qa-selector="review_preview_dropdown"
2020-06-23 00:09:42 +05:30
>
2021-01-03 14:25:43 +05:30
<template #button-content>
{{ __('Pending comments') }}
<gl-icon class="dropdown-chevron" name="chevron-up" />
</template>
<gl-dropdown-item
v-for="(draft, index) in sortedDrafts"
:key="draft.id"
2021-06-08 01:23:25 +05:30
data-testid="preview-item"
@click="onClickDraft(draft)"
2020-06-23 00:09:42 +05:30
>
2021-01-03 14:25:43 +05:30
<preview-item :draft="draft" :is-last="isLast(index)" />
</gl-dropdown-item>
</gl-dropdown>
2020-06-23 00:09:42 +05:30
</template>