All files / app/assets/javascripts/pipelines/components/pipelines_list job_item.vue

87.5% Statements 28/32
65.22% Branches 15/23
78.57% Functions 11/14
87.5% Lines 28/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 189 190 191  21x 21x 21x 21x 21x 21x 21x                                                                                                                         21x                         24x     24x     24x     24x 24x   24x 24x     24x 24x 24x     24x 24x     24x       24x               24x     24x     24x     24x                         2x         135x                                                                                          
<script>
import { GlTooltipDirective, GlLink } from '@gitlab/ui';
import delayedJobMixin from '~/jobs/mixins/delayed_job_mixin';
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
import { sprintf } from '~/locale';
import { reportToSentry } from '../../utils';
import ActionComponent from '../jobs_shared/action_component.vue';
import JobNameComponent from '../jobs_shared/job_name_component.vue';
 
/**
 * Renders the badge for the pipeline graph and the job's dropdown.
 *
 * The following object should be provided as `job`:
 *
 * {
 *   "id": 4256,
 *   "name": "test",
 *   "status": {
 *     "icon": "status_success",
 *     "text": "passed",
 *     "label": "passed",
 *     "group": "success",
 *     "tooltip": "passed",
 *     "details_path": "/root/ci-mock/builds/4256",
 *     "action": {
 *       "icon": "retry",
 *       "title": "Retry",
 *       "path": "/root/ci-mock/builds/4256/retry",
 *       "method": "post"
 *     }
 *   }
 * }
 */
 
export default {
  hoverClass: 'gl-shadow-x0-y0-b3-s1-blue-500',
  components: {
    ActionComponent,
    JobNameComponent,
    GlLink,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  mixins: [delayedJobMixin],
  props: {
    job: {
      type: Object,
      required: true,
    },
    cssClassJobName: {
      type: String,
      required: false,
      default: '',
    },
    dropdownLength: {
      type: Number,
      required: false,
      default: Infinity,
    },
    jobHovered: {
      type: String,
      required: false,
      default: '',
    },
    pipelineExpanded: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    pipelineId: {
      type: Number,
      required: false,
      default: -1,
    },
  },
  computed: {
    boundary() {
      return this.dropdownLength === 1 ? 'viewport' : 'scrollParent';
    },
    detailsPath() {
      return this.status.details_path;
    },
    hasDetails() {
      return this.status.has_details;
    },
    status() {
      return this.job && this.job.status ? this.job.status : {};
    },
    tooltipText() {
      const textBuilder = [];
      const { name: jobName } = this.job;
 
E      if (jobName) {
        textBuilder.push(jobName);
      }
 
      const { tooltip: statusTooltip } = this.status;
E      if (jobName && statusTooltip) {
        textBuilder.push('-');
      }
 
E      if (statusTooltip) {
I        if (this.isDelayedJob) {
          textBuilder.push(sprintf(statusTooltip, { remainingTime: this.remainingTime }));
        } else {
          textBuilder.push(statusTooltip);
        }
      }
 
      return textBuilder.join(' ');
    },
    /**
     * Verifies if the provided job has an action path
     *
     * @return {Boolean}
     */
    hasAction() {
      return this.job.status && this.job.status.action && this.job.status.action.path;
    },
    relatedDownstreamHovered() {
      return this.job.name === this.jobHovered;
    },
    relatedDownstreamExpanded() {
      return this.job.name === this.pipelineExpanded.jobName && this.pipelineExpanded.expanded;
    },
    jobClasses() {
      return this.relatedDownstreamHovered || this.relatedDownstreamExpanded
        ? `${this.$options.hoverClass} ${this.cssClassJobName}`
        : this.cssClassJobName;
    },
  },
  errorCaptured(err, _vm, info) {
    reportToSentry('pipelines_job_item', `pipelines_job_item error: ${err}, info: ${info}`);
  },
  methods: {
    hideTooltips() {
      this.$root.$emit(BV_HIDE_TOOLTIP);
    },
    pipelineActionRequestComplete() {
      this.$emit('pipelineActionRequestComplete');
    },
  },
};
</script>
<template>
  <div
    class="ci-job-component gl-display-flex gl-align-items-center gl-justify-content-space-between"
    data-qa-selector="job_item_container"
  >
    <gl-link
      v-if="hasDetails"
      v-gl-tooltip="{
        boundary: 'viewport',
        placement: 'bottom',
        customClass: 'gl-pointer-events-none',
      }"
      :href="detailsPath"
      :title="tooltipText"
      :class="jobClasses"
      class="js-pipeline-graph-job-link qa-job-link menu-item gl-text-gray-900 gl-active-text-decoration-none gl-focus-text-decoration-none gl-hover-text-decoration-none"
      data-testid="job-with-link"
      @click.stop="hideTooltips"
      @mouseout="hideTooltips"
    >
      <job-name-component :name="job.name" :status="job.status" :icon-size="24" />
    </gl-link>
 
    <div
      v-else
      v-gl-tooltip="{ boundary, placement: 'bottom', customClass: 'gl-pointer-events-none' }"
      :title="tooltipText"
      :class="jobClasses"
      class="js-job-component-tooltip non-details-job-component menu-item"
      data-testid="job-without-link"
      @mouseout="hideTooltips"
    >
      <job-name-component :name="job.name" :status="job.status" :icon-size="24" />
    </div>
 
    <action-component
      v-if="hasAction"
      :tooltip-text="status.action.title"
      :link="status.action.path"
      :action-icon="status.action.icon"
      data-qa-selector="action_button"
      @pipelineActionRequestComplete="pipelineActionRequestComplete"
    />
  </div>
</template>