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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2.1 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';
2022-07-23 23:45:48 +05:30
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2022-08-13 15:12:31 +05:30
import { setUrlParams, visitUrl } from '~/lib/utils/url_utility';
2020-06-23 00:09:42 +05:30
import PreviewItem from './preview_item.vue';
2022-07-23 23:45:48 +05:30
import DraftsCount from './drafts_count.vue';
2020-06-23 00:09:42 +05:30
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,
2022-07-23 23:45:48 +05:30
DraftsCount,
2020-06-23 00:09:42 +05:30
},
2022-07-23 23:45:48 +05:30
mixins: [glFeatureFlagMixin()],
2020-06-23 00:09:42 +05:30
computed: {
2021-06-08 01:23:25 +05:30
...mapState('diffs', ['viewDiffsFileByFile']),
2020-06-23 00:09:42 +05:30
...mapGetters('batchComments', ['draftsCount', 'sortedDrafts']),
2022-08-13 15:12:31 +05:30
...mapGetters(['getNoteableData']),
2020-06-23 00:09:42 +05:30
},
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;
},
2022-08-13 15:12:31 +05:30
isOnLatestDiff(draft) {
return draft.position?.head_sha === this.getNoteableData.diff_head_sha;
},
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
}
2022-08-13 15:12:31 +05:30
if (draft.position && !this.isOnLatestDiff(draft)) {
const url = new URL(setUrlParams({ commit_id: draft.position.head_sha }));
url.hash = `note_${draft.id}`;
visitUrl(url.toString());
} else {
await this.scrollToDraft(draft);
}
2021-06-08 01:23:25 +05:30
},
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') }}
2022-07-23 23:45:48 +05:30
<drafts-count v-if="glFeatures.mrReviewSubmitComment" variant="neutral" />
2021-01-03 14:25:43 +05:30
<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>