sidebar.vue 7.1 KB
Newer Older
1
<script>
2
import { isEmpty } from 'lodash';
3
import { mapActions, mapState } from 'vuex';
4
import { GlLink, GlDeprecatedButton, GlIcon } from '@gitlab/ui';
5
import { __, sprintf } from '~/locale';
6
import timeagoMixin from '~/vue_shared/mixins/timeago';
7
import TooltipOnTruncate from '~/vue_shared/components/tooltip_on_truncate.vue';
8 9 10 11 12 13 14
import { timeIntervalInWords } from '~/lib/utils/datetime_utility';
import DetailRow from './sidebar_detail_row.vue';
import ArtifactsBlock from './artifacts_block.vue';
import TriggerBlock from './trigger_block.vue';
import CommitBlock from './commit_block.vue';
import StagesDropdown from './stages_dropdown.vue';
import JobsContainer from './jobs_container.vue';
15

16 17 18 19 20 21
export default {
  name: 'JobSidebar',
  components: {
    ArtifactsBlock,
    CommitBlock,
    DetailRow,
22
    GlIcon,
23 24 25
    TriggerBlock,
    StagesDropdown,
    JobsContainer,
26
    GlLink,
27
    GlDeprecatedButton,
28
    TooltipOnTruncate,
29 30 31
  },
  mixins: [timeagoMixin],
  props: {
32 33 34 35 36
    artifactHelpUrl: {
      type: String,
      required: false,
      default: '',
    },
37 38 39 40
    runnerHelpUrl: {
      type: String,
      required: false,
      default: '',
41
    },
42 43
  },
  computed: {
44
    ...mapState(['job', 'stages', 'jobs', 'selectedStage']),
45 46 47 48 49 50 51 52 53 54 55 56 57
    coverage() {
      return `${this.job.coverage}%`;
    },
    duration() {
      return timeIntervalInWords(this.job.duration);
    },
    queued() {
      return timeIntervalInWords(this.job.queued);
    },
    runnerId() {
      return `${this.job.runner.description} (#${this.job.runner.id})`;
    },
    retryButtonClass() {
F
Fernando Arias 已提交
58
      let className = 'js-retry-button btn btn-retry';
59 60 61 62 63 64 65 66 67 68 69
      className +=
        this.job.status && this.job.recoverable ? ' btn-primary' : ' btn-inverted-secondary';
      return className;
    },
    hasTimeout() {
      return this.job.metadata != null && this.job.metadata.timeout_human_readable !== null;
    },
    timeout() {
      if (this.job.metadata == null) {
        return '';
      }
70

71 72
      let t = this.job.metadata.timeout_human_readable;
      if (this.job.metadata.timeout_source !== '') {
73 74 75
        t += sprintf(__(` (from %{timeoutSource})`), {
          timeoutSource: this.job.metadata.timeout_source,
        });
76
      }
77

78 79 80 81 82
      return t;
    },
    renderBlock() {
      return (
        this.job.duration ||
83
        this.job.finished_at ||
84 85
        this.job.erased_at ||
        this.job.queued ||
86
        this.hasTimeout ||
87 88
        this.job.runner ||
        this.job.coverage ||
89
        this.job.tags.length
90 91 92
      );
    },
    hasArtifact() {
93
      return !isEmpty(this.job.artifact);
94 95
    },
    hasTriggers() {
96
      return !isEmpty(this.job.trigger);
97 98 99 100 101 102 103 104 105
    },
    hasStages() {
      return (
        (this.job &&
          this.job.pipeline &&
          this.job.pipeline.stages &&
          this.job.pipeline.stages.length > 0) ||
        false
      );
106
    },
107
    commit() {
108
      return this.job.pipeline && this.job.pipeline.commit ? this.job.pipeline.commit : {};
109
    },
110 111
  },
  methods: {
112
    ...mapActions(['fetchJobsForStage', 'toggleSidebar']),
113 114
  },
};
115 116
</script>
<template>
M
Mike Greiling 已提交
117
  <aside class="right-sidebar build-sidebar" data-offset-top="101" data-spy="affix">
118 119
    <div class="sidebar-container">
      <div class="blocks-container">
F
Fernando Arias 已提交
120
        <div class="block d-flex flex-nowrap align-items-center">
121 122 123 124 125
          <tooltip-on-truncate :title="job.name" truncate-target="child"
            ><h4 class="my-0 mr-2 gl-text-truncate">
              {{ job.name }}
            </h4>
          </tooltip-on-truncate>
