summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/groups/components/item_actions.vue
blob: fc7cfffc22c14ca13904f9e1f76ad2f90834edf8 (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
<script>
import { GlTooltipDirective, GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { COMMON_STR } from '../constants';
import eventHub from '../event_hub';

const { LEAVE_BTN_TITLE, EDIT_BTN_TITLE, REMOVE_BTN_TITLE, OPTIONS_DROPDOWN_TITLE } = COMMON_STR;

export default {
  components: {
    GlDropdown,
    GlDropdownItem,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    parentGroup: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    group: {
      type: Object,
      required: true,
    },
    action: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    removeButtonHref() {
      return `${this.group.editPath}#js-remove-group-form`;
    },
  },
  methods: {
    onLeaveGroup() {
      eventHub.$emit(`${this.action}showLeaveGroupModal`, this.group, this.parentGroup);
    },
  },
  i18n: {
    leaveBtnTitle: LEAVE_BTN_TITLE,
    editBtnTitle: EDIT_BTN_TITLE,
    removeBtnTitle: REMOVE_BTN_TITLE,
    optionsDropdownTitle: OPTIONS_DROPDOWN_TITLE,
  },
};
</script>

<template>
  <div class="gl-display-flex gl-justify-content-end gl-ml-5">
    <gl-dropdown
      v-gl-tooltip.hover.focus="$options.i18n.optionsDropdownTitle"
      right
      category="tertiary"
      icon="ellipsis_v"
      no-caret
      :data-testid="`group-${group.id}-dropdown-button`"
      data-qa-selector="group_dropdown_button"
      :data-qa-group-id="group.id"
    >
      <gl-dropdown-item
        v-if="group.canEdit"
        :data-testid="`edit-group-${group.id}-btn`"
        :href="group.editPath"
        @click.stop
      >
        {{ $options.i18n.editBtnTitle }}
      </gl-dropdown-item>
      <gl-dropdown-item
        v-if="group.canLeave"
        :data-testid="`leave-group-${group.id}-btn`"
        @click.stop="onLeaveGroup"
      >
        {{ $options.i18n.leaveBtnTitle }}
      </gl-dropdown-item>
      <gl-dropdown-item
        v-if="group.canRemove"
        :href="removeButtonHref"
        :data-testid="`remove-group-${group.id}-btn`"
        variant="danger"
        @click.stop
      >
        {{ $options.i18n.removeBtnTitle }}
      </gl-dropdown-item>
    </gl-dropdown>
  </div>
</template>