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 isSupportedEnvironment virtual member #2693

Merged
merged 39 commits into from
Jun 17, 2019
Merged

Add isSupportedEnvironment virtual member #2693

merged 39 commits into from
Jun 17, 2019

Conversation

jacekbogdanski
Copy link
Member

What is the purpose of this pull request?

Task

Closes #2692

@jacekbogdanski jacekbogdanski changed the base branch from major to master December 19, 2018 13:49
@Comandeer Comandeer self-assigned this Dec 21, 2018
@Comandeer Comandeer self-requested a review December 21, 2018 16:06
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

In fact this method should probably be bound to the plugin's namespace, not instance, as it's done in tableselection plugin.


If we add such method, lets refactor plugins at once. There are several plugins, that can use isSupportedEnvironment function:

  • tableselection (for now there is property, not method)
  • easyimage
  • balloontoolbar
  • copyformatting
  • uploadwidget
  • etc.

@@ -175,3 +175,28 @@
* @since 4.2
* @property {Boolean} hidpi
*/

/**
* A virtual function which should be implemented if a plugin is not supported on every
Copy link
Member

Choose a reason for hiding this comment

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

It's not virtual, it's very real 😛

Copy link
Member Author

@jacekbogdanski jacekbogdanski Feb 14, 2019

Choose a reason for hiding this comment

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

https://en.wikipedia.org/wiki/Virtual_function

However, taking into account that this function is not implemented by default, abstract may better define its purpose.

Actually, I see that the whole pluginDefinition is marked as virtual, so I will just skip modifier to not repeat it needlessly.

* } );
* ```
*
* @since 4.11.2
Copy link
Member

Choose a reason for hiding this comment

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

Probably it would be better to introduce such change in next major release, 4.12.0, not in 4.11.2.

@engineering-this
Copy link
Contributor

It would be nice to refactor all the plugins which has limited environment support. We need to ignore tests once isSupportedEnvironment property/method is accessible, hence it should be in listener to pluginsLoaded. I'd make sense to put such logic in one general helper which would be accessible by any test.
This proposal comes from #2694 (comment)

@jacekbogdanski
Copy link
Member Author

I'm not sure if this member should be attached into plugin namespace. In that case, we are unable to unify this function among the plugins. AFAIK we don't have any recommendation nor abstract interface how to write a plugin namespace, so we will be unable to define it in our docs easily, which can be done with pluginDefinition. I see that it will require some refactoring like for tableselection plugin but it still has to be done for other plugins like easyimage which uses isUnsupportedEnvironment in tests (this member has to be moved into the plugin itself).

Also, if I have a simple plugin like autolink, I will have to create special, separate plugin namespace to keep isSupportedEnvironment member. Writing something like:

CKEDITOR.plugins.autolink = { 
   isSupportedEnvironment: fn 
};

CKEDITOR.plugins.add( autolink, {
   init: function() { // init stuff }
 } );

seems less coder friendly for me than just:

CKEDITOR.plugins.add( autolink, {
   init: function() { // init stuff },
   isSupportedEnvironment: fn
 } );

Currently, our options are:

  1. Define virtual method as a member of pluginDefinition
  2. Put this function into the plugin namespace (not sure how to document such a requirement).
  3. ?

@engineering-this
Copy link
Contributor

I'd go with first option.

I have one suggestion. If this method is optional, then maybe it should have default value function(){ return true; }. Thanks to this we could update bender so it ignores every test for unsupported env based on bender-ckeditor-plugins declared in test file. We wouldn't have to ever write

if ( plugin.isSupportedEnvironment ) {
    bender.ignore(); // or assert.ignore();
 }

@jacekbogdanski
Copy link
Member Author

jacekbogdanski commented Mar 5, 2019

I was also thinking about it. It also fixes the issue when you have to manually check if isSupportedEnvironment is declared, like:

if ( plugin.isSupportedEnvironment && plugin.isSupportedEnvironment()) {
// do stuff
}

@jacekbogdanski jacekbogdanski self-assigned this Mar 5, 2019
@f1ames
Copy link
Contributor

f1ames commented Mar 7, 2019

I'm late to the party, but agree with @engineering-this on adding virtual method to pluginDefinition. And integrating it with bender would be nice 🤩

@jacekbogdanski
Copy link
Member Author

jacekbogdanski commented Apr 9, 2019

It seems like it makes sense to pass an optional editor instance as an argument. It will complicate refactoring a bit, although some plugins require information about editor state. As an example, docprops plugin only works for a classic editor with config.fullPage = true.

// Example for docprops
pluginDef.isSupportedEnvironment = function( editor ) {
    return !editor.editable().isInline() && editor.config.fullPage;
}

We could even extend this feature to automatically detect unsupported plugins and prevent executing initialization methods.

@jacekbogdanski
Copy link
Member Author

I refactored tableselection, easyimage and balloontoolbar plugins + tests. There is much more work to do thus this PR will require reviewing all our plugins in the context of a supported environment. I would like to take it slowly because if the current implementation will be rejected, we will spend a lot of time refactoring again.

Please, take a look if you are fine with the current changes and if so, I will continue refactoring/implementing support sniffing methods.

@f1ames
Copy link
Contributor

f1ames commented May 23, 2019

Taking over review of this PR.

@f1ames
Copy link
Contributor

f1ames commented May 23, 2019

Rebased on the latest major.

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Looking good 👍

I have one suggestion/idea. What if bender.tools.ignoreUnsupportedEnvironment() method could be called automatically by bender without a need to add it in every test suite? You could just create a plugin with proper isSupportedEnvironment() function and create tests without really thinking about correct ignoreUnsupportedEnvironment() calls (tests may also have other plugins which can have env restriction and then one would have to check them, or just add all used plugins to ignoreUnsupportedEnvironment() call).

From what I see the proper place to add such automatic call could be bender extensions where under tests var you have current test suit (and can modify setUp calls) and under bender.plugins a list of plugins loaded for this test suite. WDYT? (Btw. This code is rn only for unit tests, so manual ones will need different place to hook in).

core/editor.js Outdated
// Plugin is supported by default (#2692).
plugin.isSupportedEnvironment = plugin.isSupportedEnvironment || function() {
return true;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there any particular reason why this code was added here and not in plugin.js, somewhere near: https://github.com/ckeditor/ckeditor-dev/blob/680bdd9f66dfa21e0822a1154573ddda743a1a75/core/plugins.js#L71 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

onLoad method may not be provided, but yeah it makes more sense to attach default method implementation inside core/plugins.js file.

Copy link
Contributor

Choose a reason for hiding this comment

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

onLoad method may not be provided.

Yes, I meant the line above. It shouldn't depend on presence of onLoad.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like the safest place is https://github.com/ckeditor/ckeditor-dev/blob/14e3bab99f1d4b968dd44e9b4e5b408e97b26758/core/plugins.js#L37 because it makes sure that the function won't be attached multiple times.

core/plugindefinition.js Outdated Show resolved Hide resolved
core/plugindefinition.js Outdated Show resolved Hide resolved
core/plugindefinition.js Outdated Show resolved Hide resolved
plugins/balloontoolbar/plugin.js Show resolved Hide resolved
tests/_benderjs/ckeditor/static/tools.js Show resolved Hide resolved
@jacekbogdanski
Copy link
Member Author

jacekbogdanski commented May 27, 2019

As we already talked F2F, there are some popular use cases where we cannot simply automate ignoring tests, like:

  • using multiple declared editors by bender.editors
  • declared editors may use a different set of plugins than information in bender-ckeditor-plugins tag

I updated an additional list of plugins. Please, tell if you still see some plugins requiring covering.

@f1ames f1ames dismissed Comandeer’s stale review June 17, 2019 12:40

Taken over PR review.

@f1ames f1ames merged commit 27f156c into major Jun 17, 2019
@CKEditorBot CKEditorBot deleted the t/2692 branch June 17, 2019 12:42
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.

Update plugin definition with isEnvironmentSupported optional member
4 participants