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

WIP: Add "insert items" menu item to editor #5071

Merged
merged 16 commits into from
May 24, 2016
Merged

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Apr 28, 2016

Part of #5070

Adds an "insert item" menu bar to the editor toolbar to allow inserting various types of media or embeds into a post, similar to how the insert menus in mainstream applications work.

artboard1

This PR's goal is to add in the empty shell on the editor toolbar which will make it easy to add other modules or embeds.

Testing

  • Load the editor
  • Check for the new dropdown on the top left of the toolbar

Questions

  • There's something pretty strange about the way this code replaces the top HTML in the split button. It's deeply coupled into the DOM structure of what the TinyMCE menu creates. I would appreciate some advice on a better or more idiomatic way to do this.
  • The toolbar button initialization and runtime code is tightly coupled to TinyMCE's API. This is making it hard to abstract the buttons and actions; for example, it's not possible to simply add the existing media plugin into the new dropdown menu. Our options are to refactor the existing TinyMCE plugins or to provide an adapter interface to mock the TinyMCE API and pass through the appropriate calls to the actual TinyMCE. None of this feels like the "right way to do it" so if anyone can offer some wisdom that would help us keep the code clean. As long as the other plugins create a new TinyMCE command, we can use that command in the insert menu without having to rewire anything else.

cc: @dan @aduth @drw158 @rodrigoi

