2020-11-27 15:09:34 +00:00
|
|
|
<script>
|
|
|
|
import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import { __ } from '~/locale';
|
|
|
|
import { DEFAULT, LOAD_FAILURE } from '../../constants';
|
|
|
|
import getPipelineDetails from '../../graphql/queries/get_pipeline_details.query.graphql';
|
|
|
|
import PipelineGraph from './graph_component.vue';
|
2020-12-14 18:09:48 +00:00
|
|
|
import { unwrapPipelineData, toggleQueryPollingByVisibility } from './utils';
|
2020-11-27 15:09:34 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'PipelineGraphWrapper',
|
|
|
|
components: {
|
|
|
|
GlAlert,
|
|
|
|
GlLoadingIcon,
|
|
|
|
PipelineGraph,
|
|
|
|
},
|
|
|
|
inject: {
|
|
|
|
pipelineIid: {
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
pipelineProjectPath: {
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
pipeline: null,
|
|
|
|
alertType: null,
|
|
|
|
showAlert: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
errorTexts: {
|
|
|
|
[LOAD_FAILURE]: __('We are currently unable to fetch data for this pipeline.'),
|
|
|
|
[DEFAULT]: __('An unknown error occurred while loading this graph.'),
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
pipeline: {
|
|
|
|
query: getPipelineDetails,
|
2020-12-14 18:09:48 +00:00
|
|
|
pollInterval: 10000,
|
2020-11-27 15:09:34 +00:00
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
projectPath: this.pipelineProjectPath,
|
|
|
|
iid: this.pipelineIid,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update(data) {
|
2020-12-07 15:09:49 +00:00
|
|
|
return unwrapPipelineData(this.pipelineProjectPath, data);
|
2020-11-27 15:09:34 +00:00
|
|
|
},
|
|
|
|
error() {
|
|
|
|
this.reportFailure(LOAD_FAILURE);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
alert() {
|
|
|
|
switch (this.alertType) {
|
|
|
|
case LOAD_FAILURE:
|
|
|
|
return {
|
|
|
|
text: this.$options.errorTexts[LOAD_FAILURE],
|
|
|
|
variant: 'danger',
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return {
|
|
|
|
text: this.$options.errorTexts[DEFAULT],
|
|
|
|
variant: 'danger',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
2020-12-14 18:09:48 +00:00
|
|
|
showLoadingIcon() {
|
|
|
|
/*
|
|
|
|
Shows the icon only when the graph is empty, not when it is is
|
|
|
|
being refetched, for instance, on action completion
|
|
|
|
*/
|
|
|
|
return this.$apollo.queries.pipeline.loading && !this.pipeline;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
toggleQueryPollingByVisibility(this.$apollo.queries.pipeline);
|
2020-11-27 15:09:34 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
hideAlert() {
|
|
|
|
this.showAlert = false;
|
|
|
|
},
|
2020-12-14 18:09:48 +00:00
|
|
|
refreshPipelineGraph() {
|
|
|
|
this.$apollo.queries.pipeline.refetch();
|
|
|
|
},
|
2020-11-27 15:09:34 +00:00
|
|
|
reportFailure(type) {
|
|
|
|
this.showAlert = true;
|
|
|
|
this.failureType = type;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
2020-12-07 15:09:49 +00:00
|
|
|
<div>
|
|
|
|
<gl-alert v-if="showAlert" :variant="alert.variant" @dismiss="hideAlert">
|
|
|
|
{{ alert.text }}
|
|
|
|
</gl-alert>
|
2020-12-14 18:09:48 +00:00
|
|
|
<gl-loading-icon v-if="showLoadingIcon" class="gl-mx-auto gl-my-4" size="lg" />
|
|
|
|
<pipeline-graph
|
|
|
|
v-if="pipeline"
|
|
|
|
:pipeline="pipeline"
|
|
|
|
@error="reportFailure"
|
|
|
|
@refreshPipelineGraph="refreshPipelineGraph"
|
|
|
|
/>
|
2020-12-07 15:09:49 +00:00
|
|
|
</div>
|
2020-11-27 15:09:34 +00:00
|
|
|
</template>
|