Skip to content

Commit 8a1cf8f

Browse files
committed
feat(ui): optimize loading tasks
1 parent 266268d commit 8a1cf8f

File tree

6 files changed

+43
-60
lines changed

6 files changed

+43
-60
lines changed

web/src/components/ItemFormBase.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from 'axios';
22
import { getErrorMessage } from '@/lib/error';
3+
import ProjectMixin from '@/components/ProjectMixin';
34

45
/**
56
* Most of Semaphore entities (keys, environments, etc) have similar REST API for
@@ -23,6 +24,9 @@ import { getErrorMessage } from '@/lib/error';
2324
* (GET, POST, PUT, DELETE methods).
2425
*/
2526
export default {
27+
28+
mixins: [ProjectMixin],
29+
2630
props: {
2731
itemId: [Number, String],
2832
projectId: [Number, String],

web/src/components/NewTaskDialog.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<template>
22
<EditDialog
33
v-model="dialog"
4-
:save-button-text="$t(TEMPLATE_TYPE_ACTION_TITLES[templateType])"
4+
:save-button-text="$t(TEMPLATE_TYPE_ACTION_TITLES[template?.type || ''])"
55
:title="$t('newTask')"
66
@save="closeDialog"
77
@close="closeDialog"
88
test-id="newTaskDialog"
99
>
1010
<template v-slot:title={}>
11-
<v-icon small class="mr-4">{{ TEMPLATE_TYPE_ICONS[templateType] }}</v-icon>
12-
<span class="breadcrumbs__item">{{ templateAlias }}</span>
11+
<v-icon small class="mr-4">{{ TEMPLATE_TYPE_ICONS[template?.type || ''] }}</v-icon>
12+
<span class="breadcrumbs__item">{{ template?.alias || '' }}</span>
1313
<v-icon>mdi-chevron-right</v-icon>
1414
<span class="breadcrumbs__item">{{ $t('newTask') }}</span>
1515
</template>
@@ -18,7 +18,7 @@
1818
<TaskForm
1919
:project-id="projectId"
2020
item-id="new"
21-
:template-id="templateId"
21+
:template="template"
2222
@save="onSave"
2323
@error="onError"
2424
:need-save="needSave"
@@ -43,10 +43,7 @@ export default {
4343
props: {
4444
value: Boolean,
4545
projectId: Number,
46-
templateId: [Number, String],
47-
templateType: String,
48-
templateAlias: String,
49-
templateApp: String,
46+
template: Object,
5047
sourceTask: Object,
5148
},
5249
data() {

web/src/components/TaskForm.vue

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
dense
118118
required
119119
:disabled="formSaving"
120-
v-if="needField('inventory') && (template.task_params || {}).allow_override_inventory"
120+
v-if="needInventory"
121121
></v-select>
122122

123123
<ArgsPicker
@@ -183,7 +183,7 @@ export default {
183183
mixins: [ItemFormBase, AppFieldsMixin],
184184
185185
props: {
186-
templateId: Number,
186+
template: Object,
187187
sourceTask: Object,
188188
},
189189
@@ -194,7 +194,6 @@ export default {
194194
195195
data() {
196196
return {
197-
template: null,
198197
buildTasks: null,
199198
hasCommit: null,
200199
editedEnvironment: null,
@@ -212,6 +211,10 @@ export default {
212211
},
213212
214213
computed: {
214+
needInventory() {
215+
return this.needField('inventory') && this.template.task_params?.allow_override_inventory;
216+
},
217+
215218
args() {
216219
return JSON.parse(this.item.arguments || '[]');
217220
},
@@ -243,16 +246,16 @@ export default {
243246
needReset(val) {
244247
if (val) {
245248
if (this.item) {
246-
this.item.template_id = this.templateId;
249+
this.item.template_id = this.template.id;
247250
}
248251
this.inventory = null;
249-
this.template = null;
252+
// this.template = null;
250253
}
251254
},
252255
253-
templateId(val) {
256+
template(val) {
254257
if (this.item) {
255-
this.item.template_id = val;
258+
this.item.template_id = val?.id;
256259
}
257260
},
258261
@@ -330,29 +333,29 @@ export default {
330333
async afterLoadData() {
331334
this.assignItem(this.sourceTask);
332335
333-
this.item.template_id = this.templateId;
336+
this.item.template_id = this.template.id;
334337
335338
if (!this.item.params) {
336339
this.item.params = {};
337340
}
338341
339-
this.template = (await axios({
340-
keys: 'get',
341-
url: `/api/project/${this.projectId}/templates/${this.templateId}`,
342-
responseType: 'json',
343-
})).data;
342+
[
343+
this.buildTasks,
344+
this.inventory,
345+
] = await Promise.all([
344346
345-
this.buildTasks = this.template.type === 'deploy' ? (await axios({
346-
keys: 'get',
347-
url: `/api/project/${this.projectId}/templates/${this.template.build_template_id}/tasks?status=success`,
348-
responseType: 'json',
349-
})).data.filter((task) => task.status === 'success') : [];
347+
this.template.type === 'deploy' ? (await axios({
348+
keys: 'get',
349+
url: `/api/project/${this.projectId}/templates/${this.template.build_template_id}/tasks?status=success`,
350+
responseType: 'json',
351+
})).data.filter((task) => task.status === 'success') : [],
350352
351-
this.inventory = (await axios({
352-
keys: 'get',
353-
url: this.getInventoryUrl(),
354-
responseType: 'json',
355-
})).data;
353+
this.needInventory ? (await axios({
354+
keys: 'get',
355+
url: this.getInventoryUrl(),
356+
responseType: 'json',
357+
})).data : [],
358+
]);
356359
357360
if (this.item.build_task_id == null
358361
&& this.buildTasks.length > 0
@@ -384,7 +387,7 @@ export default {
384387
switch (this.app) {
385388
case 'terraform':
386389
case 'tofu':
387-
res += `&template_id=${this.templateId}`;
390+
res += `&template_id=${this.template.id}`;
388391
break;
389392
default:
390393
break;

web/src/components/TaskList.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
<NewTaskDialog
55
v-model="newTaskDialog"
66
:project-id="template.project_id"
7-
:template-id="template.id"
8-
:template-alias="template.name"
9-
:template-type="template.type"
10-
:template-app="template.app"
7+
:template="template"
118
:source-task="sourceTask"
129
/>
1310

web/src/views/project/TemplateView.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
<NewTaskDialog
77
v-model="newTaskDialog"
88
:project-id="projectId"
9-
:template-id="itemId"
10-
:template-alias="item.name"
11-
:template-type="item.type"
12-
:template-app="item.app"
9+
:template="item"
1310
/>
1411

1512
<EditTemplateDialog

web/src/views/project/Templates.vue

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
@save="itemId = null"
4141
@close="itemId = null"
4242
:project-id="projectId"
43+
:template="template"
4344
:template-id="itemId"
44-
:template-alias="templateAlias"
45-
:template-type="templateType"
46-
:template-app="templateApp"
4745
/>
4846

4947
<v-toolbar flat>
@@ -315,32 +313,19 @@ export default {
315313
};
316314
},
317315
computed: {
316+
318317
viewId() {
319318
if (/^-?\d+$/.test(this.$route.params.viewId)) {
320319
return parseInt(this.$route.params.viewId, 10);
321320
}
322321
return this.$route.params.viewId;
323322
},
324323
325-
templateType() {
326-
if (this.itemId == null || this.itemId === 'new') {
327-
return '';
328-
}
329-
return this.items.find((x) => x.id === this.itemId).type;
330-
},
331-
332-
templateAlias() {
333-
if (this.itemId == null || this.itemId === 'new') {
334-
return '';
335-
}
336-
return this.items.find((x) => x.id === this.itemId).name;
337-
},
338-
339-
templateApp() {
324+
template() {
340325
if (this.itemId == null || this.itemId === 'new') {
341-
return '';
326+
return null;
342327
}
343-
return this.items.find((x) => x.id === this.itemId).app;
328+
return this.items.find((x) => x.id === this.itemId);
344329
},
345330
346331
isLoaded() {

0 commit comments

Comments
 (0)