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

276 lines
7.3 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';
2022-04-04 11:22:00 +05:30
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-11-11 11:23:49 +05:30
import { 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],
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: {
2021-11-18 22:05:49 +05:30
type: [String, Array, Object],
2018-05-09 12:01:36 +05:30
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() {
2021-11-11 11:23:49 +05:30
return this.status.detailsPath;
2021-02-22 17:27:13 +05:30
},
hasDetails() {
2021-11-11 11:23:49 +05:30
return this.status.hasDetails;
2021-02-22 17:27:13 +05:30
},
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
},
2022-04-04 11:22:00 +05:30
hasUnauthorizedManualAction() {
return (
!this.hasAction &&
this.job.status?.group === 'manual' &&
this.job.status?.label?.includes('(not allowed)')
);
},
unauthorizedManualActionIcon() {
/*
The action object is not available when the user cannot run the action.
So we can show the correct icon, extract the action name from the label instead:
"manual play action (not allowed)" or "manual stop action (not allowed)"
*/
return this.job.status?.label?.split(' ')[1];
},
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() {
2021-11-18 22:05:49 +05:30
return [
{
[this.$options.hoverClass]:
this.relatedDownstreamHovered || this.relatedDownstreamExpanded,
},
this.cssClassJobName,
];
2020-07-28 23:09:34 +05:30
},
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:
2021-11-11 11:23:49 +05:30
https://gitlab.com/gitlab-org/gitlab/-/issues/267117
2021-04-29 21:17:54 +05:30
*/
evt.stopPropagation();
}
this.hideTooltips();
},
2018-10-15 14:42:47 +05:30
pipelineActionRequestComplete() {
this.$emit('pipelineActionRequestComplete');
},
},
2022-04-04 11:22:00 +05:30
i18n: {
unauthorizedTooltip: __('You are not authorized to run this manual job'),
},
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"
2022-01-26 12:08:38 +05:30
class="ci-job-component gl-display-flex gl-justify-content-space-between gl-pipeline-job-width"
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" />
2022-01-26 12:08:38 +05:30
<div class="gl-pl-3 gl-pr-3 gl-display-flex gl-flex-direction-column gl-pipeline-job-width">
<div class="gl-text-truncate gl-pr-9 gl-line-height-normal">{{ job.name }}</div>
2021-04-29 21:17:54 +05:30
<div
v-if="showStageName"
data-testid="stage-name-in-job"
2022-01-26 12:08:38 +05:30
class="gl-text-truncate gl-pr-9 gl-font-sm gl-text-gray-500 gl-line-height-normal"
2021-04-29 21:17:54 +05:30
>
{{ 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"
2022-04-04 11:22:00 +05:30
data-qa-selector="job_action_button"
2018-10-15 14:42:47 +05:30
@pipelineActionRequestComplete="pipelineActionRequestComplete"
2018-03-17 18:26:18 +05:30
/>
2022-04-04 11:22:00 +05:30
<action-component
v-if="hasUnauthorizedManualAction"
disabled
:tooltip-text="$options.i18n.unauthorizedTooltip"
:action-icon="unauthorizedManualActionIcon"
:link="`unauthorized-${computedJobId}`"
class="gl-mr-1"
/>
2017-08-17 22:00:37 +05:30
</div>
</template>