Welcome to mirror list, hosted at ThFree Co, Russian Federation.

app.vue « bridge « jobs « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c639e49083bd0f25f365890cceb30745522426e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { __, sprintf } from '~/locale';
import CiHeader from '~/vue_shared/components/header_ci_component.vue';
import getPipelineQuery from './graphql/queries/pipeline.query.graphql';
import BridgeEmptyState from './components/empty_state.vue';
import BridgeSidebar from './components/sidebar.vue';
import { SIDEBAR_COLLAPSE_BREAKPOINTS } from './components/constants';

export default {
  name: 'BridgePageApp',
  components: {
    BridgeEmptyState,
    BridgeSidebar,
    CiHeader,
    GlLoadingIcon,
  },
  inject: ['buildId', 'projectFullPath', 'pipelineIid'],
  apollo: {
    pipeline: {
      query: getPipelineQuery,
      variables() {
        return {
          fullPath: this.projectFullPath,
          iid: this.pipelineIid,
        };
      },
      update(data) {
        if (!data?.project?.pipeline) {
          return null;
        }

        const { pipeline } = data.project;
        const stages = pipeline?.stages.edges.map((edge) => edge.node) || [];
        const jobs = stages.map((stage) => stage.jobs.nodes).flat();

        return {
          ...pipeline,
          commit: {
            ...pipeline.commit,
            commit_path: pipeline.commit.webPath,
            short_id: pipeline.commit.shortId,
          },
          id: getIdFromGraphQLId(pipeline.id),
          jobs,
          stages,
        };
      },
    },
  },
  data() {
    return {
      isSidebarExpanded: true,
      pipeline: {},
    };
  },
  computed: {
    bridgeJob() {
      return (
        this.pipeline.jobs?.filter(
          (job) => getIdFromGraphQLId(job.id) === Number(this.buildId),
        )[0] || {}
      );
    },
    bridgeName() {
      return sprintf(__('Job %{jobName}'), { jobName: this.bridgeJob.name });
    },
    isPipelineLoading() {
      return this.$apollo.queries.pipeline.loading;
    },
  },
  created() {
    window.addEventListener('resize', this.onResize);
  },
  mounted() {
    this.onResize();
  },
  methods: {
    toggleSidebar() {
      this.isSidebarExpanded = !this.isSidebarExpanded;
    },
    onResize() {
      const breakpoint = bp.getBreakpointSize();
      if (SIDEBAR_COLLAPSE_BREAKPOINTS.includes(breakpoint)) {
        this.isSidebarExpanded = false;
      } else if (!this.isSidebarExpanded) {
        this.isSidebarExpanded = true;
      }
    },
  },
};
</script>
<template>
  <div>
    <gl-loading-icon v-if="isPipelineLoading" size="lg" class="gl-mt-4" />
    <div v-else>
      <ci-header
        class="gl-border-b-1 gl-border-b-solid gl-border-b-gray-100"
        :status="bridgeJob.detailedStatus"
        :time="bridgeJob.createdAt"
        :user="pipeline.user"
        :has-sidebar-button="true"
        :item-name="bridgeName"
        @clickedSidebarButton="toggleSidebar"
      />
      <bridge-empty-state :downstream-pipeline-path="bridgeJob.downstreamPipeline.path" />
      <bridge-sidebar
        v-if="isSidebarExpanded"
        :bridge-job="bridgeJob"
        :commit="pipeline.commit"
        :is-sidebar-expanded="isSidebarExpanded"
        @toggleSidebar="toggleSidebar"
      />
    </div>
  </div>
</template>