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

clusters_actions.vue « components « clusters_list « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c388d3fee7111ec6d48b568a8500fef42543d04b (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
<script>
import {
  GlButton,
  GlButtonGroup,
  GlModalDirective,
  GlTooltip,
  GlDisclosureDropdown,
} from '@gitlab/ui';

import { INSTALL_AGENT_MODAL_ID, CLUSTERS_ACTIONS } from '../constants';

export default {
  i18n: CLUSTERS_ACTIONS,
  INSTALL_AGENT_MODAL_ID,
  components: {
    GlButton,
    GlButtonGroup,
    GlDisclosureDropdown,
    GlTooltip,
  },
  directives: {
    GlModalDirective,
  },
  inject: [
    'addClusterPath',
    'newClusterDocsPath',
    'canAddCluster',
    'displayClusterAgents',
    'certificateBasedClustersEnabled',
  ],
  computed: {
    shouldTriggerModal() {
      return this.canAddCluster && this.displayClusterAgents;
    },
    defaultActionText() {
      const { connectCluster, connectWithAgent, connectClusterDeprecated } = this.$options.i18n;

      if (!this.displayClusterAgents) {
        return connectClusterDeprecated;
      } else if (!this.certificateBasedClustersEnabled) {
        return connectCluster;
      }
      return connectWithAgent;
    },
    defaultActionUrl() {
      if (this.displayClusterAgents) {
        return null;
      }
      return this.addClusterPath;
    },
    actionItems() {
      const createCluster = {
        href: this.newClusterDocsPath,
        text: this.$options.i18n.createCluster,
        extraAttrs: {
          'data-testid': 'create-cluster-link',
        },
      };
      const connectCluster = {
        href: this.addClusterPath,
        text: this.$options.i18n.connectClusterCertificate,
        extraAttrs: {
          'data-testid': 'connect-cluster-link',
        },
      };
      const actions = [];

      if (this.displayClusterAgents) {
        actions.push(createCluster);
      }
      if (this.displayClusterAgents && this.certificateBasedClustersEnabled) {
        actions.push(connectCluster);
      }
      return actions;
    },
  },
  methods: {
    getTooltipTarget() {
      return this.actionItems.length ? this.$refs.actions.$el : this.$refs.actionsContainer;
    },
  },
};
</script>

<template>
  <div ref="actionsContainer" class="nav-controls gl-ml-auto">
    <gl-tooltip
      v-if="!canAddCluster"
      :target="() => getTooltipTarget()"
      :title="$options.i18n.actionsDisabledHint"
    />

    <!--TODO: Replace button-group workaround once `split` option for new dropdowns is implemented.-->
    <!-- See issue at https://gitlab.com/gitlab-org/gitlab-ui/-/issues/2263-->
    <gl-button-group ref="actions" class="gl-w-full gl-mb-3 gl-md-w-auto gl-md-mb-0">
      <gl-button
        v-gl-modal-directive="shouldTriggerModal && $options.INSTALL_AGENT_MODAL_ID"
        :href="defaultActionUrl"
        :disabled="!canAddCluster"
        data-testid="clusters-default-action-button"
        category="primary"
        variant="confirm"
      >
        {{ defaultActionText }}
      </gl-button>
      <gl-disclosure-dropdown
        v-if="actionItems.length"
        class="split"
        toggle-class="gl-rounded-top-left-none! gl-rounded-bottom-left-none! gl-pl-1!"
        category="primary"
        variant="confirm"
        placement="right"
        :toggle-text="defaultActionText"
        :items="actionItems"
        :disabled="!canAddCluster"
        text-sr-only
      />
    </gl-button-group>
  </div>
</template>