blob: 0184801ce8073c9b0d7cecb2b56d4baa2cdd63cd (
plain)
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
|
export class MergeRequestGeneratedContent {
constructor({ editor } = {}) {
this.warningElement = document.querySelector('.js-ai-description-warning');
this.markdownEditor = editor;
this.generatedContent = null;
this.connectToDOM();
}
get hasEditor() {
return Boolean(this.markdownEditor);
}
get hasWarning() {
return Boolean(this.warningElement);
}
get canReplaceContent() {
return this.hasEditor && Boolean(this.generatedContent);
}
connectToDOM() {
let close;
let cancel;
let approve;
if (this.hasWarning) {
approve = this.warningElement.querySelector('.js-ai-override-description');
cancel = this.warningElement.querySelector('.js-cancel-btn');
close = this.warningElement.querySelector('.js-close-btn');
approve.addEventListener('click', () => {
this.replaceDescription();
this.hideWarning();
});
cancel.addEventListener('click', () => this.hideWarning());
close.addEventListener('click', () => this.hideWarning());
}
}
setEditor(markdownEditor) {
this.markdownEditor = markdownEditor;
}
setGeneratedContent(newContent) {
this.generatedContent = newContent;
}
clearGeneratedContent() {
this.generatedContent = null;
}
showWarning() {
if (this.canReplaceContent) {
this.warningElement?.classList.remove('hidden');
}
}
hideWarning() {
this.warningElement?.classList.add('hidden');
}
replaceDescription() {
if (this.canReplaceContent) {
this.markdownEditor.setValue(this.generatedContent);
this.clearGeneratedContent();
}
}
}
|