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

registration_dropdown.vue « registration « components « runner « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bb2a8ddf15190a50f7b8bcd43d490cf358941d99 (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
<script>
import {
  GlFormGroup,
  GlDropdown,
  GlDropdownForm,
  GlDropdownItem,
  GlDropdownDivider,
} from '@gitlab/ui';
import { s__ } from '~/locale';
import RunnerInstructionsModal from '~/vue_shared/components/runner_instructions/runner_instructions_modal.vue';
import { INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE } from '../../constants';
import RegistrationToken from './registration_token.vue';
import RegistrationTokenResetDropdownItem from './registration_token_reset_dropdown_item.vue';

export default {
  i18n: {
    showInstallationInstructions: s__(
      'Runners|Show runner installation and registration instructions',
    ),
    registrationToken: s__('Runners|Registration token'),
  },
  components: {
    GlFormGroup,
    GlDropdown,
    GlDropdownForm,
    GlDropdownItem,
    GlDropdownDivider,
    RegistrationToken,
    RunnerInstructionsModal,
    RegistrationTokenResetDropdownItem,
  },
  props: {
    registrationToken: {
      type: String,
      required: true,
    },
    type: {
      type: String,
      required: true,
      validator(type) {
        return [INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE].includes(type);
      },
    },
  },
  data() {
    return {
      currentRegistrationToken: this.registrationToken,
      instructionsModalOpened: false,
    };
  },
  computed: {
    dropdownText() {
      switch (this.type) {
        case INSTANCE_TYPE:
          return s__('Runners|Register an instance runner');
        case GROUP_TYPE:
          return s__('Runners|Register a group runner');
        case PROJECT_TYPE:
          return s__('Runners|Register a project runner');
        default:
          return s__('Runners|Register a runner');
      }
    },
  },
  methods: {
    onShowInstructionsClick() {
      // Rendering the modal on demand, to avoid
      // loading instructions prematurely from API.
      this.instructionsModalOpened = true;

      this.$nextTick(() => {
        // $refs.runnerInstructionsModal is defined in
        // the tick after the modal is rendered
        this.$refs.runnerInstructionsModal.show();
      });
    },
    onTokenReset(token) {
      this.currentRegistrationToken = token;

      this.$refs.runnerRegistrationDropdown.hide(true);
    },
  },
};
</script>

<template>
  <gl-dropdown
    ref="runnerRegistrationDropdown"
    menu-class="gl-w-auto!"
    :text="dropdownText"
    variant="confirm"
    v-bind="$attrs"
  >
    <gl-dropdown-item @click.capture.native.stop="onShowInstructionsClick">
      {{ $options.i18n.showInstallationInstructions }}
      <runner-instructions-modal
        v-if="instructionsModalOpened"
        ref="runnerInstructionsModal"
        :registration-token="currentRegistrationToken"
        data-testid="runner-instructions-modal"
      />
    </gl-dropdown-item>
    <gl-dropdown-divider />
    <gl-dropdown-form class="gl-p-4!">
      <gl-form-group class="gl-mb-0" :label="$options.i18n.registrationToken">
        <registration-token :value="currentRegistrationToken" />
      </gl-form-group>
    </gl-dropdown-form>
    <gl-dropdown-divider />
    <registration-token-reset-dropdown-item :type="type" @tokenReset="onTokenReset" />
  </gl-dropdown>
</template>