debian-mirror-gitlab/app/assets/javascripts/sidebar/components/reviewers/sidebar_reviewers.vue

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

195 lines
5.3 KiB
Vue
Raw Normal View History

2021-01-03 14:25:43 +05:30
<script>
// NOTE! For the first iteration, we are simply copying the implementation of Assignees
// It will soon be overhauled in Issue https://gitlab.com/gitlab-org/gitlab/-/issues/233736
2022-08-27 11:52:29 +05:30
import Vue from 'vue';
2021-03-08 18:12:59 +05:30
import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests';
2022-11-25 23:54:43 +05:30
import { createAlert } from '~/flash';
2021-03-11 19:13:27 +05:30
import { __ } from '~/locale';
2021-01-03 14:25:43 +05:30
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2023-01-13 00:05:48 +05:30
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2023-03-04 22:38:38 +05:30
import eventHub from '../../event_hub';
import getMergeRequestReviewersQuery from '../../queries/get_merge_request_reviewers.query.graphql';
import mergeRequestReviewersUpdatedSubscription from '../../queries/merge_request_reviewers.subscription.graphql';
import Store from '../../stores/sidebar_store';
2021-01-03 14:25:43 +05:30
import ReviewerTitle from './reviewer_title.vue';
import Reviewers from './reviewers.vue';
2022-08-27 11:52:29 +05:30
export const state = Vue.observable({
issuable: {},
loading: false,
initialLoading: true,
});
2021-01-03 14:25:43 +05:30
export default {
name: 'SidebarReviewers',
components: {
ReviewerTitle,
Reviewers,
},
mixins: [glFeatureFlagsMixin()],
props: {
mediator: {
type: Object,
required: true,
},
field: {
type: String,
required: true,
},
issuableType: {
type: String,
required: false,
default: 'issue',
},
issuableIid: {
type: String,
required: true,
},
projectPath: {
type: String,
required: true,
},
},
2022-08-27 11:52:29 +05:30
apollo: {
issuable: {
query: getMergeRequestReviewersQuery,
variables() {
return {
iid: this.issuableIid,
fullPath: this.projectPath,
};
},
update(data) {
return data.workspace?.issuable;
},
result() {
this.initialLoading = false;
},
error() {
2022-11-25 23:54:43 +05:30
createAlert({ message: __('An error occurred while fetching reviewers.') });
2022-08-27 11:52:29 +05:30
},
2023-01-13 00:05:48 +05:30
subscribeToMore: {
document() {
return mergeRequestReviewersUpdatedSubscription;
},
variables() {
return {
issuableId: this.issuable?.id,
};
},
skip() {
return !this.issuable?.id || !this.isRealtimeEnabled;
},
updateQuery(
_,
{
subscriptionData: {
data: { mergeRequestReviewersUpdated },
},
},
) {
if (mergeRequestReviewersUpdated) {
this.store.setReviewersFromRealtime(
mergeRequestReviewersUpdated.reviewers.nodes.map((r) => ({
...r,
id: getIdFromGraphQLId(r.id),
})),
);
}
},
},
2022-08-27 11:52:29 +05:30
},
},
2021-01-03 14:25:43 +05:30
data() {
2022-08-27 11:52:29 +05:30
return state;
2021-01-03 14:25:43 +05:30
},
computed: {
relativeUrlRoot() {
return gon.relative_url_root ?? '';
},
2022-08-27 11:52:29 +05:30
reviewers() {
return this.issuable.reviewers?.nodes || [];
},
graphqlFetching() {
return this.$apollo.queries.issuable.loading;
},
isLoading() {
return this.loading || this.$apollo.queries.issuable.loading;
},
canUpdate() {
2022-11-25 23:54:43 +05:30
return this.issuable.userPermissions?.adminMergeRequest || false;
2022-08-27 11:52:29 +05:30
},
2023-01-13 00:05:48 +05:30
isRealtimeEnabled() {
return this.glFeatures.realtimeReviewers;
},
2021-01-03 14:25:43 +05:30
},
created() {
2022-08-27 11:52:29 +05:30
this.store = new Store();
2021-01-03 14:25:43 +05:30
this.removeReviewer = this.store.removeReviewer.bind(this.store);
this.addReviewer = this.store.addReviewer.bind(this.store);
this.removeAllReviewers = this.store.removeAllReviewers.bind(this.store);
// Get events from deprecatedJQueryDropdown
eventHub.$on('sidebar.removeReviewer', this.removeReviewer);
eventHub.$on('sidebar.addReviewer', this.addReviewer);
eventHub.$on('sidebar.removeAllReviewers', this.removeAllReviewers);
eventHub.$on('sidebar.saveReviewers', this.saveReviewers);
},
beforeDestroy() {
eventHub.$off('sidebar.removeReviewer', this.removeReviewer);
eventHub.$off('sidebar.addReviewer', this.addReviewer);
eventHub.$off('sidebar.removeAllReviewers', this.removeAllReviewers);
eventHub.$off('sidebar.saveReviewers', this.saveReviewers);
},
methods: {
2023-03-04 22:38:38 +05:30
reviewBySelf() {
// Notify gl dropdown that we are now assigning to current user
this.$el.parentElement.dispatchEvent(new Event('assignYourself'));
this.mediator.addSelfReview();
this.saveReviewers();
},
2021-01-03 14:25:43 +05:30
saveReviewers() {
this.loading = true;
this.mediator
.saveReviewers(this.field)
.then(() => {
this.loading = false;
2021-03-08 18:12:59 +05:30
refreshUserMergeRequestCounts();
2022-08-27 11:52:29 +05:30
this.$apollo.queries.issuable.refetch();
2021-01-03 14:25:43 +05:30
})
.catch(() => {
this.loading = false;
2022-11-25 23:54:43 +05:30
return createAlert({
2021-09-30 23:02:18 +05:30
message: __('Error occurred when saving reviewers'),
});
2021-01-03 14:25:43 +05:30
});
},
2021-03-11 19:13:27 +05:30
requestReview(data) {
this.mediator.requestReview(data);
},
2021-01-03 14:25:43 +05:30
},
};
</script>
<template>
<div>
<reviewer-title
2022-08-27 11:52:29 +05:30
:number-of-reviewers="reviewers.length"
:loading="isLoading"
:editable="canUpdate"
2021-01-03 14:25:43 +05:30
/>
<reviewers
2022-08-27 11:52:29 +05:30
v-if="!initialLoading"
2021-01-03 14:25:43 +05:30
:root-path="relativeUrlRoot"
2022-08-27 11:52:29 +05:30
:users="reviewers"
:editable="canUpdate"
2021-01-03 14:25:43 +05:30
:issuable-type="issuableType"
2021-03-11 19:13:27 +05:30
@request-review="requestReview"
2023-03-04 22:38:38 +05:30
@assign-self="reviewBySelf"
2021-01-03 14:25:43 +05:30
/>
</div>
</template>