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.

80 lines
2.4 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
2023-04-23 21:23:45 +05:30
import { GlIcon, GlDisclosureDropdown, GlButton } from '@gitlab/ui';
2021-06-08 01:23:25 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
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: {
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,
2023-04-23 21:23:45 +05:30
GlDisclosureDropdown,
GlButton,
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']),
2023-04-23 21:23:45 +05:30
listItems() {
const sortedDraftCount = this.sortedDrafts.length - 1;
return this.sortedDrafts.map((item, index) => ({
text: item.id.toString(),
action: () => {
this.onClickDraft(item);
},
last: index === sortedDraftCount,
...item,
}));
},
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']),
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>
2023-04-23 21:23:45 +05:30
<gl-disclosure-dropdown :items="listItems" dropup data-qa-selector="review_preview_dropdown">
<template #toggle>
2023-05-27 22:25:52 +05:30
<gl-button>
{{ __('Pending comments') }}
<drafts-count variant="neutral" />
<gl-icon class="dropdown-chevron" name="chevron-up" />
</gl-button>
2023-04-23 21:23:45 +05:30
</template>
<template #header>
2023-05-27 22:25:52 +05:30
<div
class="gl-display-flex gl-align-items-center gl-p-4! gl-min-h-8 gl-border-b-1 gl-border-b-solid gl-border-b-gray-200"
>
<span class="gl-flex-grow-1 gl-font-weight-bold gl-font-sm gl-pr-2">
{{ n__('%d pending comment', '%d pending comments', draftsCount) }}
</span>
</div>
2023-04-23 21:23:45 +05:30
</template>
<template #list-item="{ item }">
2023-05-27 22:25:52 +05:30
<preview-item :draft="item" :is-last="item.last" />
2021-01-03 14:25:43 +05:30
</template>
2023-04-23 21:23:45 +05:30
</gl-disclosure-dropdown>
2020-06-23 00:09:42 +05:30
</template>