Welcome to mirror list, hosted at ThFree Co, Russian Federation.

branch_more_actions.vue « components « branches « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c646dab276086c009486611335ea8bd6454d78f8 (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
<script>
import { GlDisclosureDropdown, GlTooltipDirective } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import eventHub from '../event_hub';

export default {
  name: 'BranchMoreActions',
  components: { GlDisclosureDropdown },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    branchName: {
      type: String,
      required: true,
    },
    defaultBranchName: {
      type: String,
      required: true,
    },
    canDeleteBranch: {
      type: Boolean,
      required: true,
    },
    isProtectedBranch: {
      type: Boolean,
      required: true,
    },
    merged: {
      type: Boolean,
      required: true,
    },
    comparePath: {
      type: String,
      required: true,
    },
    deletePath: {
      type: String,
      required: true,
    },
  },
  i18n: {
    toggleText: __('More actions'),
    compare: s__('Branches|Compare'),
    deleteBranch: s__('Branches|Delete branch'),
    deleteProtectedBranch: s__('Branches|Delete protected branch'),
  },
  computed: {
    deleteBranchText() {
      return this.isProtectedBranch
        ? this.$options.i18n.deleteProtectedBranch
        : this.$options.i18n.deleteBranch;
    },
    dropdownItems() {
      const items = [
        {
          text: this.$options.i18n.compare,
          href: this.comparePath,
          extraAttrs: {
            class: 'js-onboarding-compare-branches',
            'data-testid': 'compare-branch-button',
            'data-method': 'post',
          },
        },
      ];

      if (this.canDeleteBranch) {
        items.push({
          text: this.deleteBranchText,
          action: () => {
            this.openModal();
          },
          extraAttrs: {
            class: 'js-delete-branch-button gl-text-red-500!',
            'aria-label': this.deleteBranchText,
            'data-testid': 'delete-branch-button',
            'data-qa-selector': 'delete_branch_button',
          },
        });
      }

      return items;
    },
  },
  methods: {
    openModal() {
      eventHub.$emit('openModal', {
        branchName: this.branchName,
        defaultBranchName: this.defaultBranchName,
        deletePath: this.deletePath,
        isProtectedBranch: this.isProtectedBranch,
        merged: this.merged,
      });
    },
  },
};
</script>

<template>
  <gl-disclosure-dropdown
    v-gl-tooltip.hover.top="{
      title: $options.i18n.toggleText,
      boundary: 'viewport',
    }"
    :items="dropdownItems"
    :toggle-text="$options.i18n.toggleText"
    icon="ellipsis_v"
    category="tertiary"
    placement="right"
    data-testid="branch-more-actions"
    text-sr-only
    no-caret
  />
</template>