scottyaslan commented on code in PR #9068:
URL: https://github.com/apache/nifi/pull/9068#discussion_r1684929940
##########
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:
I refactored this to protect against `codeEditor.codeMirror` being
`undefined`.
##########
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:
I refactored this to protect against `codeEditor.codeMirror` being
`undefined`.
--
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]