Skip to content

Commit 3ab400d

Browse files
committed
Show dashboard code in CodeMirror
1 parent 0aad455 commit 3ab400d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

frontend/src/chat/chat-message-script/chat-message-script.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<div class="my-4">
7575
<label class="block text-sm font-medium leading-6 text-gray-900">Code</label>
7676
<div class="border border-gray-200">
77-
<textarea class="p-2 h-[300px] w-full" v-model="dashboardCode"></textarea>
77+
<textarea class="p-2 h-[300px] w-full" ref="dashboardCodeEditor"></textarea>
7878
</div>
7979
</div>
8080
<async-button

frontend/src/chat/chat-message-script/chat-message-script.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = app => app.component('chat-message-script', {
1414
showCreateDashboardModal: false,
1515
newDashboardTitle: '',
1616
dashboardCode: '',
17-
createErrors: []
17+
createErrors: [],
18+
dashboardEditor: null
1819
};
1920
},
2021
computed: {
@@ -39,8 +40,22 @@ module.exports = app => app.component('chat-message-script', {
3940
this.dashboardCode = this.script;
4041
this.createErrors = [];
4142
this.showCreateDashboardModal = true;
43+
this.$nextTick(() => {
44+
if (this.dashboardEditor) {
45+
this.dashboardEditor.toTextArea();
46+
}
47+
this.$refs.dashboardCodeEditor.value = this.dashboardCode;
48+
this.dashboardEditor = CodeMirror.fromTextArea(this.$refs.dashboardCodeEditor, {
49+
mode: 'javascript',
50+
lineNumbers: true
51+
});
52+
this.dashboardEditor.on('change', () => {
53+
this.dashboardCode = this.dashboardEditor.getValue();
54+
});
55+
});
4256
},
4357
async createDashboardFromScript() {
58+
this.dashboardCode = this.dashboardEditor.getValue();
4459
const { dashboard } = await api.Dashboard.createDashboard({
4560
code: this.dashboardCode,
4661
title: this.newDashboardTitle
@@ -70,6 +85,14 @@ module.exports = app => app.component('chat-message-script', {
7085
});
7186
}
7287
},
88+
watch: {
89+
showCreateDashboardModal(val) {
90+
if (!val && this.dashboardEditor) {
91+
this.dashboardEditor.toTextArea();
92+
this.dashboardEditor = null;
93+
}
94+
}
95+
},
7396
mounted() {
7497
Prism.highlightElement(this.$refs.code);
7598
if (this.message.executionResult?.output) {

0 commit comments

Comments
 (0)