summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_merge_request_widget/components/states/mr_widget_merged.js
blob: 9fe4f91a157d960b053d820353e399a7bccaa1be (plain)
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
117
118
119
120
import mrWidgetAuthorTime from '../../components/mr_widget_author_time';
import eventHub from '../../event_hub';

export default {
  name: 'MRWidgetMerged',
  props: {
    mr: { type: Object, required: true },
    service: { type: Object, required: true },
  },
  components: {
    'mr-widget-author-and-time': mrWidgetAuthorTime,
  },
  data() {
    return {
      isMakingRequest: false,
    };
  },
  computed: {
    shouldShowRemoveSourceBranch() {
      const { isRemovingSourceBranch, canRemoveSourceBranch } = this.mr;

      return canRemoveSourceBranch && !this.isMakingRequest && !isRemovingSourceBranch;
    },
    shouldShowSourceBranchRemoving() {
      return this.isMakingRequest || this.mr.isRemovingSourceBranch;
    },

    shouldShowRevertForCurrentMR() {
      return this.mr.canBeReverted && this.mr.userCanCollaborateWithProject;
    },

    // TODO: Remove UJS
    shouldShowRevertForForkMR() {
      return this.mr.canBeReverted && this.mr.userCanForkProject;
    },

    shouldShowCherryPickForCurrentMR() {
      return this.mr.canBeCherryPicked && this.mr.userCanCollaborateWithProject;
    },

    // TODO: Remove UJS
    shouldShowCherryPickForForkMR() {
      return this.mr.canBeCherryPicked && this.mr.userCanForkProject;
    },
  },
  methods: {
    removeSourceBranch() {
      this.isMakingRequest = true;
      // TODO: Error handling
      this.service.removeSourceBranch()
        .then(res => res.json())
        .then((res) => {
          if (res.message === 'Branch was removed') {
            eventHub.$emit('MRWidgetUpdateRequested', () => {
              this.isMakingRequest = false;
            });
          }
        });
    },
  },
  template: `
    <div class="mr-widget-body">
      <mr-widget-author-and-time
        actionText="Merged by"
        :author="mr.mergedBy"
        :dateTitle="mr.updatedAt"
        :dateReadable="mr.mergedAt"
      />
      <section class="mr-info-list">
        <div class="legend"></div>
        <p>
          The changes were merged into
          <span class="label-branch">
            <a :href="mr.targetBranchPath">{{mr.targetBranch}}</a>
          </span>
        </p>
        <p v-if="mr.sourceBranchRemoved">The source branch has been removed.</p>
        <p v-if="shouldShowRemoveSourceBranch">
          You can remove source branch now.
          <button
            @click="removeSourceBranch"
            :class="{ disabled: isMakingRequest }"
            type="button" class="btn btn-xs btn-default">Remove Source Branch</button>
        </p>
        <p v-if="shouldShowSourceBranchRemoving">
          The source branch is being removed.
          <i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
        </p>
      </section>
      <div class="merged-buttons clearfix">
        <a
          v-if="shouldShowRevertForCurrentMR"
          class="btn btn-close btn-sm has-tooltip"
          href="#modal-revert-commit"
          data-toggle="modal"
          data-container="body"
          data-original-title="Revert this merge request in a new merge request">Revert</a>
        <a
          v-else-if="shouldShowRevertForForkMR"
          class="btn btn-close btn-sm has-tooltip"
          data-method='post'
          :href="mr.revertInForkPath"
          data-original-title="Revert this merge request in a new merge request">Revert</a>
        <a
          v-if="shouldShowCherryPickForCurrentMR"
          class="btn btn-default btn-sm has-tooltip"
          href="#modal-cherry-pick-commit"
          data-toggle="modal"
          data-container="body"
          data-original-title="Cherry-pick this merge request in a new merge request">Cherry-pick</a>
        <a
          v-else-if="shouldShowCherryPickForForkMR"
          class="btn btn-default btn-sm has-tooltip"
          data-method='post'
          :href="mr.cherryPickInForkPath"
          data-original-title="Cherry-pick this merge request in a new merge request">Cherry-pick</a>
      </div>
    </div>
  `,
};