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

admin_jobs_table_app.vue « table « components « jobs « admin « pages « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f93e9583d032f6010a09e1f086d364a73398fd5 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<script>
import { GlAlert } from '@gitlab/ui';
import { __ } from '~/locale';
import { queryToObject } from '~/lib/utils/url_utility';
import { validateQueryString } from '~/jobs/components/filtered_search/utils';
import JobsTable from '~/jobs/components/table/jobs_table.vue';
import JobsTableTabs from '~/jobs/components/table/jobs_table_tabs.vue';
import JobsTableEmptyState from '~/jobs/components/table/jobs_table_empty_state.vue';
import { DEFAULT_FIELDS_ADMIN } from '../constants';
import JobsSkeletonLoader from '../jobs_skeleton_loader.vue';
import GetAllJobs from './graphql/queries/get_all_jobs.query.graphql';
import CancelableJobs from './graphql/queries/get_cancelable_jobs_count.query.graphql';

export default {
  i18n: {
    jobsFetchErrorMsg: __('There was an error fetching the jobs.'),
  },
  components: {
    JobsSkeletonLoader,
    JobsTableEmptyState,
    GlAlert,
    JobsTable,
    JobsTableTabs,
  },
  inject: {
    jobStatuses: {
      default: null,
      required: false,
    },
    url: {
      default: '',
      required: false,
    },
    emptyStateSvgPath: {
      default: '',
      required: false,
    },
  },
  apollo: {
    jobs: {
      query: GetAllJobs,
      variables() {
        return this.variables;
      },
      update(data) {
        const { jobs: { nodes: list = [], pageInfo = {}, count } = {} } = data || {};
        return {
          list,
          pageInfo,
          count,
        };
      },
      error() {
        this.error = this.$options.i18n.jobsFetchErrorMsg;
      },
    },
    cancelable: {
      query: CancelableJobs,
      update(data) {
        this.isCancelable = data.cancelable.count !== 0;
      },
    },
  },
  data() {
    return {
      jobs: {
        list: [],
      },
      error: '',
      count: 0,
      scope: null,
      infiniteScrollingTriggered: false,
      filterSearchTriggered: false,
      DEFAULT_FIELDS_ADMIN,
      isCancelable: false,
    };
  },
  computed: {
    loading() {
      return this.$apollo.queries.jobs.loading;
    },
    // Show when on All tab with no jobs
    // Show only when not loading and filtered search has not been triggered
    // So we don't show empty state when results are empty on a filtered search
    showEmptyState() {
      return (
        this.jobs.list.length === 0 && !this.scope && !this.loading && !this.filterSearchTriggered
      );
    },
    variables() {
      return { ...this.validatedQueryString };
    },
    validatedQueryString() {
      const queryStringObject = queryToObject(window.location.search);

      return validateQueryString(queryStringObject);
    },
    jobsCount() {
      return this.jobs.count;
    },
    showLoadingSpinner() {
      return this.loading && this.infiniteScrollingTriggered;
    },
    showSkeletonLoader() {
      return this.loading && !this.showLoadingSpinner;
    },
  },
  watch: {
    // this watcher ensures that the count on the all tab
    //  is not updated when switching to the finished tab
    jobsCount(newCount) {
      if (this.scope) return;

      this.count = newCount;
    },
  },
  methods: {
    fetchJobsByStatus(scope) {
      this.infiniteScrollingTriggered = false;

      this.scope = scope;

      this.$apollo.queries.jobs.refetch({ statuses: scope });
    },
  },
};
</script>

<template>
  <div>
    <gl-alert v-if="error" class="gl-mt-2" variant="danger" dismissible @dismiss="error = ''">
      {{ error }}
    </gl-alert>

    <jobs-table-tabs
      :all-jobs-count="count"
      :loading="loading"
      :show-cancel-all-jobs-button="isCancelable"
      @fetchJobsByStatus="fetchJobsByStatus"
    />

    <jobs-skeleton-loader v-if="showSkeletonLoader" class="gl-mt-5" />

    <jobs-table-empty-state v-else-if="showEmptyState" />

    <jobs-table
      v-else
      :jobs="jobs.list"
      :table-fields="DEFAULT_FIELDS_ADMIN"
      class="gl-table-no-top-border"
    />
  </div>
</template>