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

FIX: Empty Links shows on frontend #2302

Merged
merged 9 commits into from
Aug 15, 2017
Merged

Conversation

tg-ephox
Copy link
Contributor

@tg-ephox tg-ephox commented Aug 9, 2017

Fixes #2080

Changed the Toolbar to only create a link when the URL has been entered, instead of creating the link up front and then setting the URL.

I needed to lift the state for the link functionality from FormatToolbar to Editable as this needs to be reset from onNodeChange. This allowed FormatToolbar to be simplified a lot as we don't have to guess what has happened in componentWillReceiveProps.

A remaining issue is that when typing into UrlInput, the cursor position is reset to the end if typing in the middle. This is caused by the updateSuggestions function which does an api call and sets the state causing a re-render. I believe that moving this to a separate component will fix the issue. (Using the separate component's render cycle instead of re-rendering the input which is confusing react as to where the cursor should be)

Fixes #1069 (I put this in the same PR as its right in the same area)

Added CSS class and custom selector to TinyMCE so when the Toolbar is used, it doesn't loose focus. Also before applying formatting, focus the TinyMCE instance. This meant that the bookmark was no longer needed in state.

@codecov
Copy link

codecov bot commented Aug 9, 2017

Codecov Report

Merging #2302 into master will increase coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2302      +/-   ##
=========================================
+ Coverage    25.9%   25.9%   +<.01%     
=========================================
  Files         157     157              
  Lines        4849    4848       -1     
  Branches      820     817       -3     
=========================================
  Hits         1256    1256              
- Misses       3033    3035       +2     
+ Partials      560     557       -3
Impacted Files Coverage Δ
blocks/editable/format-toolbar/index.js 7.5% <0%> (+0.52%) ⬆️
blocks/editable/index.js 10.87% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 961e987...620892a. Read the comment docs.

@tg-ephox tg-ephox requested a review from aduth August 9, 2017 23:36
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

This works great, but I think we should still keep the local state in the FormatToolbar. A state that is not used in a component but just passed as a prop to the child component should leave in the child component, don't you think?

linkValue: props.formats.link ? props.formats.link.value : '',
isEditingLink: false,
};
super( props );
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we should always prefer super( ...arguments ) to avoid errors when we use the context feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problems, i will revert this.

isAddingLink: false,
isEditingLink: false,
newLinkValue: '',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we keep this state in the formatToolbar instead. Seems more related to the link modal than the Editable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These all need to be reset in onNodeChange which FormatTooblar has no knowledge of. This also removes the need for trying to reconcile state in componentWillReceiveProps and the setTimeout hack that was in addLink. I can't think of a cleaner way to do this but happy to take suggestions!

Copy link
Contributor

Choose a reason for hiding this comment

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

I have a preference over componentWillReceiveProps. It's a better Separation of Concerns IMO but I can live with it. Thoughts @aduth?

Copy link
Member

Choose a reason for hiding this comment

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

First reaction before digging in: I don't see it as a win to drop some lines and logic from FormatToolbar if it means we add more code and responsibilities to the already-bloated Editable.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not super familiar with this code, but it seems like we're trying to force this component to be treated as a controlled component, maintaining the value as it's changed? This seems like a good use case for an uncontrolled component, meaning the link toolbar starts with an empty initial value when first shown, and only at the point that we decide we want to confirm a link being added do we trigger the onAddLink callback.

@aduth
Copy link
Member

aduth commented Aug 11, 2017

Added CSS class and custom selector to TinyMCE so when the Toolbar is used, it doesn't loose focus.

Can you explain why this is necessary? I'm a bit reluctant about this change for a few reasons:

  • The Editable becomes aware of and dependent upon the existence of the Editor wrapper assigning this class
  • So far as distinct Editables, and blocks not leveraging Editable, it would seem to me that we would want blur to occur when leaving any individual Editable

@tg-ephox
Copy link
Contributor Author

tg-ephox commented Aug 14, 2017

@aduth @youknowriad I removed the CSS class and selector, I was recommended to try this in order that the editor keeps its selection but it seems that focussing the editor before applying/removing formatting fixes this anyway. Have also moved the FormatToolbar state back and added a selectedNodeId so that FormatToolbar can track node changes.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

It looks like this is working great. 👍

When I worked on the UrlInput the first time, I had to do add this convert_urls: false, to the TinyMCE settings to avoid JS errors when using empty URLs. Maybe we can remove this option now?

@tg-ephox
Copy link
Contributor Author

@youknowriad I tried removing the convert_urls setting from TinyMCE and didn't see any difference... Although UrlInput forces a complete URL to be entered anyway so this option might not be relevant, but I have left it there for now.

@tg-ephox tg-ephox merged commit c29caae into master Aug 15, 2017
@tg-ephox tg-ephox deleted the fix/2080-empty-link-shows branch August 15, 2017 00:49
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.

Empty Links shows on frontend Firefox: Adding Link displays error in Console
3 participants