1
1
<script >
2
- import { GlToggle } from ' @gitlab/ui' ;
2
+ import { GlToggle , GlLoadingIcon } from ' @gitlab/ui' ;
3
3
import { sprintf , s__ } from ' ~/locale' ;
4
4
import {
5
5
FORM_TYPES ,
@@ -12,7 +12,10 @@ import {
12
12
WORK_ITEM_TYPE_ENUM_EPIC ,
13
13
I18N_WORK_ITEM_SHOW_LABELS ,
14
14
CHILD_ITEMS_ANCHOR ,
15
+ DEFAULT_PAGE_SIZE_CHILD_ITEMS ,
15
16
} from ' ../../constants' ;
17
+ import { findHierarchyWidgets } from ' ../../utils' ;
18
+ import getWorkItemTreeQuery from ' ../../graphql/work_item_tree.query.graphql' ;
16
19
import WidgetWrapper from ' ../widget_wrapper.vue' ;
17
20
import WorkItemActionsSplitButton from ' ./work_item_actions_split_button.vue' ;
18
21
import WorkItemLinksForm from ' ./work_item_links_form.vue' ;
@@ -31,6 +34,7 @@ export default {
31
34
WorkItemChildrenWrapper,
32
35
WorkItemTreeActions,
33
36
GlToggle,
37
+ GlLoadingIcon,
34
38
},
35
39
inject: [' hasSubepicsFeature' ],
36
40
props: {
@@ -61,11 +65,6 @@ export default {
61
65
required: false ,
62
66
default: false ,
63
67
},
64
- children: {
65
- type: Array ,
66
- required: false ,
67
- default : () => [],
68
- },
69
68
canUpdate: {
70
69
type: Boolean ,
71
70
required: false ,
@@ -92,6 +91,28 @@ export default {
92
91
showLabels: true ,
93
92
};
94
93
},
94
+ apollo: {
95
+ hierarchyWidget: {
96
+ query: getWorkItemTreeQuery,
97
+ variables () {
98
+ return {
99
+ id: this .workItemId ,
100
+ pageSize: DEFAULT_PAGE_SIZE_CHILD_ITEMS ,
101
+ };
102
+ },
103
+ skip () {
104
+ return ! this .workItemId ;
105
+ },
106
+ update ({ workItem = {} }) {
107
+ const { children } = findHierarchyWidgets (workItem .widgets );
108
+ this .$emit (' childrenLoaded' , Boolean (children? .count ));
109
+ return children || {};
110
+ },
111
+ error () {
112
+ this .error = s__ (' WorkItems|An error occurred while fetching children' );
113
+ },
114
+ },
115
+ },
95
116
computed: {
96
117
childrenIds () {
97
118
return this .children .map ((c ) => c .id );
@@ -135,6 +156,15 @@ export default {
135
156
canShowActionsMenu () {
136
157
return this .workItemType .toUpperCase () === WORK_ITEM_TYPE_ENUM_EPIC && this .workItemIid ;
137
158
},
159
+ children () {
160
+ return this .hierarchyWidget ? .nodes || [];
161
+ },
162
+ isLoadingChildren () {
163
+ return this .$apollo .queries .hierarchyWidget .loading ;
164
+ },
165
+ showEmptyMessage () {
166
+ return ! this .isShownAddForm && this .children .length === 0 && ! this .isLoadingChildren ;
167
+ },
138
168
},
139
169
methods: {
140
170
genericActionItems (workItem ) {
@@ -206,7 +236,7 @@ export default {
206
236
< / template>
207
237
< template #body>
208
238
< div class = " gl-new-card-content gl-px-0" >
209
- < div v- if = " !isShownAddForm && children.length === 0 " data- testid= " tree-empty" >
239
+ < div v- if = " showEmptyMessage " data- testid= " tree-empty" >
210
240
< p class = " gl-new-card-empty" >
211
241
{{ $options .WORK_ITEMS_TREE_TEXT_MAP [workItemType].empty }}
212
242
< / p>
@@ -227,6 +257,7 @@ export default {
227
257
@addChild= " $emit('addChild')"
228
258
/ >
229
259
< work- item- children- wrapper
260
+ v- if = " !isLoadingChildren"
230
261
: children= " children"
231
262
: can- update= " canUpdateChildren"
232
263
: full- path= " fullPath"
@@ -237,6 +268,7 @@ export default {
237
268
@error= " error = $event"
238
269
@show- modal= " showModal"
239
270
/ >
271
+ < gl- loading- icon v- else size= " md" / >
240
272
< / div>
241
273
< / template>
242
274
< / widget- wrapper>
0 commit comments