|
| 1 | +<script> |
| 2 | +import { GlLink, GlLoadingIcon, GlSprintf } from '@gitlab/ui'; |
| 3 | +import Visibility from 'visibilityjs'; |
| 4 | +import { createAlert } from '~/alert'; |
| 5 | +import { __, s__ } from '~/locale'; |
| 6 | +import { getIncreasedPollInterval } from '~/ci/utils/polling_utils'; |
| 7 | +import { NETWORK_STATUS_READY, PIPELINE_POLL_INTERVAL_DEFAULT } from '~/ci/constants'; |
| 8 | +import { getIdFromGraphQLId } from '~/graphql_shared/utils'; |
| 9 | +import CiIcon from '~/vue_shared/components/ci_icon/ci_icon.vue'; |
| 10 | +import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; |
| 11 | +import { getQueryHeaders } from '~/ci/pipeline_details/graph/utils'; |
| 12 | +import PipelineMiniGraph from '~/ci/pipeline_mini_graph/pipeline_mini_graph.vue'; |
| 13 | +import getPipelineMetadataQuery from './graphql/queries/get_pipeline_metadata.query.graphql'; |
| 14 | +
|
| 15 | +export default { |
| 16 | + name: 'PipelineSummary', |
| 17 | + i18n: { |
| 18 | + loadingText: s__('Pipeline|Checking pipeline status'), |
| 19 | + pipelineMetadataFetchError: __('There was a problem fetching the pipeline metadata.'), |
| 20 | + pipelineStatusText: s__('Pipelines|Pipeline %{linkStart}#%{pipelineId}%{linkEnd} %{status}'), |
| 21 | + }, |
| 22 | + components: { |
| 23 | + CiIcon, |
| 24 | + GlLink, |
| 25 | + GlLoadingIcon, |
| 26 | + GlSprintf, |
| 27 | + PipelineMiniGraph, |
| 28 | + TimeAgoTooltip, |
| 29 | + }, |
| 30 | + props: { |
| 31 | + fullPath: { |
| 32 | + type: String, |
| 33 | + required: true, |
| 34 | + }, |
| 35 | + iid: { |
| 36 | + type: String, |
| 37 | + required: true, |
| 38 | + }, |
| 39 | + pipelineEtag: { |
| 40 | + type: String, |
| 41 | + required: true, |
| 42 | + }, |
| 43 | + }, |
| 44 | + data() { |
| 45 | + return { |
| 46 | + pipelineInfo: {}, |
| 47 | + pollInterval: PIPELINE_POLL_INTERVAL_DEFAULT, |
| 48 | + }; |
| 49 | + }, |
| 50 | + apollo: { |
| 51 | + pipelineInfo: { |
| 52 | + context() { |
| 53 | + return getQueryHeaders(this.pipelineEtag); |
| 54 | + }, |
| 55 | + query: getPipelineMetadataQuery, |
| 56 | + notifyOnNetworkStatusChange: true, |
| 57 | + pollInterval() { |
| 58 | + return this.pollInterval; |
| 59 | + }, |
| 60 | + variables() { |
| 61 | + return { |
| 62 | + fullPath: this.fullPath, |
| 63 | + iid: this.iid, |
| 64 | + }; |
| 65 | + }, |
| 66 | + result({ networkStatus }) { |
| 67 | + // We need this for handling the reactive poll interval while also using frontend cache |
| 68 | + // a status of 7 = 'ready' |
| 69 | + if (networkStatus !== NETWORK_STATUS_READY) return; |
| 70 | + this.pollInterval = this.increasePollInterval(); |
| 71 | + }, |
| 72 | + update({ project }) { |
| 73 | + return project?.pipeline || {}; |
| 74 | + }, |
| 75 | + error() { |
| 76 | + createAlert({ message: this.$options.i18n.pipelineMetadataFetchError }); |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + computed: { |
| 81 | + finishedAt() { |
| 82 | + return this.pipelineInfo?.finishedAt; |
| 83 | + }, |
| 84 | + isLoading() { |
| 85 | + return this.$apollo.queries.pipelineInfo.loading; |
| 86 | + }, |
| 87 | + pipelineId() { |
| 88 | + return getIdFromGraphQLId(this.pipelineInfo?.id); |
| 89 | + }, |
| 90 | + pipelinePath() { |
| 91 | + return this.status?.detailsPath || ''; |
| 92 | + }, |
| 93 | + status() { |
| 94 | + return this.pipelineInfo?.detailedStatus || null; |
| 95 | + }, |
| 96 | + statusLabel() { |
| 97 | + return this.status?.label || ''; |
| 98 | + }, |
| 99 | + }, |
| 100 | + mounted() { |
| 101 | + Visibility.change(() => { |
| 102 | + this.handlePolling(); |
| 103 | + }); |
| 104 | + }, |
| 105 | + methods: { |
| 106 | + /** Note: cannot use `toggleQueryPollingByVisibility` because interval is dynamic */ |
| 107 | + handlePolling() { |
| 108 | + if (!Visibility.hidden()) { |
| 109 | + this.resetPollInterval(); |
| 110 | + } else { |
| 111 | + this.pollInterval = 0; |
| 112 | + } |
| 113 | + }, |
| 114 | + increasePollInterval() { |
| 115 | + return getIncreasedPollInterval(this.pollInterval); |
| 116 | + }, |
| 117 | + onJobActionExecuted() { |
| 118 | + this.resetPollInterval(); |
| 119 | + }, |
| 120 | + resetPollInterval() { |
| 121 | + this.pollInterval = PIPELINE_POLL_INTERVAL_DEFAULT; |
| 122 | + }, |
| 123 | + }, |
| 124 | +}; |
| 125 | +</script> |
| 126 | +
|
| 127 | +<template> |
| 128 | + <div class="w-100"> |
| 129 | + <div v-if="isLoading" class="align-items-center gl-mx-2 gl-flex"> |
| 130 | + <gl-loading-icon class="gl-mr-4" /> |
| 131 | + {{ $options.i18n.loadingText }} |
| 132 | + </div> |
| 133 | + <div v-else class="align-items-center w-100 gl-flex"> |
| 134 | + <div |
| 135 | + class="flex-grow-1 justify-space-between gl-flex gl-flex-wrap gl-gap-3" |
| 136 | + :class="{ 'align-items-center': !finishedAt }" |
| 137 | + > |
| 138 | + <ci-icon v-if="status" class="gl-mt-1 gl-self-start" :status="status" /> |
| 139 | + <div class="flex-grow-1 gl-flex gl-flex-col"> |
| 140 | + <span> |
| 141 | + <gl-sprintf :message="$options.i18n.pipelineStatusText"> |
| 142 | + <template #status>{{ statusLabel }}</template> |
| 143 | + <template #link="{ content }"> |
| 144 | + <gl-link :href="pipelinePath"> |
| 145 | + <gl-sprintf :message="content"> |
| 146 | + <template #pipelineId>{{ pipelineId }}</template> |
| 147 | + </gl-sprintf> |
| 148 | + </gl-link> |
| 149 | + </template> |
| 150 | + </gl-sprintf> |
| 151 | + </span> |
| 152 | + <time-ago-tooltip |
| 153 | + v-if="finishedAt" |
| 154 | + class="gl-line-height-0 gl-flex gl-text-sm gl-text-subtle" |
| 155 | + :time="finishedAt" |
| 156 | + tooltip-placement="bottom" |
| 157 | + /> |
| 158 | + </div> |
| 159 | + <pipeline-mini-graph |
| 160 | + data-testid="pipeline-summary-pipeline-mini-graph" |
| 161 | + :full-path="fullPath" |
| 162 | + :iid="iid" |
| 163 | + :pipeline-etag="pipelineEtag" |
| 164 | + @jobActionExecuted="onJobActionExecuted" |
| 165 | + /> |
| 166 | + </div> |
| 167 | + </div> |
| 168 | + </div> |
| 169 | +</template> |
0 commit comments