All files / app/assets/javascripts/sidebar/components/reviewers sidebar_reviewers.vue

0% Statements 0/31
0% Branches 0/4
0% Functions 0/10
0% Lines 0/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116                                                                                                                                                                                                                                       
<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
import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests';
import createFlash from '~/flash';
import { __ } from '~/locale';
import eventHub from '~/sidebar/event_hub';
import Store from '~/sidebar/stores/sidebar_store';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import ReviewerTitle from './reviewer_title.vue';
import Reviewers from './reviewers.vue';
 
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,
    },
  },
  data() {
    return {
      store: new Store(),
      loading: false,
    };
  },
  computed: {
    relativeUrlRoot() {
      return gon.relative_url_root ?? '';
    },
  },
  created() {
    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: {
    saveReviewers() {
      this.loading = true;
 
      this.mediator
        .saveReviewers(this.field)
        .then(() => {
          this.loading = false;
          refreshUserMergeRequestCounts();
        })
        .catch(() => {
          this.loading = false;
          return createFlash({
            message: __('Error occurred when saving reviewers'),
          });
        });
    },
    requestReview(data) {
      this.mediator.requestReview(data);
    },
    toggleAttentionRequested(data) {
      this.mediator.toggleAttentionRequested('reviewer', data);
    },
  },
};
</script>
 
<template>
  <div>
    <reviewer-title
      :number-of-reviewers="store.reviewers.length"
      :loading="loading || store.isFetching.reviewers"
      :editable="store.editable"
    />
    <reviewers
      v-if="!store.isFetching.reviewers"
      :root-path="relativeUrlRoot"
      :users="store.reviewers"
      :editable="store.editable"
      :issuable-type="issuableType"
      @request-review="requestReview"
      @toggle-attention-requested="toggleAttentionRequested"
    />
  </div>
</template>