From 0da71ae52b4238595b7f022708a833cbb2342e8e Mon Sep 17 00:00:00 2001 From: Gene Hynson Date: Thu, 27 Jul 2023 11:04:17 -0700 Subject: [PATCH 1/2] fix: save codemirror content to textarea --- airflow/www/static/js/connection_form.js | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/airflow/www/static/js/connection_form.js b/airflow/www/static/js/connection_form.js index 453be58411a9b..d0987f3fc8d52 100644 --- a/airflow/www/static/js/connection_form.js +++ b/airflow/www/static/js/connection_form.js @@ -202,6 +202,21 @@ $(document).ready(() => { $("form#model_form div.well.well-sm button:submit") ); + // Change conn.extra TextArea widget to CodeMirror + const textArea = document.getElementById("extra"); + const editor = CodeMirror.fromTextArea(textArea, { + mode: { name: "javascript", json: true }, + gutters: ["CodeMirror-lint-markers"], + lineWrapping: true, + lint: true, + }); + + // beautify JSON + const jsonData = editor.getValue(); + const data = JSON.parse(jsonData); + const formattedData = JSON.stringify(data, null, 2); + editor.setValue(formattedData); + /** * Changes the connection type. * @param {string} connType The connection type to change to. @@ -296,6 +311,8 @@ $(document).ready(() => { // payload. if (this.name === "extra") { let extra; + // save the contents of the CodeMirror editor to the textArea + editor.save(); try { extra = JSON.parse(this.value); } catch (e) { @@ -353,19 +370,4 @@ $(document).ready(() => { // Initialize the form by setting a connection type. changeConnType(connTypeElem.value); - - // Change conn.extra TextArea widget to CodeMirror - const textArea = document.getElementById("extra"); - const editor = CodeMirror.fromTextArea(textArea, { - mode: { name: "javascript", json: true }, - gutters: ["CodeMirror-lint-markers"], - lineWrapping: true, - lint: true, - }); - - // beautify JSON - const jsonData = editor.getValue(); - const data = JSON.parse(jsonData); - const formattedData = JSON.stringify(data, null, 2); - editor.setValue(formattedData); }); From 5675ef662aa09c455e427bb946b7f8697aa1c1b3 Mon Sep 17 00:00:00 2001 From: Gene Hynson Date: Fri, 28 Jul 2023 09:27:22 -0700 Subject: [PATCH 2/2] fix: variable name conflict --- airflow/www/static/js/connection_form.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airflow/www/static/js/connection_form.js b/airflow/www/static/js/connection_form.js index d0987f3fc8d52..03043a2abd282 100644 --- a/airflow/www/static/js/connection_form.js +++ b/airflow/www/static/js/connection_form.js @@ -213,8 +213,8 @@ $(document).ready(() => { // beautify JSON const jsonData = editor.getValue(); - const data = JSON.parse(jsonData); - const formattedData = JSON.stringify(data, null, 2); + const parsedData = JSON.parse(jsonData); + const formattedData = JSON.stringify(parsedData, null, 2); editor.setValue(formattedData); /**