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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
<script>
import { GlAlert, GlIntersectionObserver, GlLoadingIcon } from '@gitlab/ui';
import { __ } from '~/locale';
import { createAlert } from '~/alert';
import { setUrlParams, updateHistory, queryToObject } from '~/lib/utils/url_utility';
import JobsSkeletonLoader from '~/pages/admin/jobs/components/jobs_skeleton_loader.vue';
import JobsFilteredSearch from '../filtered_search/jobs_filtered_search.vue';
import { validateQueryString } from '../filtered_search/utils';
import GetJobs from './graphql/queries/get_jobs.query.graphql';
import GetJobsCount from './graphql/queries/get_jobs_count.query.graphql';
import JobsTable from './jobs_table.vue';
import JobsTableEmptyState from './jobs_table_empty_state.vue';
import JobsTableTabs from './jobs_table_tabs.vue';
import { RAW_TEXT_WARNING } from './constants';
export default {
i18n: {
jobsFetchErrorMsg: __('There was an error fetching the jobs for your project.'),
jobsCountErrorMsg: __('There was an error fetching the number of jobs for your project.'),
loadingAriaLabel: __('Loading'),
},
filterSearchBoxStyles:
'gl-my-0 gl-p-5 gl-bg-gray-10 gl-text-gray-900 gl-border-b gl-border-gray-100',
components: {
GlAlert,
JobsFilteredSearch,
JobsTable,
JobsTableEmptyState,
JobsTableTabs,
GlIntersectionObserver,
GlLoadingIcon,
JobsSkeletonLoader,
},
inject: {
fullPath: {
default: '',
},
},
apollo: {
jobs: {
query: GetJobs,
variables() {
return {
fullPath: this.fullPath,
...this.validatedQueryString,
};
},
update(data) {
const { jobs: { nodes: list = [], pageInfo = {} } = {} } = data.project || {};
return {
list,
pageInfo,
};
},
error() {
this.error = this.$options.i18n.jobsFetchErrorMsg;
},
},
jobsCount: {
query: GetJobsCount,
context: {
isSingleRequest: true,
},
variables() {
return {
fullPath: this.fullPath,
...this.validatedQueryString,
};
},
update({ project }) {
return project?.jobs?.count || 0;
},
error() {
this.error = this.$options.i18n.jobsCountErrorMsg;
},
},
},
data() {
return {
jobs: {
list: [],
},
error: '',
scope: null,
infiniteScrollingTriggered: false,
filterSearchTriggered: false,
jobsCount: null,
count: 0,
};
},
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
);
},
hasNextPage() {
return this.jobs?.pageInfo?.hasNextPage;
},
showLoadingSpinner() {
return this.loading && this.infiniteScrollingTriggered;
},
showSkeletonLoader() {
return this.loading && !this.showLoadingSpinner;
},
showFilteredSearch() {
return !this.scope;
},
validatedQueryString() {
const queryStringObject = queryToObject(window.location.search);
return validateQueryString(queryStringObject);
},
},
watch: {
// this watcher ensures that the count on the all tab
// is not updated when switching to the finished tab
jobsCount(newCount, oldCount) {
if (this.scope) {
this.count = oldCount;
} else {
this.count = newCount;
}
},
},
methods: {
updateHistoryAndFetchCount(status = null) {
this.$apollo.queries.jobsCount.refetch({ statuses: status });
updateHistory({
url: setUrlParams({ statuses: status }, window.location.href, true),
});
},
fetchJobsByStatus(scope) {
this.infiniteScrollingTriggered = false;
if (this.scope === scope) return;
this.scope = scope;
if (!this.scope) this.updateHistoryAndFetchCount();
this.$apollo.queries.jobs.refetch({ statuses: scope });
},
filterJobsBySearch(filters) {
this.infiniteScrollingTriggered = false;
this.filterSearchTriggered = true;
// all filters have been cleared reset query param
// and refetch jobs/count with defaults
if (!filters.length) {
this.updateHistoryAndFetchCount();
this.$apollo.queries.jobs.refetch({ statuses: null });
return;
}
// Eventually there will be more tokens available
// this code is written to scale for those tokens
filters.forEach((filter) => {
// Raw text input in filtered search does not have a type
// when a user enters raw text we alert them that it is
// not supported and we do not make an additional API call
if (!filter.type) {
createAlert({
message: RAW_TEXT_WARNING,
type: 'warning',
});
}
if (filter.type === 'status') {
this.updateHistoryAndFetchCount(filter.value.data);
this.$apollo.queries.jobs.refetch({ statuses: filter.value.data });
}
});
},
fetchMoreJobs() {
if (!this.loading) {
this.infiniteScrollingTriggered = true;
this.$apollo.queries.jobs.fetchMore({
variables: {
fullPath: this.fullPath,
after: this.jobs?.pageInfo?.endCursor,
},
});
}
},
},
};
</script>
<template>
<div>
<gl-alert
v-if="error"
class="gl-mt-2"
variant="danger"
data-testid="jobs-table-error-alert"
dismissible
@dismiss="error = ''"
>
{{ error }}
</gl-alert>
<jobs-table-tabs
:all-jobs-count="count"
:loading="loading"
@fetchJobsByStatus="fetchJobsByStatus"
/>
<div v-if="showFilteredSearch" :class="$options.filterSearchBoxStyles">
<jobs-filtered-search
:query-string="validatedQueryString"
@filterJobsBySearch="filterJobsBySearch"
/>
</div>
<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" class="gl-table-no-top-border" />
<gl-intersection-observer v-if="hasNextPage" @appear="fetchMoreJobs">
<gl-loading-icon
v-if="showLoadingSpinner"
size="lg"
:aria-label="$options.i18n.loadingAriaLabel"
/>
</gl-intersection-observer>
</div>
</template>
|