summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/commit/components/commit_options_dropdown.vue
blob: d96d1035ed079dc73136153bf5f3a6cb9a263505 (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
<script>
import { GlDropdown, GlDropdownItem, GlDropdownDivider, GlDropdownSectionHeader } from '@gitlab/ui';
import { OPEN_REVERT_MODAL, OPEN_CHERRY_PICK_MODAL } from '../constants';
import eventHub from '../event_hub';

export default {
  components: {
    GlDropdown,
    GlDropdownItem,
    GlDropdownDivider,
    GlDropdownSectionHeader,
  },
  inject: {
    newProjectTagPath: {
      default: '',
    },
    emailPatchesPath: {
      default: '',
    },
    plainDiffPath: {
      default: '',
    },
  },
  props: {
    canRevert: {
      type: Boolean,
      required: true,
    },
    canCherryPick: {
      type: Boolean,
      required: true,
    },
    canTag: {
      type: Boolean,
      required: true,
    },
    canEmailPatches: {
      type: Boolean,
      required: true,
    },
  },
  computed: {
    showDivider() {
      return this.canRevert || this.canCherryPick || this.canTag;
    },
  },
  methods: {
    showModal(modalId) {
      eventHub.$emit(modalId);
    },
  },
  openRevertModal: OPEN_REVERT_MODAL,
  openCherryPickModal: OPEN_CHERRY_PICK_MODAL,
};
</script>

<template>
  <gl-dropdown
    :text="__('Options')"
    right
    data-testid="commit-options-dropdown"
    data-qa-selector="options_button"
    class="gl-xs-w-full"
  >
    <gl-dropdown-item
      v-if="canRevert"
      data-testid="revert-link"
      @click="showModal($options.openRevertModal)"
    >
      {{ s__('ChangeTypeAction|Revert') }}
    </gl-dropdown-item>
    <gl-dropdown-item
      v-if="canCherryPick"
      data-testid="cherry-pick-link"
      data-qa-selector="cherry_pick_button"
      @click="showModal($options.openCherryPickModal)"
    >
      {{ s__('ChangeTypeAction|Cherry-pick') }}
    </gl-dropdown-item>
    <gl-dropdown-item v-if="canTag" :href="newProjectTagPath" data-testid="tag-link">
      {{ s__('CreateTag|Tag') }}
    </gl-dropdown-item>
    <gl-dropdown-divider v-if="showDivider" />
    <gl-dropdown-section-header>
      {{ __('Download') }}
    </gl-dropdown-section-header>
    <gl-dropdown-item
      v-if="canEmailPatches"
      :href="emailPatchesPath"
      download
      rel="nofollow"
      data-testid="email-patches-link"
      data-qa-selector="email_patches"
    >
      {{ s__('DownloadCommit|Email Patches') }}
    </gl-dropdown-item>
    <gl-dropdown-item
      :href="plainDiffPath"
      download
      rel="nofollow"
      data-testid="plain-diff-link"
      data-qa-selector="plain_diff"
    >
      {{ s__('DownloadCommit|Plain Diff') }}
    </gl-dropdown-item>
  </gl-dropdown>
</template>