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


##########
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);
+        }
+
+        this.clearMessages();
+    }
+
+    private toggleDisplayEditorErrors(editor: EditorFromTextArea | undefined, 
hideErrors: boolean = false) {
+        if (editor) {
+            const display: HTMLElement | undefined = 
editor?.getWrapperElement();

Review Comment:
   Optional chaining isn't needed here because we've verified `editor` is not 
`null` or `undefined` above.



##########
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);
+        }
+
+        this.clearMessages();
+    }
+
+    private toggleDisplayEditorErrors(editor: EditorFromTextArea | undefined, 
hideErrors: boolean = false) {
+        if (editor) {
+            const display: HTMLElement | undefined = 
editor?.getWrapperElement();
+            const errors: Element[] = 
Array.from(display?.getElementsByClassName('CodeMirror-lint-marker-error'));

Review Comment:
   Should we protect against `display` from being `undefined` here? The 
optional chaining below may yield unexpected results if it is `undefined`. 



##########
nifi-frontend/src/main/frontend/package.json:
##########
@@ -66,6 +67,7 @@
         "@types/d3": "^7.4.3",
         "@types/humanize-duration": "^3.27.3",
         "@types/jest": "^29.5.12",
+        "@types/jsonlint": "^1.6.3",

Review Comment:
   This introduces `audit` issues. Can we force resolve so address them?



##########
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:
   `display` may be `undefined`. Should we protect against it here?



##########
nifi-frontend/src/main/frontend/apps/nifi-jolt-transform-ui/src/app/pages/jolt-transform-json-ui/state/jolt-transform-json-ui/jolt-transform-json-ui.reducer.ts:
##########
@@ -41,7 +41,13 @@ export const initialState: JoltTransformJsonUiState = {
     processorDetails: null,
     transformingJoltSpec: false,
     validatingJoltSpec: false,
-    savingProperties: false
+    savingProperties: false,
+    savePropertiesResponse: null,
+    savePropertiesFailureResponse: null,
+    validationResponse: null,
+    validationFailureResponse: null,
+    transformationResponse: null,
+    transformationFailureResponse: null

Review Comment:
   Can we decouple these into different states? Maybe a `PropertiesState`, 
`ValidationState`, and `TransformationState` which can each have their own 
`saving` flag, `timestamp`, `status`, `error`, etc rather than having to prefix 
everything here.



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