jens-scheffler-bosch commented on code in PR #27063:
URL: https://github.com/apache/airflow/pull/27063#discussion_r1088323671
##########
airflow/www/static/js/trigger.js:
##########
@@ -19,33 +19,190 @@
/* global document, CodeMirror, window */
-const textArea = document.getElementById('json');
+let jsonForm;
+const objectFields = new Map();
const recentConfigList = document.getElementById('recent_configs');
-const minHeight = 300;
-const maxHeight = window.innerHeight - 450;
-const height = maxHeight > minHeight ? maxHeight : minHeight;
-
-CodeMirror.fromTextArea(textArea, {
- lineNumbers: true,
- mode: {
- name: 'javascript',
- json: true,
- },
- gutters: ['CodeMirror-lint-markers'],
- lint: true,
-})
- .setSize(null, height);
+
+/**
+ * Update the generated JSON DagRun.conf JSON field if any field changed
+ */
+function updateJSONconf() {
+ const jsonStart = document.getElementById('json_start').value;
+ const params = JSON.parse(jsonStart);
+ const elements = document.getElementById('trigger_form');
+ for (let i = 0; i < elements.length; i += 1) {
+ if (elements[i].name && elements[i].name.startsWith('element_')) {
+ const keyName = elements[i].name.substr(8);
+ if (elements[i].type === 'checkbox') {
+ params[keyName] = elements[i].checked;
+ } else if (elements[i].attributes.valuetype &&
elements[i].attributes.valuetype.value === 'array') {
+ const lines = elements[i].value.split('\n');
+ const values = [];
+ for (let j = 0; j < lines.length; j += 1) {
+ if (lines[j].trim().length > 0) {
+ values[values.length] = lines[j].trim();
+ }
+ }
+ params[keyName] = values;
+ } else if (elements[i].value.length === 0) {
+ params[keyName] = null;
+ } else if (elements[i].attributes.valuetype &&
elements[i].attributes.valuetype.value === 'object') {
+ try {
+ const textValue = objectFields.get(elements[i].name).getValue();
+ if (textValue.length > 0) {
+ const objValue = JSON.parse(textValue);
+ params[keyName] = objValue;
+
objectFields.get(elements[i].name).setValue(JSON.stringify(objValue, null, 4));
+ } else {
+ params[keyName] = null;
+ }
+ } catch (e) {
+ // ignore JSON parsing errors
Review Comment:
JSON is validated before form submission, I removed any alerting here not to
bother user during entry. Added a comment so that future reader knows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]