environments_detail_header.vue 5.07 KB
Newer Older
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
<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 DeleteEnvironmentModal from './delete_environment_modal.vue';
import StopEnvironmentModal from './stop_environment_modal.vue';

export default {
  name: 'EnvironmentsDetailHeader',
  csrf,
  components: {
    GlButton,
    GlSprintf,
    TimeAgo,
    DeleteEnvironmentModal,
    StopEnvironmentModal,
  },
  directives: {
    GlModalDirective,
    GlTooltip,
  },
  mixins: [timeagoMixin],
  props: {
    environment: {
      type: Object,
      required: true,
    },
    canReadEnvironment: {
      type: Boolean,
      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'),
    cancelAutoStopButtonTitle: __('Prevent environment from auto-stopping'),
  },
  computed: {
    shouldShowCancelAutoStopButton() {
      return this.environment.isAvailable && Boolean(this.environment.autoStopAt);
    },
    shouldShowExternalUrlButton() {
      return this.canReadEnvironment && Boolean(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">
      <h3 class="page-title">
        {{ environment.name }}
      </h3>
      <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"
      />
      <gl-button
        v-if="shouldShowExternalUrlButton"
        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
      >
      <gl-button
        v-if="canReadEnvironment"
        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>