application_row.vue 10.5 KB
Newer Older
1
<script>
2
/* eslint-disable vue/require-default-prop */
3 4
import { GlLink } from '@gitlab/ui';
import TimeagoTooltip from '../../vue_shared/components/time_ago_tooltip.vue';
5 6 7 8
import { s__, sprintf } from '../../locale';
import eventHub from '../event_hub';
import identicon from '../../vue_shared/components/identicon.vue';
import loadingButton from '../../vue_shared/components/loading_button.vue';
9 10 11 12 13 14
import {
  APPLICATION_STATUS,
  REQUEST_SUBMITTED,
  REQUEST_FAILURE,
  UPGRADE_REQUESTED,
} from '../constants';
15

16 17 18 19
export default {
  components: {
    loadingButton,
    identicon,
20 21
    TimeagoTooltip,
    GlLink,
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
  },
  props: {
    id: {
      type: String,
      required: true,
    },
    title: {
      type: String,
      required: true,
    },
    titleLink: {
      type: String,
      required: false,
    },
    manageLink: {
      type: String,
      required: false,
    },
    logoUrl: {
      type: String,
      required: false,
      default: null,
    },
    disabled: {
      type: Boolean,
      required: false,
      default: false,
    },
    status: {
      type: String,
      required: false,
    },
    statusReason: {
      type: String,
      required: false,
    },
    requestStatus: {
      type: String,
      required: false,
    },
    requestReason: {
      type: String,
      required: false,
    },
66 67 68 69 70
    installed: {
      type: Boolean,
      required: false,
      default: false
    },
71 72 73 74 75 76 77 78 79 80 81 82
    version: {
      type: String,
      required: false,
    },
    chartRepo: {
      type: String,
      required: false,
    },
    upgradeAvailable: {
      type: Boolean,
      required: false,
    },
83 84 85 86 87 88 89 90 91 92 93 94 95
    installApplicationRequestParams: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  },
  computed: {
    isUnknownStatus() {
      return !this.isKnownStatus && this.status !== null;
    },
    isKnownStatus() {
      return Object.values(APPLICATION_STATUS).includes(this.status);
    },
96 97 98 99
    isInstalling() {
      return (
        this.status === APPLICATION_STATUS.SCHEDULED ||
        this.status === APPLICATION_STATUS.INSTALLING ||
100
        (this.requestStatus === REQUEST_SUBMITTED && !this.statusReason && !this.installed)
101 102
      );
    },
103 104 105 106 107 108 109 110 111 112 113 114
    canInstall() {
      if (this.isInstalling) {
        return false;
      }

      return (
        this.status === APPLICATION_STATUS.NOT_INSTALLABLE ||
        this.status === APPLICATION_STATUS.INSTALLABLE ||
        this.status === APPLICATION_STATUS.ERROR ||
        this.isUnknownStatus
      );
    },
115 116 117 118 119 120 121 122 123 124 125
    hasLogo() {
      return !!this.logoUrl;
    },
    identiconId() {
      // generate a deterministic integer id for the identicon background
      return this.id.charCodeAt(0);
    },
    rowJsClass() {
      return `js-cluster-application-row-${this.id}`;
    },
    installButtonLoading() {
126
      return !this.status || this.status === APPLICATION_STATUS.SCHEDULED || this.isInstalling;
127 128 129 130 131 132 133 134
    },
    installButtonDisabled() {
      // Avoid the potential for the real-time data to say APPLICATION_STATUS.INSTALLABLE but
      // we already made a request to install and are just waiting for the real-time
      // to sync up.
      return (
        ((this.status !== APPLICATION_STATUS.INSTALLABLE &&
          this.status !== APPLICATION_STATUS.ERROR) ||
135
          this.isInstalling) &&
136 137 138 139 140
        this.isKnownStatus
      );
    },
    installButtonLabel() {
      let label;
141
      if (this.canInstall) {
142
        label = s__('ClusterIntegration|Install');
143
      } else if (this.isInstalling) {
144
        label = s__('ClusterIntegration|Installing');
145
      } else if (this.installed) {
146 147
        label = s__('ClusterIntegration|Installed');
      }
148

149 150 151 152 153 154 155 156 157
      return label;
    },
    showManageButton() {
      return this.manageLink && this.status === APPLICATION_STATUS.INSTALLED;
    },
    manageButtonLabel() {
      return s__('ClusterIntegration|Manage');
    },
    hasError() {
158 159 160 161
      return (
        !this.isInstalling &&
        (this.status === APPLICATION_STATUS.ERROR || this.requestStatus === REQUEST_FAILURE)
      );
162 163 164 165 166 167
    },
    generalErrorDescription() {
      return sprintf(s__('ClusterIntegration|Something went wrong while installing %{title}'), {
        title: this.title,
      });
    },
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
    versionLabel() {
      if (this.upgradeFailed) {
        return s__('ClusterIntegration|Upgrade failed');
      } else if (this.isUpgrading) {
        return s__('ClusterIntegration|Upgrading');
      }

      return s__('ClusterIntegration|Upgraded');
    },
    upgradeRequested() {
      return this.requestStatus === UPGRADE_REQUESTED;
    },
    upgradeSuccessful() {
      return this.status === APPLICATION_STATUS.UPDATED;
    },
    upgradeFailed() {
      if (this.isUpgrading) {
        return false;
      }

      return this.status === APPLICATION_STATUS.UPDATE_ERRORED;
    },
    upgradeFailureDescription() {
J
jerasmus 已提交
191
      return s__('ClusterIntegration|Update failed. Please check the logs and try again.');
192 193 194 195 196 197 198 199 200 201 202
    },
    upgradeSuccessDescription() {
      return sprintf(s__('ClusterIntegration|%{title} upgraded successfully.'), {
        title: this.title,
      });
    },
    upgradeButtonLabel() {
      let label;
      if (this.upgradeAvailable && !this.upgradeFailed && !this.isUpgrading) {
        label = s__('ClusterIntegration|Upgrade');
      } else if (this.isUpgrading) {
J
jerasmus 已提交
203
        label = s__('ClusterIntegration|Updating');
204
      } else if (this.upgradeFailed) {
J
jerasmus 已提交
205
        label = s__('ClusterIntegration|Retry update');
206 207 208 209 210 211 212 213 214 215 216
      }

      return label;
    },
    isUpgrading() {
      // Since upgrading is handled asynchronously on the backend we need this check to prevent any delay on the frontend
      return (
        this.status === APPLICATION_STATUS.UPDATING ||
        (this.upgradeRequested && !this.upgradeSuccessful)
      );
    },
J
jerasmus 已提交
217 218 219 220 221 222 223 224
    shouldShowUpgradeDetails() {
      // This method only returns true when;
      // Upgrade was successful OR Upgrade failed
      //     AND new upgrade is unavailable AND version information is present.
      return (
        (this.upgradeSuccessful || this.upgradeFailed) && !this.upgradeAvailable && this.version
      );
    },
225 226 227 228 229 230 231
  },
  watch: {
    status() {
      if (this.status === APPLICATION_STATUS.UPDATE_ERRORED) {
        eventHub.$emit('upgradeFailed', this.id);
      }
    },
232 233 234 235 236 237 238 239
  },
  methods: {
    installClicked() {
      eventHub.$emit('installApplication', {
        id: this.id,
        params: this.installApplicationRequestParams,
      });
    },
240 241 242 243 244 245 246 247 248
    upgradeClicked() {
      eventHub.$emit('upgradeApplication', {
        id: this.id,
        params: this.installApplicationRequestParams,
      });
    },
    dismissUpgradeSuccess() {
      eventHub.$emit('dismissUpgradeSuccess', this.id);
    },
249 250
  },
};
251 252 253 254
</script>

