Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Script Editor language-specific subclasses #2388

Merged
merged 7 commits into from
Jan 21, 2022

Conversation

karlaspuldaro
Copy link
Member

@karlaspuldaro karlaspuldaro commented Jan 12, 2022

Fixes #1517
This PR introduces new PythonEditor and REditor sublasses, making the ScriptEditor class language agnostic.
The existing functionality is maintained.

How was this pull request tested?

Ran existing Script Editor integration tests.

Developer's Certificate of Origin 1.1

   By making a contribution to this project, I certify that:

   (a) The contribution was created in whole or in part by me and I
       have the right to submit it under the Apache License 2.0; or

   (b) The contribution is based upon previous work that, to the best
       of my knowledge, is covered under an appropriate open source
       license and I have the right under that license to submit that
       work with modifications, whether created in whole or in part
       by me, under the same open source license (unless I am
       permitted to submit under a different license), as indicated
       in the file; or

   (c) The contribution was provided directly to me by some other
       person who certified (a), (b) or (c) and I have not modified
       it.

   (d) I understand and agree that this project and the contribution
       are public and that a record of the contribution (including all
       personal information I submit with it, including my sign-off) is
       maintained indefinitely and may be redistributed consistent with
       this project or the open source license(s) involved.

@elyra-bot
Copy link

elyra-bot bot commented Jan 12, 2022

Thanks for making a pull request to Elyra!

To try out this branch on binder, follow this link: Binder

@lresende lresende modified the milestones: 3.5.0, 3.6.0 Jan 13, 2022
Comment on lines 36 to 42
this.editorLanguage = 'python';

// Add icon to main tab
this.title.icon = pyIcon;

this.context.ready.then(() => {
this.initializeKernelSpecs();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect both constructors (PythonEditor and REditor) could be removed simply by treating ScriptEditor as an abstract base class that defines two abstract methods: getLanguage() and getIcon() that PythonEditor and REditor implement. Then, wherever there's this.editorLanguage in ScriptEditor, it is replaced with this.getLanguage() and same goes for this.title.icon -> this.getIcon(). The intialize Kernelspecs just moves to the ScriptEditor constructor as well.

You probably don't need the fields this.editorLanguage or this.title.icon, although, if they're a hassle to remove, the ScriptEditor constructor could just be like this...

    this.editorLanguage = this.getLanguage();

    // Add icon to main tab
    this.title.icon = this.getIcon();

    this.context.ready.then(() => {
      this.initializeKernelSpecs();

Since the subclasses know what they are, the fields could probably be made private.

I also suspect the factory stuff could be simplified just based on java/python experiences. Typically, the factory for something like this would be a class method on ScriptEditor like ScriptEditor.createInstance() where createInstance() takes an "identifying characteristic" corresponding to the class to create. Language would probably be a good "id".

Take this with a grain of salt since I don't know how much applies in the JS world.

Copy link
Member

@lresende lresende left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above about rIcon

@@ -80,7 +72,8 @@ export class ScriptEditor extends DocumentWidget<
private runDisabled: boolean;
private kernelSelectorRef: RefObject<ISelect> | null;
private controller: ScriptEditorController;
private editorLanguage: string;
abstract getLanguage(): string;
abstract getIcon(): LabIcon | string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we passing labIcon or string? we do have an rIcon defined in ui-components and thus I was expecting to use that in favor of consistency.

Copy link
Member Author

@karlaspuldaro karlaspuldaro Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe our rIcon is created differently, that's why we define it with a string, I didn't change the original way we refer to it.
When I import it from ui-components library the same way we add python icons, the r icon isn't loaded properly in the launcher, file browser or editor tab:
image

@ajbozarth might be able to elaborate on why/how that works?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why this fix works, but there's an issue with LabIcons where depending on the DOM within a svg added multiple copies of it causes problems. The R icon is the icon we found that has this issue.

@ptitzler ptitzler modified the milestones: 3.6.0, 3.5.0 Jan 20, 2022
@akchinSTC akchinSTC requested a review from lresende January 21, 2022 16:32
Copy link
Member

@ajbozarth ajbozarth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple clarification questions for @karlaspuldaro otherwise LGTM

@@ -80,7 +72,8 @@ export class ScriptEditor extends DocumentWidget<
private runDisabled: boolean;
private kernelSelectorRef: RefObject<ISelect> | null;
private controller: ScriptEditorController;
private editorLanguage: string;
abstract getLanguage(): string;
abstract getIcon(): LabIcon | string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why this fix works, but there's an issue with LabIcons where depending on the DOM within a svg added multiple copies of it causes problems. The R icon is the icon we found that has this issue.

/**
* A widget factory for script editors.
*/
export class ScriptEditorWidgetFactory extends ABCWidgetFactory<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two comments on this (both non-blocking):

  1. Why the name change from ScriptEditorFactory to ScriptEditorWidgetFactory?

  2. Why move this into a separate file?

Copy link
Member Author

@karlaspuldaro karlaspuldaro Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The name has changed to make it more clear that it is a widget factory class.
  2. It has moved to its own file because the editor is independent of its factory (imo this should have been done before). Makes it easier to maintain (the ScriptEditor class will become more complex with the debugger), follows common conventions and doesn't expose to ScriptEditor things it doesn't need to know about from certain libraries.

@akchinSTC akchinSTC merged commit 6fca891 into elyra-ai:master Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create language-specific subclasses of ScriptEditor
6 participants