scottyaslan commented on code in PR #9068:
URL: https://github.com/apache/nifi/pull/9068#discussion_r1683534274


##########
nifi-frontend/src/main/frontend/apps/nifi-jolt-transform-ui/src/app/pages/jolt-transform-json-ui/feature/jolt-transform-json-ui.component.ts:
##########
@@ -326,4 +320,92 @@ export class JoltTransformJsonUi implements OnDestroy {
         }
         return result;
     }
+
+    initSpecEditor(codeEditor: CodemirrorComponent): void {
+        this.specEditor = codeEditor.codeMirror;
+
+        this.specEditor?.on('change', (cm: Editor, changeObj: EditorChange) => 
{
+            const transform = 
this.editJoltTransformJSONProcessorForm.get('transform')?.value;
+
+            if (!(transform == 'jolt-transform-sort' && 
changeObj.text.toString() == '')) {
+                this.clearMessages();
+            }
+        });
+
+        // listen to value changes
+        
this.editJoltTransformJSONProcessorForm.controls['specification'].valueChanges.subscribe(()
 => {
+            this.toggleSpecEditorEnabled();
+        });
+
+        
this.editJoltTransformJSONProcessorForm.controls['transform'].valueChanges.subscribe(()
 => {
+            this.toggleSpecEditorEnabled();
+        });
+    }
+
+    initInputEditor(codeEditor: any): void {
+        codeEditor.codeMirror.on('change', () => {
+            this.clearMessages();
+        });
+
+        
this.editJoltTransformJSONProcessorForm.controls['input'].valueChanges.subscribe(()
 => {
+            codeEditor.codeMirror.setOption('lint', true);
+        });
+    }
+
+    private clearMessages() {
+        this.store.dispatch(resetValidateJoltSpecState());
+    }
+
+    private toggleSpecEditorEnabled() {
+        const transform = 
this.editJoltTransformJSONProcessorForm.get('transform')?.value;
+        const display: HTMLElement | undefined = 
this.specEditor?.getWrapperElement();
+
+        if (transform == 'jolt-transform-sort') {
+            this.specEditor?.setOption('readOnly', 'nocursor');
+            this.renderer.addClass(display, 'disabled');
+            this.toggleDisplayEditorErrors(this.specEditor, true);
+        } else {
+            this.specEditor?.setOption('readOnly', false);
+            this.renderer.removeClass(display, 'disabled');
+            this.toggleDisplayEditorErrors(this.specEditor);
+        }

Review Comment:
   We can add the check for is not null or undefined here if you like but 
`display` will never be `undefined` since `this.toggleSpecEditorEnabled()` is 
only called after the `this.specEditor` has been initialized in the 
ngx-codemirror codeMirrorLoaded function. 



-- 
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]

Reply via email to