-
Notifications
You must be signed in to change notification settings - Fork 344
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
Add Script Editor language-specific subclasses #2388
Conversation
Thanks for making a pull request to Elyra! To try out this branch on binder, follow this link: |
this.editorLanguage = 'python'; | ||
|
||
// Add icon to main tab | ||
this.title.icon = pyIcon; | ||
|
||
this.context.ready.then(() => { | ||
this.initializeKernelSpecs(); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
@ajbozarth might be able to elaborate on why/how that works?
There was a problem hiding this comment.
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.
There was a problem hiding this 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; |
There was a problem hiding this comment.
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< |
There was a problem hiding this comment.
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):
-
Why the name change from
ScriptEditorFactory
toScriptEditorWidgetFactory
? -
Why move this into a separate file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The name has changed to make it more clear that it is a widget factory class.
- 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 toScriptEditor
things it doesn't need to know about from certain libraries.
Fixes #1517
This PR introduces new
PythonEditor
andREditor
sublasses, making theScriptEditor
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