summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/environments/components/environments_detail_header.vue
blob: bb2f053b3fc162296388446159af2889c011f71d (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<script>
import { GlButton, GlModalDirective, GlTooltipDirective as GlTooltip, GlSprintf } from '@gitlab/ui';
import csrf from '~/lib/utils/csrf';
import { __, s__ } from '~/locale';
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
import timeagoMixin from '~/vue_shared/mixins/timeago';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
import { isSafeURL } from '~/lib/utils/url_utility';
import DeleteEnvironmentModal from './delete_environment_modal.vue';
import StopEnvironmentModal from './stop_environment_modal.vue';

export default {
  name: 'EnvironmentsDetailHeader',
  csrf,
  components: {
    GlButton,
    GlSprintf,
    TimeAgo,
    DeleteEnvironmentModal,
    StopEnvironmentModal,
    ModalCopyButton,
  },
  directives: {
    GlModalDirective,
    GlTooltip,
  },
  mixins: [timeagoMixin],
  props: {
    environment: {
      type: Object,
      required: true,
    },
    canAdminEnvironment: {
      type: Boolean,
      required: true,
    },
    canUpdateEnvironment: {
      type: Boolean,
      required: true,
    },
    canDestroyEnvironment: {
      type: Boolean,
      required: true,
    },
    canStopEnvironment: {
      type: Boolean,
      required: true,
    },
    cancelAutoStopPath: {
      type: String,
      required: false,
      default: '',
    },
    metricsPath: {
      type: String,
      required: false,
      default: '',
    },
    updatePath: {
      type: String,
      required: false,
      default: '',
    },
    terminalPath: {
      type: String,
      required: false,
      default: '',
    },
  },
  i18n: {
    autoStopAtText: s__('Environments|Auto stops %{autoStopAt}'),
    metricsButtonTitle: __('See metrics'),
    metricsButtonText: __('Monitoring'),
    editButtonText: __('Edit'),
    stopButtonText: s__('Environments|Stop'),
    deleteButtonText: s__('Environments|Delete'),
    externalButtonTitle: s__('Environments|Open live environment'),
    externalButtonText: __('View deployment'),
    copyUrlText: __('Copy URL'),
    copyUrlTitle: s__('Environments|Copy live environment URL'),
    cancelAutoStopButtonTitle: __('Prevent environment from auto-stopping'),
  },
  computed: {
    shouldShowCancelAutoStopButton() {
      return this.environment.isAvailable && Boolean(this.environment.autoStopAt);
    },
    shouldShowExternalUrlButton() {
      return Boolean(this.environment.externalUrl);
    },
    isSafeUrl() {
      return isSafeURL(this.environment.externalUrl);
    },
    shouldShowStopButton() {
      return this.canStopEnvironment && this.environment.isAvailable;
    },
    shouldShowTerminalButton() {
      return this.canAdminEnvironment && this.environment.hasTerminals;
    },
  },
};
</script>
<template>
  <header class="top-area gl-justify-content-between">
    <div class="gl-display-flex gl-flex-grow-1 gl-align-items-center">
      <h1 class="page-title gl-font-size-h-display">
        {{ environment.name }}
      </h1>
      <p v-if="shouldShowCancelAutoStopButton" class="gl-mb-0 gl-ml-3" data-testid="auto-stops-at">
        <gl-sprintf :message="$options.i18n.autoStopAtText">
          <template #autoStopAt>
            <time-ago :time="environment.autoStopAt" />
          </template>
        </gl-sprintf>
      </p>
    </div>
    <div class="nav-controls gl-my-1">
      <form method="POST" :action="cancelAutoStopPath" data-testid="cancel-auto-stop-form">
        <input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
        <gl-button
          v-if="shouldShowCancelAutoStopButton"
          v-gl-tooltip.hover
          data-testid="cancel-auto-stop-button"
          :title="$options.i18n.cancelAutoStopButtonTitle"
          type="submit"
          icon="thumbtack"
        />
      </form>
      <gl-button
        v-if="shouldShowTerminalButton"
        data-testid="terminal-button"
        :href="terminalPath"
        icon="terminal"
      />
      <template v-if="shouldShowExternalUrlButton">
        <gl-button
          v-if="isSafeUrl"
          v-gl-tooltip.hover
          data-testid="external-url-button"
          :title="$options.i18n.externalButtonTitle"
          :href="environment.externalUrl"
          icon="external-link"
          target="_blank"
          >{{ $options.i18n.externalButtonText }}</gl-button
        >
        <modal-copy-button
          v-else
          :title="$options.i18n.copyUrlTitle"
          :text="environment.externalUrl"
        >
          {{ $options.i18n.copyUrlText }}
        </modal-copy-button>
      </template>
      <gl-button
        v-if="shouldShowExternalUrlButton"
        v-gl-tooltip.hover
        data-testid="metrics-button"
        :href="metricsPath"
        :title="$options.i18n.metricsButtonTitle"
        icon="chart"
        class="gl-mr-2"
      >
        {{ $options.i18n.metricsButtonText }}
      </gl-button>
      <gl-button v-if="canUpdateEnvironment" data-testid="edit-button" :href="updatePath">
        {{ $options.i18n.editButtonText }}
      </gl-button>
      <gl-button
        v-if="shouldShowStopButton"
        v-gl-modal-directive="'stop-environment-modal'"
        data-testid="stop-button"
        icon="stop"
        variant="danger"
      >
        {{ $options.i18n.stopButtonText }}
      </gl-button>
      <gl-button
        v-if="canDestroyEnvironment"
        v-gl-modal-directive="'delete-environment-modal'"
        data-testid="destroy-button"
        variant="danger"
      >
        {{ $options.i18n.deleteButtonText }}
      </gl-button>
    </div>
    <delete-environment-modal v-if="canDestroyEnvironment" :environment="environment" />
    <stop-environment-modal v-if="shouldShowStopButton" :environment="environment" />
  </header>
</template>