@dmsnell dmsnell added [Feature] Plans & Upgrades All of the plans on WordPress.com and flow for upgrading plans. [Status] In Progress labels Apr 28, 2016
.mce-container.mce-menu .mce-container-body .mce-wpcom-insert-menu__menu-item {
margin-left: -6px;

& svg {
Copy link
Member

Choose a reason for hiding this comment

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

Could we use classes to target these?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, prefixing descendent selector with & is redundant and can be removed safely.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @mtias and @aduth. This is still very much a work-in-progress. I have rearranged the CSS to make better use of classes for specifying the styles, but I'm still pretty troubled by the strange .mce classes.

I'm new to TinyMCE work and had trouble getting enough specificity to overwrite the TinyMCE-provided styles. Any help to clean this up would be much-appreciated!

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it'd be nice to replace the whole toolbar with our components and scope at some point.

@aduth
Copy link
Contributor

aduth commented Apr 28, 2016

We should feature flag this plugin until it's fully implemented.

@dmsnell
Copy link
Member Author

dmsnell commented Apr 28, 2016

We should feature flag this plugin until it's fully implemented.

Will do soon @aduth but not yet. I think this is going to involve some bigger changes and I think that I would prefer for now to get a little further along before thinking of merging. In other words, I want to see how far this reaches before I send out twenty different if ( config.isEnabled( '…' ) ) checks

@dmsnell
Copy link
Member Author

dmsnell commented Apr 28, 2016

@drw158 if you can take a look at this I would appreciate the CSS review. I have diverged from the example in the picture above by turning the color of the menu items blue when hovered instead of changing the background color to blue. This is what the format selector to the immediate right of the control does, so I chose it for consistency.

Styling questions

  • Hover emphasis - should it be background-color or color?
  • CSS mess - is it sane styling?
  • Drop-down chevron - I couldn't get this thing to look right on hover. There's a box that appears over the whole button and it cuts off to the left of the chevron.
  • I left the add media button as a separate button instead of the default. After looking at some apps that we cited in the issue, such as Pages, and getting some good feedback from a friend, I realized that those apps don't have a default click-action on the "insert dropdowns." They always dropdown. This is the behavior I replicated here but am willing to change.

screen shot 2016-04-28 at 11 28 18 am

@dmsnell dmsnell force-pushed the add/editor-insert-plugin branch from 072c3ca to a660563 Compare April 28, 2016 18:50
dmsnell added a commit that referenced this pull request Apr 28, 2016
The "add media" dialog appears after clicking on the "add media" icon in
the TinyMCE toolbar.

Previously, this occurred as a direct result of the `onclick` handler in
`editor.addButton()`. Because this meant that adding media was dependent
on clicking the button, it prevented being able to do so in other ways,
such as is the goal in #5071

This patch moves the code to cause the media dialog to appear into a new
command, which the button then calls when it's clicked.
@davewhitley
Copy link
Contributor

davewhitley commented Apr 28, 2016

What you decided for the hover state is good — just text color. Looks like Calypso dropdowns are standard in that way.

I think the CSS looks good. The selectors are super specific, but that might be a tinyMCE thing.

I added some right padding on the button, and I think it's behaving correctly now.

.mce-toolbar .mce-btn-group .mce-btn.mce-insert-menu button {
    padding-right: 20px;
}

Normally we wouldn't use so many selectors, but I just copied the CSS for the text style dropdown.
screen shot 2016-04-28 at 3 06 30 pm

I also got rid of a & that was not needed.

I left the add media button as a separate button instead of the default.

We might change this behavior later, but we want to combine the Add Media button and this dropdown. Most apps have a single "Add" button that encapsulates everything, so every action takes 2 clicks. But, we want to keep the Add Media selectable with just one click. Similar to something like this:

screen shot 2016-04-28 at 2 23 22 pm

Might be helpful, but I noticed that the text color selection dropdown in the Editor, uses 2 buttons — one for the icon, and another for the dropdown caret.

@dmsnell
Copy link
Member Author

dmsnell commented Apr 28, 2016

We might change this behavior later, but we want to combine the Add Media button and this dropdown. Most apps have a single "Add" button that encapsulates everything, so every action takes 2 clicks.

Thanks @drw158 - I will change it back to the plan. The only reason I diverged was because in practice it felt confusing the way it did one thing if you click on the icon and another thing if you click on the chevron. Some of our justification for doing it this was (based on the behavior of other apps) was actually reported incorrectly in the earlier discussions too.

@dmsnell
Copy link
Member Author

dmsnell commented Apr 28, 2016

Might be helpful, but I noticed that the text color selection dropdown in the Editor, uses 2 buttons — one for the icon, and another for the dropdown caret.

I'll probably leave this as-is for now because of the TinyMCE wrangling. We should be able to supply the appropriate styling to do what we need visually.

@dmsnell
Copy link
Member Author

dmsnell commented Apr 28, 2016

The selectors are super specific, but that might be a tinyMCE thing.

I'm very open for help here and think it's ugly as-is, but I was really struggling to get a higher specificity than the styles from TinyMCE that were overwriting my changes.

@dmsnell
Copy link
Member Author

dmsnell commented Apr 28, 2016

@drw158 I switched back to the split button, and I am sorry to say that I broke your lovely box-padding fix around the chevron. Would you be willing to take another look at it?

@davewhitley
Copy link
Contributor

The only reason I diverged was because in practice it felt confusing the way it did one thing if you click on the icon and another thing if you click on the chevron.

This may prove to be problematic, but should come up in testing. It's possible users won't even notice that you can click on the chevron to get the dropdown menu.

dmsnell added a commit that referenced this pull request Apr 29, 2016
Create TinyMCE command for adding media

The "add media" dialog appears after clicking on the "add media" icon in
the TinyMCE toolbar.

Previously, this occurred as a direct result of the `onclick` handler in
`editor.addButton()`. Because this meant that adding media was dependent
on clicking the button, it prevented being able to do so in other ways,
such as is the goal in #5071

This patch moves the code to cause the media dialog to appear into a new
command, which the button then calls when it's clicked.
@dmsnell dmsnell force-pushed the add/editor-insert-plugin branch from f095f0e to 506668d Compare April 29, 2016 17:16
@davewhitley
Copy link
Contributor

I think the design is in an acceptable state now.

screen shot 2016-04-29 at 3 47 21 pm

I'm not confident in the CSS; there are a lot of classes that I'm unsure about. It works though.

@dmsnell
Copy link
Member Author

dmsnell commented Apr 30, 2016

@drw158 I don't want to rain on your parade, but I noticed that when I hover over the label for one of the items in that dropdown menu, the icon doesn't highlight. The same is true if I hover over the icon, where the label doesn't highlight.

@davewhitley
Copy link
Contributor

Np, I just pushed a fix.

@dmsnell dmsnell added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels May 2, 2016
@davewhitley
Copy link
Contributor

I'm concerned about:

  • If users will know to click the dropdown
  • Users won't know where the contact form went

But, I don't think this small of a change really warrants a Horizon test. Can we deploy on wpcalypso first? We can feedback internally.

@dmsnell dmsnell force-pushed the add/editor-insert-plugin branch from 061e03b to 4243e3a Compare May 2, 2016 22:48
@dmsnell
Copy link
Member Author

dmsnell commented May 2, 2016

@drw158 and @aduth I have hidden this behind a config flag, but the code actually still loads on every request. Personally I don't feel much hesitation to do this since I haven't found any bugs or errors the code produces, but if you think it's worth it we can hide it all. Each step towards preventing it from loading at all in the production environment simply requires more and more if ( config.isEnabled( … ) ) checks and I'm trying to avoid that.

@rralian rralian added this to the Plans: Iteration 2 milestone May 3, 2016
{
name: 'insert_media_item',
icon: 'add-image',
item: <GridiconButton icon="image-multiple" label={ 'Add Media' } />,
Copy link
Contributor

Choose a reason for hiding this comment

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

These labels should be translated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @aduth - translations added in d5419ce

Note that we need a string review of Insert content because it's currently untranslated. We should review the wording before merging and having people translate that particular message.

@davewhitley
Copy link
Contributor

Did the large icon get fixed?

@aduth
Copy link
Contributor

aduth commented May 20, 2016

Did the large icon get fixed?

I don't see any changes that would indicate that it has been, but I haven't spun up the branch to verify.

@dmsnell
Copy link
Member Author

dmsnell commented May 20, 2016

Did the large icon get fixed?

haha, whoops I didn't test it and had assumed you got it @drw158

dmsnell and others added 15 commits May 24, 2016 14:40
Adds a basic shell for a new split button in TinyMCE, meant to be
pluggable to display a variety of menu options to insert embeds/widgets.
This patch changes the behavior of the insert menu dropdown, whereas
previously we had a separate add media button and then the insert
button, which always opened the drop-down. Now, we have a single button
that will add media on a direct click and only open the drop-down when
the chevron is clicked.
Changing color of caret on hover
@dmsnell dmsnell force-pushed the add/editor-insert-plugin branch from c1ec490 to adaa14b Compare May 24, 2016 18:40
@dmsnell
Copy link
Member Author

dmsnell commented May 24, 2016

The icon size should be fixed thanks to @drw158's suggestions.

Before
screen shot 2016-05-24 at 3 30 30 pm
screen shot 2016-05-24 at 3 30 37 pm

After
screen shot 2016-05-24 at 3 27 35 pm
screen shot 2016-05-24 at 3 27 41 pm

Tested in IE11 and verified in Chrome that it didn't mess up.

@davewhitley davewhitley added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 24, 2016
@dmsnell dmsnell merged commit 65c22ab into master May 24, 2016
@dmsnell dmsnell deleted the add/editor-insert-plugin branch May 24, 2016 19:59
@dmsnell dmsnell restored the add/editor-insert-plugin branch May 24, 2016 20:49
dmsnell added a commit that referenced this pull request May 25, 2016
Fix of #5071 - was missing a config flag check

Adds an "insert item" menu bar to the editor toolbar to allow inserting various types of media or embeds into a post, similar to how the insert menus in other mainstream applications (such as Pages, Sketch, etc…) work.

This patch removes the contact form button and the media button and combines those into the new insert menu. The insert menu button has two behaviors: a default click on the button inserts a media item; a click on the chevron opens the drop-down menu to select one of many possible items to insert.

Props to all who helped review and edit and design this feature:
@aduth @drw158 @folletto @mtias @rralian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Plans & Upgrades All of the plans on WordPress.com and flow for upgrading plans.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants