debian-mirror-gitlab/app/assets/javascripts/pipelines/components/graph/job_item.vue

252 lines
6.5 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2020-01-01 13:55:28 +05:30
import { GlTooltipDirective, GlLink } from '@gitlab/ui';
2018-12-13 13:39:08 +05:30
import delayedJobMixin from '~/jobs/mixins/delayed_job_mixin';
2021-03-11 19:13:27 +05:30
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
import { sprintf } from '~/locale';
2021-04-29 21:17:54 +05:30
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import { reportToSentry } from '../../utils';
import ActionComponent from '../jobs_shared/action_component.vue';
import JobNameComponent from '../jobs_shared/job_name_component.vue';
2021-02-22 17:27:13 +05:30
import { accessValue } from './accessors';
2021-04-29 21:17:54 +05:30
import { REST, SINGLE_JOB } from './constants';
2018-05-09 12:01:36 +05:30
/**
* 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": {
2018-11-18 11:00:15 +05:30
* "icon": "status_success",
2018-05-09 12:01:36 +05:30
* "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 {
2020-11-24 15:15:51 +05:30
hoverClass: 'gl-shadow-x0-y0-b3-s1-blue-500',
2018-05-09 12:01:36 +05:30
components: {
ActionComponent,
2021-04-29 21:17:54 +05:30
CiIcon,
2018-05-09 12:01:36 +05:30
JobNameComponent,
2019-02-15 15:39:39 +05:30
GlLink,
2018-05-09 12:01:36 +05:30
},
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2018-05-09 12:01:36 +05:30
},
2018-12-13 13:39:08 +05:30
mixins: [delayedJobMixin],
2021-02-22 17:27:13 +05:30
inject: {
dataMethod: {
default: REST,
},
},
2018-05-09 12:01:36 +05:30
props: {
job: {
type: Object,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
cssClassJobName: {
type: String,
required: false,
default: '',
2018-03-17 18:26:18 +05:30
},
2018-11-08 19:23:39 +05:30
dropdownLength: {
type: Number,
required: false,
default: Infinity,
},
2021-04-29 21:17:54 +05:30
groupTooltip: {
type: String,
required: false,
default: '',
},
2020-07-28 23:09:34 +05:30
jobHovered: {
type: String,
required: false,
default: '',
},
2020-11-24 15:15:51 +05:30
pipelineExpanded: {
type: Object,
required: false,
default: () => ({}),
},
2021-03-08 18:12:59 +05:30
pipelineId: {
type: Number,
required: false,
default: -1,
},
2021-04-29 21:17:54 +05:30
sourceJobHovered: {
type: String,
required: false,
default: '',
},
stageName: {
type: String,
required: false,
default: '',
},
type: {
type: String,
required: false,
default: SINGLE_JOB,
},
2018-05-09 12:01:36 +05:30
},
computed: {
2019-07-07 11:18:12 +05:30
boundary() {
return this.dropdownLength === 1 ? 'viewport' : 'scrollParent';
},
2021-04-29 21:17:54 +05:30
computedJobId() {
return this.pipelineId > -1 ? `${this.job.name}-${this.pipelineId}` : '';
},
2021-02-22 17:27:13 +05:30
detailsPath() {
return accessValue(this.dataMethod, 'detailsPath', this.status);
},
hasDetails() {
return accessValue(this.dataMethod, 'hasDetails', this.status);
},
2021-04-29 21:17:54 +05:30
isSingleItem() {
return this.type === SINGLE_JOB;
},
nameComponent() {
return this.hasDetails ? 'gl-link' : 'div';
},
showStageName() {
return Boolean(this.stageName);
2021-03-08 18:12:59 +05:30
},
2018-05-09 12:01:36 +05:30
status() {
return this.job && this.job.status ? this.job.status : {};
},
2021-04-29 21:17:54 +05:30
testId() {
return this.hasDetails ? 'job-with-link' : 'job-without-link';
},
2018-05-09 12:01:36 +05:30
tooltipText() {
2021-04-29 21:17:54 +05:30
if (this.groupTooltip) {
return this.groupTooltip;
}
2018-05-09 12:01:36 +05:30
const textBuilder = [];
2018-12-13 13:39:08 +05:30
const { name: jobName } = this.job;
2018-05-09 12:01:36 +05:30
2018-12-13 13:39:08 +05:30
if (jobName) {
textBuilder.push(jobName);
2018-05-09 12:01:36 +05:30
}
2018-12-13 13:39:08 +05:30
const { tooltip: statusTooltip } = this.status;
if (jobName && statusTooltip) {
2018-05-09 12:01:36 +05:30
textBuilder.push('-');
}
2018-12-13 13:39:08 +05:30
if (statusTooltip) {
if (this.isDelayedJob) {
textBuilder.push(sprintf(statusTooltip, { remainingTime: this.remainingTime }));
} else {
textBuilder.push(statusTooltip);
}
2018-05-09 12:01:36 +05:30
}
return textBuilder.join(' ');
2017-08-17 22:00:37 +05:30
},
2018-05-09 12:01:36 +05:30
/**
* 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;
2017-08-17 22:00:37 +05:30
},
2020-11-24 15:15:51 +05:30
relatedDownstreamHovered() {
2021-04-29 21:17:54 +05:30
return this.job.name === this.sourceJobHovered;
2020-11-24 15:15:51 +05:30
},
relatedDownstreamExpanded() {
return this.job.name === this.pipelineExpanded.jobName && this.pipelineExpanded.expanded;
},
2020-07-28 23:09:34 +05:30
jobClasses() {
2020-11-24 15:15:51 +05:30
return this.relatedDownstreamHovered || this.relatedDownstreamExpanded
2020-07-28 23:09:34 +05:30
? `${this.$options.hoverClass} ${this.cssClassJobName}`
: this.cssClassJobName;
},
2018-05-09 12:01:36 +05:30
},
2021-03-08 18:12:59 +05:30
errorCaptured(err, _vm, info) {
reportToSentry('job_item', `error: ${err}, info: ${info}`);
},
2018-10-15 14:42:47 +05:30
methods: {
2021-01-29 00:20:46 +05:30
hideTooltips() {
2021-03-11 19:13:27 +05:30
this.$root.$emit(BV_HIDE_TOOLTIP);
2021-01-29 00:20:46 +05:30
},
2021-04-29 21:17:54 +05:30
jobItemClick(evt) {
if (this.isSingleItem) {
/*
This is so the jobDropdown still toggles. Issue to refactor:
https://gitlab.com/gitlab-org/gitlab/-/issues/267117
*/
evt.stopPropagation();
}
this.hideTooltips();
},
2018-10-15 14:42:47 +05:30
pipelineActionRequestComplete() {
this.$emit('pipelineActionRequestComplete');
},
},
2018-05-09 12:01:36 +05:30
};
2017-08-17 22:00:37 +05:30
</script>
<template>
2021-02-22 17:27:13 +05:30
<div
2021-03-08 18:12:59 +05:30
:id="computedJobId"
2021-04-29 21:17:54 +05:30
class="ci-job-component gl-display-flex gl-align-items-center gl-justify-content-space-between gl-w-full"
2021-02-22 17:27:13 +05:30
data-qa-selector="job_item_container"
>
2021-04-29 21:17:54 +05:30
<component
:is="nameComponent"
v-gl-tooltip="{
boundary: 'viewport',
placement: 'bottom',
customClass: 'gl-pointer-events-none',
}"
2017-08-17 22:00:37 +05:30
:title="tooltipText"
2020-07-28 23:09:34 +05:30
:class="jobClasses"
2021-04-29 21:17:54 +05:30
:href="detailsPath"
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 gl-w-full"
:data-testid="testId"
@click="jobItemClick"
2021-01-29 00:20:46 +05:30
@mouseout="hideTooltips"
2018-03-17 18:26:18 +05:30
>
2021-04-29 21:17:54 +05:30
<div class="ci-job-name-component gl-display-flex gl-align-items-center">
<ci-icon :size="24" :status="job.status" class="gl-line-height-0" />
<div class="gl-pl-3 gl-display-flex gl-flex-direction-column gl-w-full">
<div class="gl-text-truncate mw-70p gl-line-height-normal">{{ job.name }}</div>
<div
v-if="showStageName"
data-testid="stage-name-in-job"
class="gl-text-truncate mw-70p gl-font-sm gl-text-gray-500 gl-line-height-normal"
>
{{ stageName }}
</div>
</div>
</div>
</component>
2017-08-17 22:00:37 +05:30
<action-component
2018-10-15 14:42:47 +05:30
v-if="hasAction"
2018-03-17 18:26:18 +05:30
:tooltip-text="status.action.title"
:link="status.action.path"
:action-icon="status.action.icon"
2021-04-29 21:17:54 +05:30
class="gl-mr-1"
2021-01-03 14:25:43 +05:30
data-qa-selector="action_button"
2018-10-15 14:42:47 +05:30
@pipelineActionRequestComplete="pipelineActionRequestComplete"
2018-03-17 18:26:18 +05:30
/>
2017-08-17 22:00:37 +05:30
</div>
</template>