application_row.vue 5.48 KB
Newer Older
1
<script>
Filipa Lacerda's avatar
Filipa Lacerda committed
2
  /* eslint-disable vue/require-default-prop */
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  import { s__, sprintf } from '../../locale';
  import eventHub from '../event_hub';
  import loadingButton from '../../vue_shared/components/loading_button.vue';
  import {
    APPLICATION_NOT_INSTALLABLE,
    APPLICATION_SCHEDULED,
    APPLICATION_INSTALLABLE,
    APPLICATION_INSTALLING,
    APPLICATION_INSTALLED,
    APPLICATION_ERROR,
    REQUEST_LOADING,
    REQUEST_SUCCESS,
    REQUEST_FAILURE,
  } from '../constants';
17

18
19
20
  export default {
    components: {
      loadingButton,
21
    },
22
23
24
25
26
27
28
29
30
31
32
33
34
    props: {
      id: {
        type: String,
        required: true,
      },
      title: {
        type: String,
        required: true,
      },
      titleLink: {
        type: String,
        required: false,
      },
35
36
37
38
      manageLink: {
        type: String,
        required: false,
      },
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
      status: {
        type: String,
        required: false,
      },
      statusReason: {
        type: String,
        required: false,
      },
      requestStatus: {
        type: String,
        required: false,
      },
      requestReason: {
        type: String,
        required: false,
      },
55
    },
56
57
58
59
60
    computed: {
      rowJsClass() {
        return `js-cluster-application-row-${this.id}`;
      },
      installButtonLoading() {
Filipa Lacerda's avatar
Filipa Lacerda committed
61
        return !this.status ||
62
63
64
65
66
67
68
69
          this.status === APPLICATION_SCHEDULED ||
          this.status === APPLICATION_INSTALLING ||
          this.requestStatus === REQUEST_LOADING;
      },
      installButtonDisabled() {
        // Avoid the potential for the real-time data to say APPLICATION_INSTALLABLE but
        // we already made a request to install and are just waiting for the real-time
        // to sync up.
Filipa Lacerda's avatar
Filipa Lacerda committed
70
71
        return (this.status !== APPLICATION_INSTALLABLE
          && this.status !== APPLICATION_ERROR) ||
72
73
74
75
76
77
78
79
80
81
82
          this.requestStatus === REQUEST_LOADING ||
          this.requestStatus === REQUEST_SUCCESS;
      },
      installButtonLabel() {
        let label;
        if (
          this.status === APPLICATION_NOT_INSTALLABLE ||
          this.status === APPLICATION_INSTALLABLE ||
          this.status === APPLICATION_ERROR
        ) {
          label = s__('ClusterIntegration|Install');
Filipa Lacerda's avatar
Filipa Lacerda committed
83
84
        } else if (this.status === APPLICATION_SCHEDULED ||
          this.status === APPLICATION_INSTALLING) {
85
86
87
88
          label = s__('ClusterIntegration|Installing');
        } else if (this.status === APPLICATION_INSTALLED) {
          label = s__('ClusterIntegration|Installed');
        }
89

90
91
        return label;
      },
92
93
94
      showManageButton() {
        return this.manageLink && this.status === APPLICATION_INSTALLED;
      },
95
96
97
      manageButtonLabel() {
        return s__('ClusterIntegration|Manage');
      },
98
      hasError() {
Filipa Lacerda's avatar
Filipa Lacerda committed
99
100
        return this.status === APPLICATION_ERROR ||
        this.requestStatus === REQUEST_FAILURE;
101
102
103
104
105
106
107
108
      },
      generalErrorDescription() {
        return sprintf(
          s__('ClusterIntegration|Something went wrong while installing %{title}'), {
            title: this.title,
          },
        );
      },
109
    },
110
111
112
113
    methods: {
      installClicked() {
        eventHub.$emit('installApplication', this.id);
      },
114
    },
115
  };
116
117
118
119
120
121
122
123
124
125
126
</script>

<template>
  <div
    class="gl-responsive-table-row gl-responsive-table-row-col-span"
    :class="rowJsClass"
  >
    <div
      class="gl-responsive-table-row-layout"
      role="row"
    >
127
      <a
Filipa Lacerda's avatar
Filipa Lacerda committed
128
        v-if="titleLink"
129
130
131
132
133
134
135
        :href="titleLink"
        target="blank"
        rel="noopener noreferrer"
        role="gridcell"
        class="table-section section-15 section-align-top js-cluster-application-title"
      >
        {{ title }}
136
137
138
139
140
141
142
      </a>
      <span
        v-else
        class="table-section section-15 section-align-top js-cluster-application-title"
      >
        {{ title }}
      </span>
143
144
145
146
      <div
        class="table-section section-wrap"
        role="gridcell"
      >
147
        <slot name="description"></slot>
148
149
      </div>
      <div
150
        class="table-section table-button-footer section-align-top"
151
        :class="{ 'section-20': showManageButton, 'section-15': !showManageButton }"
152
153
        role="gridcell"
      >
154
        <div
155
          v-if="showManageButton"
156
157
158
159
160
161
          class="btn-group table-action-buttons"
        >
          <a
            class="btn"
            :href="manageLink"
          >
162
            {{ manageButtonLabel }}
163
164
          </a>
        </div>
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
        <div class="btn-group table-action-buttons">
          <loading-button
            class="js-cluster-application-install-button"
            :loading="installButtonLoading"
            :disabled="installButtonDisabled"
            :label="installButtonLabel"
            @click="installClicked"
          />
        </div>
      </div>
    </div>
    <div
      v-if="hasError"
      class="gl-responsive-table-row-layout"
      role="row"
    >
      <div
182
        class="alert alert-danger alert-block append-bottom-0"
183
184
185
186
        role="gridcell"
      >
        <div>
          <p class="js-cluster-application-general-error-message">
187
            {{ generalErrorDescription }}
188
          </p>
Filipa Lacerda's avatar
Filipa Lacerda committed
189
          <ul v-if="statusReason || requestReason">
190
            <li
Filipa Lacerda's avatar
Filipa Lacerda committed
191
              v-if="statusReason"
192
193
194
195
196
              class="js-cluster-application-status-error-message"
            >
              {{ statusReason }}
            </li>
            <li
Filipa Lacerda's avatar
Filipa Lacerda committed
197
              v-if="requestReason"
198
199
200
201
202
203
204
205
206
207
              class="js-cluster-application-request-error-message"
            >
              {{ requestReason }}
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>