summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/integrations/edit/components/trigger_field.vue
blob: 57753c61587e7989befa41d3415c09d671b92244 (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
<script>
import { GlFormCheckbox, GlFormInput } from '@gitlab/ui';
import { mapGetters } from 'vuex';

import {
  placeholderForType,
  integrationTriggerEventTitles,
} from 'any_else_ce/integrations/constants';

export default {
  name: 'TriggerField',
  components: {
    GlFormCheckbox,
    GlFormInput,
  },
  props: {
    event: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    type: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      value: false,
      fieldValue: this.event.field?.value,
    };
  },
  computed: {
    ...mapGetters(['isInheriting']),
    name() {
      return `service[${this.event.name}]`;
    },
    fieldName() {
      return `service[${this.event.field?.name}]`;
    },
    title() {
      return integrationTriggerEventTitles[this.event.name];
    },
    defaultPlaceholder() {
      return placeholderForType[this.type];
    },
  },
  mounted() {
    this.value = this.event.value || false;
  },
};
</script>

<template>
  <div>
    <input :name="name" type="hidden" :value="value" />
    <gl-form-checkbox v-model="value" :disabled="isInheriting">
      {{ title }}
    </gl-form-checkbox>
    <div class="gl-ml-6">
      <gl-form-input
        v-if="event.field"
        v-show="value"
        v-model="fieldValue"
        :name="fieldName"
        :placeholder="event.field.placeholder || defaultPlaceholder"
        :readonly="isInheriting"
      />
    </div>
  </div>
</template>