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

198 lines
5.2 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-02-22 17:27:13 +05:30
import { accessValue } from './accessors';
2021-03-11 19:13:27 +05:30
import ActionComponent from './action_component.vue';
2021-02-22 17:27:13 +05:30
import { REST } from './constants';
2021-03-11 19:13:27 +05:30
import JobNameComponent from './job_name_component.vue';
2021-03-08 18:12:59 +05:30
import { reportToSentry } from './utils';
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,
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,
},
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,
},
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-02-22 17:27:13 +05:30
detailsPath() {
return accessValue(this.dataMethod, 'detailsPath', this.status);
},
hasDetails() {
return accessValue(this.dataMethod, 'hasDetails', this.status);
},
2021-03-08 18:12:59 +05:30
computedJobId() {
return this.pipelineId > -1 ? `${this.job.name}-${this.pipelineId}` : '';
},
2018-05-09 12:01:36 +05:30
status() {
return this.job && this.job.status ? this.job.status : {};
},
tooltipText() {
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() {
return this.job.name === this.jobHovered;
},
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
},
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-02-22 17:27:13 +05:30
class="ci-job-component gl-display-flex gl-align-items-center gl-justify-content-space-between"
data-qa-selector="job_item_container"
>
2019-02-15 15:39:39 +05:30
<gl-link
2021-02-22 17:27:13 +05:30
v-if="hasDetails"
2021-01-29 00:20:46 +05:30
v-gl-tooltip="{ boundary, placement: 'bottom', customClass: 'gl-pointer-events-none' }"
2021-02-22 17:27:13 +05:30
:href="detailsPath"
2017-08-17 22:00:37 +05:30
:title="tooltipText"
2020-11-24 15:15:51 +05:30
:class="jobClasses"
2021-03-08 18:12:59 +05:30
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"
2020-11-24 15:15:51 +05:30
data-testid="job-with-link"
2021-01-29 00:20:46 +05:30
@click.stop="hideTooltips"
@mouseout="hideTooltips"
2018-03-17 18:26:18 +05:30
>
2021-02-22 17:27:13 +05:30
<job-name-component :name="job.name" :status="job.status" :icon-size="24" />
2019-02-15 15:39:39 +05:30
</gl-link>
2017-08-17 22:00:37 +05:30
<div
2018-11-08 19:23:39 +05:30
v-else
2021-01-29 00:20:46 +05:30
v-gl-tooltip="{ boundary, 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-02-22 17:27:13 +05:30
class="js-job-component-tooltip non-details-job-component menu-item"
2020-07-28 23:09:34 +05:30
data-testid="job-without-link"
2021-01-29 00:20:46 +05:30
@mouseout="hideTooltips"
2018-03-17 18:26:18 +05:30
>
2021-02-22 17:27:13 +05:30
<job-name-component :name="job.name" :status="job.status" :icon-size="24" />
2017-08-17 22:00:37 +05:30
</div>
<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-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>