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
|
<script>
import * as Sentry from '~/sentry/sentry_browser_wrapper';
import { convertToGraphQLId } from '~/graphql_shared/utils';
import { makeLoadCandidatesErrorMessage, NO_CANDIDATES_LABEL } from '../translations';
import getModelCandidatesQuery from '../graphql/queries/get_model_candidates.query.graphql';
import { GRAPHQL_PAGE_SIZE } from '../constants';
import SearchableList from './searchable_list.vue';
import CandidateListRow from './candidate_list_row.vue';
export default {
name: 'MlCandidateList',
components: {
CandidateListRow,
SearchableList,
},
props: {
modelId: {
type: Number,
required: true,
},
},
data() {
return {
candidates: {},
errorMessage: undefined,
};
},
apollo: {
candidates: {
query: getModelCandidatesQuery,
variables() {
return this.queryVariables;
},
update(data) {
return data.mlModel?.candidates ?? {};
},
error(error) {
this.handleError(error);
},
},
},
computed: {
gid() {
return convertToGraphQLId('Ml::Model', this.modelId);
},
isLoading() {
return this.$apollo.queries.candidates.loading;
},
pageInfo() {
return this.candidates?.pageInfo ?? {};
},
queryVariables() {
return {
id: this.gid,
first: GRAPHQL_PAGE_SIZE,
};
},
items() {
return this.candidates?.nodes ?? [];
},
},
methods: {
fetchPage(newPageInfo) {
const variables = {
...this.queryVariables,
...newPageInfo,
};
this.$apollo.queries.candidates
.fetchMore({
variables,
updateQuery: (previousResult, { fetchMoreResult }) => {
return fetchMoreResult;
},
})
.catch(this.handleError);
},
handleError(error) {
this.errorMessage = makeLoadCandidatesErrorMessage(error.message);
Sentry.captureException(error);
},
},
i18n: {
NO_CANDIDATES_LABEL,
},
};
</script>
<template>
<div>
<searchable-list
:page-info="pageInfo"
:items="items"
:error-message="errorMessage"
@fetch-page="fetchPage"
>
<template #empty-state>
{{ $options.i18n.NO_CANDIDATES_LABEL }}
</template>
<template #item="{ item }">
<candidate-list-row :candidate="item" />
</template>
</searchable-list>
</div>
</template>
|