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

104 lines
2.7 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2020-11-24 15:15:51 +05:30
import { GlTooltipDirective, GlButton, GlLoadingIcon, GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { deprecatedCreateFlash as createFlash } from '~/flash';
2018-10-15 14:42:47 +05:30
import axios from '~/lib/utils/axios_utils';
2021-03-11 19:13:27 +05:30
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
2018-10-15 14:42:47 +05:30
import { dasherize } from '~/lib/utils/text_utility';
import { __ } from '~/locale';
2021-03-08 18:12:59 +05:30
import { reportToSentry } from './utils';
2018-10-15 14:42:47 +05:30
2018-05-09 12:01:36 +05:30
/**
2018-10-15 14:42:47 +05:30
* Renders either a cancel, retry or play icon button and handles the post request
*
* Used in:
* - mr widget mini pipeline graph: `mr_widget_pipeline.vue`
* - pipelines table
* - pipelines table in merge request page
* - pipelines table in commit page
2018-11-08 19:23:39 +05:30
* - pipelines detail page in big graph
2018-05-09 12:01:36 +05:30
*/
export default {
components: {
2020-11-24 15:15:51 +05:30
GlIcon,
2020-10-24 23:57:45 +05:30
GlButton,
2019-07-31 22:56:46 +05:30
GlLoadingIcon,
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
},
props: {
tooltipText: {
type: String,
required: true,
},
link: {
type: String,
required: true,
},
actionIcon: {
type: String,
required: true,
},
},
2018-10-15 14:42:47 +05:30
data() {
return {
isDisabled: false,
2019-07-31 22:56:46 +05:30
isLoading: false,
2018-10-15 14:42:47 +05:30
};
},
2018-05-09 12:01:36 +05:30
computed: {
cssClass() {
const actionIconDash = dasherize(this.actionIcon);
return `${actionIconDash} js-icon-${actionIconDash}`;
},
},
2021-03-08 18:12:59 +05:30
errorCaptured(err, _vm, info) {
reportToSentry('action_component', `error: ${err}, info: ${info}`);
},
2018-05-09 12:01:36 +05:30
methods: {
2018-10-15 14:42:47 +05:30
/**
* The request should not be handled here.
* However due to this component being used in several
* different apps it avoids repetition & complexity.
*
*/
2018-05-09 12:01:36 +05:30
onClickAction() {
2021-03-11 19:13:27 +05:30
this.$root.$emit(BV_HIDE_TOOLTIP, `js-ci-action-${this.link}`);
2018-10-15 14:42:47 +05:30
this.isDisabled = true;
2019-07-31 22:56:46 +05:30
this.isLoading = true;
2018-10-15 14:42:47 +05:30
2018-11-08 19:23:39 +05:30
axios
.post(`${this.link}.json`)
2018-10-15 14:42:47 +05:30
.then(() => {
this.isDisabled = false;
2019-07-31 22:56:46 +05:30
this.isLoading = false;
2018-10-15 14:42:47 +05:30
this.$emit('pipelineActionRequestComplete');
})
2021-03-08 18:12:59 +05:30
.catch((err) => {
2018-10-15 14:42:47 +05:30
this.isDisabled = false;
2019-07-31 22:56:46 +05:30
this.isLoading = false;
2018-10-15 14:42:47 +05:30
2021-03-08 18:12:59 +05:30
reportToSentry('action_component', err);
2018-10-15 14:42:47 +05:30
createFlash(__('An error occurred while making the request.'));
});
2017-08-17 22:00:37 +05:30
},
2018-05-09 12:01:36 +05:30
},
};
2017-08-17 22:00:37 +05:30
</script>
<template>
2020-10-24 23:57:45 +05:30
<gl-button
2019-02-15 15:39:39 +05:30
:id="`js-ci-action-${link}`"
v-gl-tooltip="{ boundary: 'viewport' }"
2017-08-17 22:00:37 +05:30
:title="tooltipText"
2018-11-08 19:23:39 +05:30
:class="cssClass"
:disabled="isDisabled"
2021-02-22 17:27:13 +05:30
class="js-ci-action gl-ci-action-icon-container ci-action-icon-container ci-action-icon-wrapper gl-display-flex gl-align-items-center gl-justify-content-center"
2021-01-03 14:25:43 +05:30
@click.stop="onClickAction"
2018-03-17 18:26:18 +05:30
>
2019-07-31 22:56:46 +05:30
<gl-loading-icon v-if="isLoading" class="js-action-icon-loading" />
2021-02-22 17:27:13 +05:30
<gl-icon v-else :name="actionIcon" class="gl-mr-0!" :aria-label="actionIcon" />
2020-10-24 23:57:45 +05:30
</gl-button>
2017-08-17 22:00:37 +05:30
</template>