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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
<script>
import { GlButton, GlLink } from '@gitlab/ui';
import { createAlert } from '~/alert';
import { updateHistory } from '~/lib/utils/url_utility';
import { fetchPolicies } from '~/lib/graphql';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { upgradeStatusTokenConfig } from 'ee_else_ce/ci/runner/components/search_tokens/upgrade_status_token_config';
import {
fromUrlQueryToSearch,
fromSearchToUrl,
fromSearchToVariables,
isSearchFiltered,
} from 'ee_else_ce/ci/runner/runner_search_utils';
import allRunnersQuery from 'ee_else_ce/ci/runner/graphql/list/all_runners.query.graphql';
import allRunnersCountQuery from 'ee_else_ce/ci/runner/graphql/list/all_runners_count.query.graphql';
import RegistrationDropdown from '../components/registration/registration_dropdown.vue';
import RunnerFilteredSearchBar from '../components/runner_filtered_search_bar.vue';
import RunnerList from '../components/runner_list.vue';
import RunnerListEmptyState from '../components/runner_list_empty_state.vue';
import RunnerName from '../components/runner_name.vue';
import RunnerStats from '../components/stat/runner_stats.vue';
import RunnerPagination from '../components/runner_pagination.vue';
import RunnerTypeTabs from '../components/runner_type_tabs.vue';
import RunnerActionsCell from '../components/cells/runner_actions_cell.vue';
import RunnerJobStatusBadge from '../components/runner_job_status_badge.vue';
import { pausedTokenConfig } from '../components/search_tokens/paused_token_config';
import { statusTokenConfig } from '../components/search_tokens/status_token_config';
import { tagTokenConfig } from '../components/search_tokens/tag_token_config';
import {
ADMIN_FILTERED_SEARCH_NAMESPACE,
INSTANCE_TYPE,
I18N_FETCH_ERROR,
FILTER_CSS_CLASSES,
JOBS_ROUTE_PATH,
} from '../constants';
import { captureException } from '../sentry_utils';
export default {
name: 'AdminRunnersApp',
components: {
GlButton,
GlLink,
RegistrationDropdown,
RunnerFilteredSearchBar,
RunnerList,
RunnerListEmptyState,
RunnerName,
RunnerStats,
RunnerPagination,
RunnerTypeTabs,
RunnerActionsCell,
RunnerJobStatusBadge,
},
mixins: [glFeatureFlagMixin()],
props: {
newRunnerPath: {
type: String,
required: true,
},
registrationToken: {
type: String,
required: true,
},
},
data() {
return {
search: fromUrlQueryToSearch(),
runners: {
items: [],
pageInfo: {},
},
};
},
apollo: {
runners: {
query: allRunnersQuery,
context: {
isSingleRequest: true,
},
fetchPolicy: fetchPolicies.NETWORK_ONLY,
variables() {
return this.variables;
},
update(data) {
const { runners } = data;
return {
items: runners?.nodes || [],
pageInfo: runners?.pageInfo || {},
};
},
error(error) {
createAlert({ message: I18N_FETCH_ERROR });
this.reportToSentry(error);
},
},
},
computed: {
variables() {
return fromSearchToVariables(this.search);
},
countVariables() {
// Exclude pagination variables, leave only filters variables
const { sort, before, last, after, first, ...countVariables } = this.variables;
return countVariables;
},
runnersLoading() {
return this.$apollo.queries.runners.loading;
},
noRunnersFound() {
return !this.runnersLoading && !this.runners.items.length;
},
searchTokens() {
return [
pausedTokenConfig,
statusTokenConfig,
{
...tagTokenConfig,
recentSuggestionsStorageKey: `${this.$options.filteredSearchNamespace}-recent-tags`,
},
upgradeStatusTokenConfig,
];
},
isSearchFiltered() {
return isSearchFiltered(this.search);
},
shouldShowCreateRunnerWorkflow() {
// create_runner_workflow_for_admin feature flag
return this.glFeatures.createRunnerWorkflowForAdmin;
},
},
watch: {
search: {
deep: true,
handler() {
// TODO Implement back button response using onpopstate
// See: https://gitlab.com/gitlab-org/gitlab/-/issues/333804
updateHistory({
url: fromSearchToUrl(this.search),
title: document.title,
});
},
},
},
errorCaptured(error) {
this.reportToSentry(error);
},
methods: {
jobsUrl(runner) {
const url = new URL(runner.adminUrl);
url.hash = `#${JOBS_ROUTE_PATH}`;
return url.href;
},
onToggledPaused() {
// When a runner becomes Paused, the tab count can
// become stale, refetch outdated counts.
this.refetchCounts();
},
onDeleted({ message }) {
this.refetchCounts();
this.$root.$toast?.show(message);
},
refetchCounts() {
this.$apollo.getClient().refetchQueries({ include: [allRunnersCountQuery] });
},
reportToSentry(error) {
captureException({ error, component: this.$options.name });
},
onPaginationInput(value) {
this.search.pagination = value;
},
},
filteredSearchNamespace: ADMIN_FILTERED_SEARCH_NAMESPACE,
INSTANCE_TYPE,
FILTER_CSS_CLASSES,
};
</script>
<template>
<div>
<div
class="gl-display-flex gl-align-items-center gl-flex-direction-column-reverse gl-md-flex-direction-row gl-mt-3 gl-md-mt-0"
>
<runner-type-tabs
v-model="search"
:count-scope="$options.INSTANCE_TYPE"
:count-variables="countVariables"
class="gl-w-full"
content-class="gl-display-none"
nav-class="gl-border-none!"
/>
<div class="gl-w-full gl-md-w-auto gl-display-flex">
<gl-button v-if="shouldShowCreateRunnerWorkflow" :href="newRunnerPath" variant="confirm">
{{ s__('Runners|New instance runner') }}
</gl-button>
<registration-dropdown
class="gl-ml-3"
:registration-token="registrationToken"
:type="$options.INSTANCE_TYPE"
right
/>
</div>
</div>
<runner-filtered-search-bar
v-model="search"
:class="$options.FILTER_CSS_CLASSES"
:tokens="searchTokens"
:namespace="$options.filteredSearchNamespace"
/>
<runner-stats :scope="$options.INSTANCE_TYPE" :variables="countVariables" />
<runner-list-empty-state
v-if="noRunnersFound"
:registration-token="registrationToken"
:is-search-filtered="isSearchFiltered"
:new-runner-path="newRunnerPath"
/>
<template v-else>
<runner-list
:runners="runners.items"
:loading="runnersLoading"
:checkable="true"
@deleted="onDeleted"
>
<template #runner-job-status-badge="{ runner }">
<runner-job-status-badge
:href="jobsUrl(runner)"
:job-status="runner.jobExecutionStatus"
/>
</template>
<template #runner-name="{ runner }">
<gl-link :href="runner.adminUrl">
<runner-name :runner="runner" />
</gl-link>
</template>
<template #runner-actions-cell="{ runner }">
<runner-actions-cell
:runner="runner"
:edit-url="runner.editAdminUrl"
@toggledPaused="onToggledPaused"
@deleted="onDeleted"
/>
</template>
</runner-list>
</template>
<runner-pagination
class="gl-mt-3"
:disabled="runnersLoading"
:page-info="runners.pageInfo"
@input="onPaginationInput"
/>
</div>
</template>
|