<template>
  <div
255 256
    :class="[
      rowJsClass,
257
      installed && 'cluster-application-installed',
M
Mike Greiling 已提交
258
      disabled && 'cluster-application-disabled',
259 260
    ]"
    class="cluster-application-row gl-responsive-table-row gl-responsive-table-row-col-span"
261
  >
M
Mike Greiling 已提交
262 263
    <div class="gl-responsive-table-row-layout" role="row">
      <div class="table-section append-right-8 section-align-top" role="gridcell">
264 265 266 267 268 269
        <img
          v-if="hasLogo"
          :src="logoUrl"
          :alt="`${title} logo`"
          class="cluster-application-logo avatar s40"
        />
M
Mike Greiling 已提交
270
        <identicon v-else :entity-id="identiconId" :entity-name="title" size-class="s40" />
271
      </div>
M
Mike Greiling 已提交
272
      <div class="table-section cluster-application-description section-wrap" role="gridcell">
273 274 275 276 277 278 279 280 281 282
        <strong>
          <a
            v-if="titleLink"
            :href="titleLink"
            target="blank"
            rel="noopener noreferrer"
            class="js-cluster-application-title"
          >
            {{ title }}
          </a>
M
Mike Greiling 已提交
283
          <span v-else class="js-cluster-application-title"> {{ title }} </span>
