summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/new/components/deployment_target_select.vue
blob: f3b7e39f148e7e8a212367f36c22839b0df7979b (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
<script>
import { GlFormGroup, GlFormSelect } from '@gitlab/ui';
import { s__ } from '~/locale';
import Tracking from '~/tracking';
import {
  DEPLOYMENT_TARGET_SELECTIONS,
  DEPLOYMENT_TARGET_LABEL,
  DEPLOYMENT_TARGET_EVENT,
  NEW_PROJECT_FORM,
} from '../constants';

const trackingMixin = Tracking.mixin({ label: DEPLOYMENT_TARGET_LABEL });

export default {
  i18n: {
    deploymentTargetLabel: s__('Deployment Target|Project deployment target (optional)'),
    defaultOption: s__('Deployment Target|Select the deployment target'),
  },
  deploymentTargets: DEPLOYMENT_TARGET_SELECTIONS,
  selectId: 'deployment-target-select',
  components: {
    GlFormGroup,
    GlFormSelect,
  },
  mixins: [trackingMixin],
  data() {
    return {
      selectedTarget: null,
      formSubmitted: false,
    };
  },
  mounted() {
    const form = document.getElementById(NEW_PROJECT_FORM);
    form.addEventListener('submit', () => {
      this.formSubmitted = true;
      this.trackSelection();
    });
  },
  methods: {
    trackSelection() {
      if (this.formSubmitted && this.selectedTarget) {
        this.track(DEPLOYMENT_TARGET_EVENT, { property: this.selectedTarget });
      }
    },
  },
};
</script>

<template>
  <gl-form-group :label="$options.i18n.deploymentTargetLabel" :label-for="$options.selectId">
    <gl-form-select
      :id="$options.selectId"
      v-model="selectedTarget"
      :options="$options.deploymentTargets"
    >
      <template #first>
        <option :value="null" disabled>{{ $options.i18n.defaultOption }}</option>
      </template>
    </gl-form-select>
  </gl-form-group>
</template>