-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathvalidate-comment-modal.js
More file actions
92 lines (79 loc) · 2.75 KB
/
Copy pathvalidate-comment-modal.js
File metadata and controls
92 lines (79 loc) · 2.75 KB
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
define([
'knockout',
'text!./validate-comment-modal.html',
'components/Component',
'utils/CommonUtils',
'utils/AutoBind',
'services/ConceptSet',
'services/AuthAPI',
'less!./validate-comment-modal.less',
'databindings',
], function (
ko,
view,
Component,
commonUtils,
AutoBind,
conceptSetService,
authApi,
) {
class ValidateCommentModal extends AutoBind(Component) {
constructor(params) {
super(params);
this.isModalShown = params.isModalShown;
this.onConfirm = params.onConfirm;
this.validationComment = ko.observable('');
this.selectedApproverId = ko.observable(null);
this.supportingInfo = ko.observable(params.supportingInfo || '');
this.delegateReviewers = ko.observableArray([]);
this.loadingReviewers = ko.observable(false);
this.canValidate = ko.computed(() => {
return this.validationComment() && this.validationComment().trim().length > 0;
});
this.isModalShown.subscribe((shown) => {
if (shown) {
this.resetForm();
this.loadDelegateReviewers();
}
});
}
async loadDelegateReviewers() {
this.loadingReviewers(true);
try {
const approvers = await conceptSetService.listApprovers('conceptset');
const formattedApprovers = approvers.data.map(approver => ({
...approver,
nameWithLogin: `${approver.name} (${approver.login})`,
}));
this.delegateReviewers(formattedApprovers);
const currentUser = formattedApprovers.find(a => a.id === authApi.id());
if (currentUser) {
this.selectedApproverId(currentUser.id);
}
} catch (error) {
console.error('Failed to load delegate reviewers:', error);
this.delegateReviewers([]);
} finally {
this.loadingReviewers(false);
}
}
resetForm() {
this.validationComment('');
this.supportingInfo(null);
}
confirm() {
const validationData = {
comment: this.validationComment(),
approverId: this.selectedApproverId(),
supportingInfo: this.supportingInfo()
};
this.onConfirm(validationData);
this.isModalShown(false);
}
cancel() {
this.resetForm();
this.isModalShown(false);
}
}
return commonUtils.build('validate-comment-modal', ValidateCommentModal, view);
});