284
        </strong>
285
        <slot name="description"></slot>
286 287 288 289 290 291 292 293
        <div
          v-if="hasError || isUnknownStatus"
          class="cluster-application-error text-danger prepend-top-10"
        >
          <p class="js-cluster-application-general-error-message append-bottom-0">
            {{ generalErrorDescription }}
          </p>
          <ul v-if="statusReason || requestReason">
M
Mike Greiling 已提交
294
            <li v-if="statusReason" class="js-cluster-application-status-error-message">
295 296
              {{ statusReason }}
            </li>
M
Mike Greiling 已提交
297
            <li v-if="requestReason" class="js-cluster-application-request-error-message">
298 299 300 301
              {{ requestReason }}
            </li>
          </ul>
        </div>
302 303

        <div
J
jerasmus 已提交
304
          v-if="shouldShowUpgradeDetails"
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
          class="form-text text-muted label p-0 js-cluster-application-upgrade-details"
        >
          {{ versionLabel }}

          <span v-if="upgradeSuccessful"> to</span>

          <gl-link
            v-if="upgradeSuccessful"
            :href="chartRepo"
            target="_blank"
            class="js-cluster-application-upgrade-version"
          >
            chart v{{ version }}
          </gl-link>
        </div>

        <div
          v-if="upgradeFailed && !isUpgrading"
          class="bs-callout bs-callout-danger cluster-application-banner mt-2 mb-0 js-cluster-application-upgrade-failure-message"
        >
          {{ upgradeFailureDescription }}
        </div>

        <div
          v-if="upgradeRequested && upgradeSuccessful"
          class="bs-callout bs-callout-success cluster-application-banner mt-2 mb-0 p-0 pl-3"
        >
          {{ upgradeSuccessDescription }}

          <button class="close cluster-application-banner-close" @click="dismissUpgradeSuccess">
            &times;
          </button>
        </div>

        <loading-button
          v-if="upgradeAvailable || upgradeFailed || isUpgrading"
          class="btn btn-primary js-cluster-application-upgrade-button mt-2"
          :loading="isUpgrading"
          :disabled="isUpgrading"
          :label="upgradeButtonLabel"
          @click="upgradeClicked"
        />
347 348
      </div>
      <div
349
        :class="{ 'section-25': showManageButton, 'section-15': !showManageButton }"
350
        class="table-section table-button-footer section-align-top"
351 352
        role="gridcell"
      >
M
Mike Greiling 已提交
353 354
        <div v-if="showManageButton" class="btn-group table-action-buttons">
          <a :href="manageLink" :class="{ disabled: disabled }" class="btn">
355
            {{ manageButtonLabel }}
356 357
          </a>
        </div>
358 359 360
        <div class="btn-group table-action-buttons">
          <loading-button
            :loading="installButtonLoading"
361
            :disabled="disabled || installButtonDisabled"
362
            :label="installButtonLabel"
363
            class="js-cluster-application-install-button"
364 365 366 367 368 369 370
            @click="installClicked"
          />
        </div>
      </div>
    </div>
  </div>
</template>