Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

t/344: Refactoring of the dropdown ecosystem #361

Merged
merged 79 commits into from
Feb 8, 2018
Merged

t/344: Refactoring of the dropdown ecosystem #361

merged 79 commits into from
Feb 8, 2018

Conversation

jodator
Copy link
Contributor

@jodator jodator commented Jan 24, 2018

Suggested merge commit message (convention)

Enhancement: Introduce SplitButtonView and new dropdowns helper methods. Closes ckeditor/ckeditor5#5434. Closes ckeditor/ckeditor5#5441.

BREAKING CHANGE: Removed DropdownModel interface - use dropdown properties directly. See ckeditor/ckeditor5#5441.
BREAKING CHANGE: Removed createButtonDropdown() and ButtonDropdownView. See ckeditor/ckeditor5#5441.
BREAKING CHANGE: Removed createListDropdown() and ListDropdownView. See ckeditor/ckeditor5#5441.

Changes in other repositories:

Merge commit message for related branches:

Internal: Aligned code to the changes in the dropdowns API (see ckeditor/ckeditor5#5441).

Additional information

So this is initial PR with SplitButton (ckeditor/ckeditor5#5434) and Dropdowns cleanup (ckeditor/ckeditor5#5441) - mostly to open some discussion on how to close ckeditor/ckeditor5#5441 as there are some things to consider here.

To quickly see how dropdowns are created now checkout Framework Guide Stub with two examples. This file is created mostly for PR but might be expanded if needed for guides.

To see how new dropdowns are used in features checkout:

Or checkout: ckeditor5#t/ckeditor5-highlight/3 branch with proper mgit.json configuration (Sorry for branches names :trollface: but that issue evolved a bit).

As suggested I've tried to create minimal set of methods. What I like here is that button appearance is controlled by model.


Some things that might be improved

  1. method naming (as always) and maybe location inside ui package
  2. All features adds own CSS class - maybe make this configurable by model / helper?
// example:
dropdownView.extendTemplate( {
	attributes: {
		class: 'ck-splitbutton-dropdown'
	}
} );
  1. All features adds execute command & focus editing view afterward - helper?
// Execute current action from dropdown's split button action button.
dropdownView.on( 'execute', () => {
	// This line is similar but need command name and param:
	editor.execute( 'command', { value: model.commandValue } );
	// This line is duplicated always:
	editor.editing.view.focus();
} );
  1. I had method addDefaultBehavior() which called three methods but I've removed to meke less methods. Below code is duplicated everywhere:
// Add default behavior of dropdown
closeDropdownOnBlur( dropdownView );
closeDropdownOnExecute( dropdownView );
focusDropdownContentsOnArrows( dropdownView );
  1. Whether to pass toolbar/listview contents by model or by method param (I'm for the latter)
  2. Toolbar - ListView dropdowns inconsistency in adding view property
// for toolbar:
dropdownView.toolbarVIew;
// for listview:
dropdownView.listView;
// maybe just:
dropdownView.contentView; // ??

Things that require fixes:

  • The SplitButton's CSS & button inside dropdown must be fixed (awaiting theme refactor as @oleq worked on that arrow thingy).
  • "execute" event is not delegated properly for SplitButton (to check at least) - see guide both "execute" are on different elements.
  • docs :D

@jodator jodator requested review from Reinmar and oleq January 24, 2018 18:22
@jodator
Copy link
Contributor Author

jodator commented Jan 29, 2018

OK I've updated the PR with the following changes:

  • instead of creating button and then dropdown there are now two functions that creates empty dropdown with given button
    • createDropdown() (maybe needs name change?)
    • createSplitButtonDropdown()
  • there are no default behavior methods adding default behavior is done by above methods
  • the addListViewToDropdown() and addToolbarToDropdown() now accepts dropdown and items or buttons respectively
  • there is no model needed - all bindings are now on dropdownView directly (maybe should go on dropdownView.button 🤔
  • I've created bindOneToMany() binding

Most changes are visible on fremework guide: fee7755...t/344#diff-1cd2b60b887d6d0735a58a4331b24806

Updated usage in features:

@Reinmar
Copy link
Member

Reinmar commented Feb 1, 2018

Some notes from the call:

@coveralls
Copy link

coveralls commented Feb 2, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 7c0e6c9 on t/344 into 7973f83 on master.

@Reinmar
Copy link
Member

Reinmar commented Feb 5, 2018

Do we need to have all these label, withText, etc properties on DropdownView? I assume that the button is accessible through DropdownView#button so one can set them directly there?

Although, when I look at the bindings in createDropdown() it may turn out that it won't be that easy. Anyway, curious to see the result, but I'm not sure yet whether this is the right direction.

@jodator
Copy link
Contributor Author

jodator commented Feb 6, 2018

@Reinmar & @oleq I've udpated this PR with changes:

  • no binding from dropdown (use dropdown.buttonView instaed to control button)
  • introduced new interfaces for buttons
  • removed createSplitButtonDropdown() method -> the createDropdown() method now accepts a ButtonClass parameter
  • updated the docs ;)

*
* document.body.append( view.element );
*
* @extends module:ui/view~View
Copy link
Member

Choose a reason for hiding this comment

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

What is this? ;) Is it an interface, is it a class or is it a plain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a copy-paste artifact.

/**
* The button interface.
*
* @interface module:ui/button/buttoninterface~ButtonInterface
Copy link
Member

Choose a reason for hiding this comment

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

I don't like using the word Interface in names of interfaces but sometimes it's just super hard to find a way around this. There's already Plugin and PluginInterface because I wasn't able to name both without using the Interface suffix.

*/

/**
* Fired when the arrow view is clicked. It won't be fired when the button {@link #isEnabled} is `false`.
Copy link
Member

@Reinmar Reinmar Feb 6, 2018

Choose a reason for hiding this comment

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

Doesn't this describe the split button?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - it should be "fired when the button is clicked".


buttonView.bind( 'isEnabled' ).to( dropdownView );

if ( buttonView instanceof DropdownButtonView ) {
Copy link
Member

Choose a reason for hiding this comment

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

This is ugly. Why is the createDropdown() function responsible for that? What if I'd create another button view which implements the same interface as the dropdown button but is not an instance of DropdownButtonView?

Copy link
Member

Choose a reason for hiding this comment

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

We should delegate this logic out of here.

render() {
super.render();

this.children.add( this.actionView );
Copy link
Member

Choose a reason for hiding this comment

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

@oleq oleq changed the title T/344 t/344: Refactoring of the dropdown ecosystem Feb 7, 2018
@Reinmar
Copy link
Member

Reinmar commented Feb 8, 2018

OK, we're not going to use the word Interface by just stripping it. So there will be the Button interface and the ButtonView class. It's not great, but the actual correct naming would be ButtonViewInterface which is catastrophically long. E.g. we'd have module:ui/dropdown/button/dropdownbuttonviewinterface~DropdownButtonViewInterface. Let's go the other way around. These are only interface names so we can always change them later if we wish.

@Reinmar Reinmar merged commit 0f26ca8 into master Feb 8, 2018
@Reinmar Reinmar deleted the t/344 branch February 8, 2018 14:23
Reinmar added a commit to ckeditor/ckeditor5-alignment that referenced this pull request Feb 8, 2018
Internal: Aligned dropdowns usage to changed in the UI. See ckeditor/ckeditor5-ui#361.
Reinmar added a commit to ckeditor/ckeditor5-heading that referenced this pull request Feb 8, 2018
Internal: Aligned dropdowns usage to changed in the UI. See ckeditor/ckeditor5-ui#361.
Reinmar added a commit to ckeditor/ckeditor5-theme-lark that referenced this pull request Feb 8, 2018
Internal: Aligned dropdowns usage to changed in the UI. See ckeditor/ckeditor5-ui#361.
@Reinmar
Copy link
Member

Reinmar commented Feb 8, 2018

OK, I closed this PR and branches in the utils, alignment, theme-lark and heading repos. I leave the rest to you, @jodator.

Also, I reported ckeditor/ckeditor5#831 and plan to report issue about the if () in the createDropdown() function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dropdown family (possibly) needs architecture refactoring Implement Split Button dropdown
3 participants