F
Fernando Arias 已提交
126 127 128 129 130 131
          <div class="flex-grow-1 flex-shrink-0 text-right">
            <gl-link
              v-if="job.retry_path"
              :class="retryButtonClass"
              :href="job.retry_path"
              data-method="post"
132
              data-qa-selector="retry_button"
F
Fernando Arias 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145
              rel="nofollow"
              >{{ __('Retry') }}</gl-link
            >
            <gl-link
              v-if="job.cancel_path"
              :href="job.cancel_path"
              class="js-cancel-job btn btn-default"
              data-method="post"
              rel="nofollow"
              >{{ __('Cancel') }}</gl-link
            >
          </div>

146
          <gl-deprecated-button
147 148
            :aria-label="__('Toggle Sidebar')"
            type="button"
149
            class="btn btn-blank gutter-toggle float-right d-block d-md-none js-sidebar-build-toggle"
150 151
            @click="toggleSidebar"
          >
M
Mike Greiling 已提交
152
            <i aria-hidden="true" data-hidden="true" class="fa fa-angle-double-right"></i>
153
          </gl-deprecated-button>
154
        </div>
F
Fernando Arias 已提交
155 156

        <div v-if="job.terminal_path || job.new_issue_path" class="block retry-link">
157
          <gl-link
158 159
            v-if="job.new_issue_path"
            :href="job.new_issue_path"
160 161
            class="btn btn-success btn-inverted float-left mr-2"
            data-testid="job-new-issue"
162
            >{{ __('New issue') }}</gl-link
163
          >
164
          <gl-link
F
Fernando Arias 已提交
165 166 167 168
            v-if="job.terminal_path"
            :href="job.terminal_path"
            class="js-terminal-link btn btn-primary btn-inverted visible-md-block visible-lg-block float-left"
            target="_blank"
169
          >
170
            {{ __('Debug') }} <gl-icon name="external-link" :size="14" />
F
Fernando Arias 已提交
171
          </gl-link>
172
        </div>
F
Fernando Arias 已提交
173

174
        <div v-if="renderBlock" class="block">
175 176 177 178 179 180 181 182
          <detail-row
            v-if="job.duration"
            :value="duration"
            class="js-job-duration"
            title="Duration"
          />
          <detail-row
            v-if="job.finished_at"
183
            :value="timeFormatted(job.finished_at)"
184 185 186 187 188
            class="js-job-finished"
            title="Finished"
          />
          <detail-row
            v-if="job.erased_at"
189
            :value="timeFormatted(job.erased_at)"
190 191 192
            class="js-job-erased"
            title="Erased"
          />
M
Mike Greiling 已提交
193
          <detail-row v-if="job.queued" :value="queued" class="js-job-queued" title="Queued" />
194 195 196 197 198 199 200
          <detail-row
            v-if="hasTimeout"
            :help-url="runnerHelpUrl"
            :value="timeout"
            class="js-job-timeout"
            title="Timeout"
          />
M
Mike Greiling 已提交
201
          <detail-row v-if="job.runner" :value="runnerId" class="js-job-runner" title="Runner" />
202 203 204 205 206 207
          <detail-row
            v-if="job.coverage"
            :value="coverage"
            class="js-job-coverage"
            title="Coverage"
          />
M
Mike Greiling 已提交
208
          <p v-if="job.tags.length" class="build-detail-row js-job-tags">
209 210 211 212
            <span class="font-weight-bold">{{ __('Tags:') }}</span>
            <span v-for="(tag, i) in job.tags" :key="i" class="badge badge-primary mr-1">{{
              tag
            }}</span>
213 214
          </p>
        </div>
215

216
        <artifacts-block v-if="hasArtifact" :artifact="job.artifact" :help-url="artifactHelpUrl" />
M
Mike Greiling 已提交
217
        <trigger-block v-if="hasTriggers" :trigger="job.trigger" />
218 219 220 221 222
        <commit-block
          :is-last-block="hasStages"
          :commit="commit"
          :merge-request="job.merge_request"
        />
223

224 225 226 227 228
        <stages-dropdown
          :stages="stages"
          :pipeline="job.pipeline"
          :selected-stage="selectedStage"
          @requestSidebarStageDropdown="fetchJobsForStage"
229 230 231
        />
      </div>

M
Mike Greiling 已提交
232
      <jobs-container v-if="jobs.length" :jobs="jobs" :job-id="job.id" />
233 234 235
    </div>
  </aside>
</template>