All files / app/assets/javascripts/vue_merge_request_widget/components/states mr_widget_merged.vue

60% Statements 21/35
53.33% Branches 8/15
89.47% Functions 17/19
60% Lines 21/35

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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168                  3x                                           13x           17x   17x                       13x     13x     13x     13x     17x   17x 17x                               17x 17x                               17x 5x             17x       13x       2x       2x           1x             1x                                                                      
<script>
import { GlTooltipDirective } from '@gitlab/ui';
import api from '~/api';
import { createAlert } from '~/alert';
import { s__, __ } from '~/locale';
import { OPEN_REVERT_MODAL, OPEN_CHERRY_PICK_MODAL } from '~/projects/commit/constants';
import modalEventHub from '~/projects/commit/event_hub';
import eventHub from '../../event_hub';
import MrWidgetAuthorTime from '../mr_widget_author_time.vue';
import StateContainer from '../state_container.vue';
 
export default {
  name: 'MRWidgetMerged',
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  components: {
    MrWidgetAuthorTime,
    StateContainer,
  },
  props: {
    mr: {
      type: Object,
      required: true,
    },
    service: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isMakingRequest: false,
    };
  },
  computed: {
    shouldShowRemoveSourceBranch() {
      const { sourceBranchRemoved, isRemovingSourceBranch, canRemoveSourceBranch } = this.mr;
 
      return (
        !sourceBranchRemoved &&
        canRemoveSourceBranch &&
        !this.isMakingRequest &&
        !isRemovingSourceBranch
      );
    },
    shouldShowSourceBranchRemoving() {
      const { sourceBranchRemoved, isRemovingSourceBranch } = this.mr;
      return !sourceBranchRemoved && (isRemovingSourceBranch || this.isMakingRequest);
    },
    revertTitle() {
      return s__('mrWidget|Revert this merge request in a new merge request');
    },
    cherryPickTitle() {
      return s__('mrWidget|Cherry-pick this merge request in a new merge request');
    },
    revertLabel() {
      return s__('mrWidget|Revert');
    },
    cherryPickLabel() {
      return s__('mrWidget|Cherry-pick');
    },
    actions() {
      const actions = [];
 
      if (this.mr.canRevertInCurrentMR) {
        actions.push({
          text: this.revertLabel,
          tooltipText: this.revertTitle,
          testId: 'revert-button',
          onClick: () => this.openRevertModal(),
        });
      } else IEif (this.mr.revertInForkPath) {
        actions.push({
          text: this.revertLabel,
          tooltipText: this.revertTitle,
          href: this.mr.revertInForkPath,
          testId: 'revert-button',
          dataMethod: 'post',
        });
      }
 
      if (this.mr.canCherryPickInCurrentMR) {
        actions.push({
          text: this.cherryPickLabel,
          tooltipText: this.cherryPickTitle,
          testId: 'cherry-pick-button',
          onClick: () => this.openCherryPickModal(),
        });
      } else IEif (this.mr.cherryPickInForkPath) {
        actions.push({
          text: this.cherryPickLabel,
          tooltipText: this.cherryPickTitle,
          href: this.mr.cherryPickInForkPath,
          testId: 'cherry-pick-button',
          dataMethod: 'post',
        });
      }
 
      if (this.shouldShowRemoveSourceBranch) {
        actions.push({
          text: s__('mrWidget|Delete source branch'),
          class: 'js-remove-branch-button',
          onClick: () => this.removeSourceBranch(),
        });
      }
 
      return actions;
    },
  },
  mounted() {
    document.dispatchEvent(new CustomEvent('merged:UpdateActions'));
  },
  methods: {
    removeSourceBranch() {
      this.isMakingRequest = true;
 
      api.trackRedisHllUserEvent('i_code_review_post_merge_delete_branch');
 
      this.service
        .removeSourceBranch()
        .then((res) => res.data)
        .then((data) => {
          // False positive i18n lint: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26
          // eslint-disable-next-line @gitlab/require-i18n-strings
          if (data.message === 'Branch was deleted') {
            eventHub.$emit('MRWidgetUpdateRequested', () => {
              this.isMakingRequest = false;
            });
          }
        })
        .catch(() => {
          this.isMakingRequest = false;
          createAlert({
            message: __('Something went wrong. Please try again.'),
          });
        });
    },
    openRevertModal() {
      api.trackRedisHllUserEvent('i_code_review_post_merge_click_revert');
 
      modalEventHub.$emit(OPEN_REVERT_MODAL);
    },
    openCherryPickModal() {
      api.trackRedisHllUserEvent('i_code_review_post_merge_click_cherry_pick');
 
      modalEventHub.$emit(OPEN_CHERRY_PICK_MODAL);
    },
  },
};
</script>
<template>
  <state-container
    :actions="actions"
    status="merged"
    is-collapsible
    :collapsed="mr.mergeDetailsCollapsed"
    @toggle="() => mr.toggleMergeDetails()"
  >
    <mr-widget-author-time
      :action-text="s__('mrWidget|Merged by')"
      :author="mr.metrics.mergedBy"
      :date-title="mr.metrics.mergedAt"
      :date-readable="mr.metrics.readableMergedAt"
    />
  </state-container>
</template>