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

invite_members_trigger.vue « components « invite_members « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bf3250f63a5cf3f38452af8b507eaf1f04bb8839 (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
121
<script>
import { GlButton, GlLink, GlIcon } from '@gitlab/ui';
import ExperimentTracking from '~/experimentation/experiment_tracking';
import { s__ } from '~/locale';
import eventHub from '../event_hub';
import { TRIGGER_ELEMENT_BUTTON, TRIGGER_ELEMENT_SIDE_NAV } from '../constants';

export default {
  components: { GlButton, GlLink, GlIcon },
  props: {
    displayText: {
      type: String,
      required: false,
      default: s__('InviteMembers|Invite team members'),
    },
    icon: {
      type: String,
      required: false,
      default: '',
    },
    classes: {
      type: String,
      required: false,
      default: '',
    },
    variant: {
      type: String,
      required: false,
      default: undefined,
    },
    triggerSource: {
      type: String,
      required: true,
    },
    trackExperiment: {
      type: String,
      required: false,
      default: undefined,
    },
    triggerElement: {
      type: String,
      required: false,
      default: 'button',
    },
    event: {
      type: String,
      required: false,
      default: '',
    },
    label: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    componentAttributes() {
      const baseAttributes = {
        class: this.classes,
        'data-qa-selector': 'invite_members_button',
        'data-test-id': 'invite-members-button',
      };

      if (this.event && this.label) {
        return {
          ...baseAttributes,
          'data-track-action': this.event,
          'data-track-label': this.label,
        };
      }

      return baseAttributes;
    },
  },
  mounted() {
    this.trackExperimentOnShow();
  },
  methods: {
    checkTrigger(targetTriggerElement) {
      return this.triggerElement === targetTriggerElement;
    },
    openModal() {
      eventHub.$emit('openModal', { inviteeType: 'members', source: this.triggerSource });
    },
    trackExperimentOnShow() {
      if (this.trackExperiment) {
        const tracking = new ExperimentTracking(this.trackExperiment);
        tracking.event('comment_invite_shown');
      }
    },
  },
  TRIGGER_ELEMENT_BUTTON,
  TRIGGER_ELEMENT_SIDE_NAV,
};
</script>

<template>
  <gl-button
    v-if="checkTrigger($options.TRIGGER_ELEMENT_BUTTON)"
    v-bind="componentAttributes"
    :variant="variant"
    :icon="icon"
    @click="openModal"
  >
    {{ displayText }}
  </gl-button>
  <gl-link
    v-else-if="checkTrigger($options.TRIGGER_ELEMENT_SIDE_NAV)"
    v-bind="componentAttributes"
    data-is-link="true"
    @click="openModal"
  >
    <span class="nav-icon-container">
      <gl-icon :name="icon" />
    </span>
    <span class="nav-item-name"> {{ displayText }} </span>
  </gl-link>
  <gl-link v-else v-bind="componentAttributes" data-is-link="true" @click="openModal">
    {{ displayText }}
  </gl-link>
</template>