Skip to content

Chore - extract link container from rich text#10495

Merged
talldan merged 17 commits intomasterfrom
chore/extract-link-container-from-rich-text
Oct 12, 2018
Merged

Chore - extract link container from rich text#10495
talldan merged 17 commits intomasterfrom
chore/extract-link-container-from-rich-text

Conversation

@talldan
Copy link
Copy Markdown
Contributor

@talldan talldan commented Oct 11, 2018

Description

Extracts the presentational aspects of the RichText's LinkContainer component into a new presentational URLPopover component.

The goal is to use this component to render the url editor for inserting media from a url in the MediaPlaceholder. That can be seen on this comment - #9264 (comment). Currently that PR completely reimplements the LinkContainer, and it'd be good to avoid that duplication.

The new component doesn't implement much link editing functionality, it's mostly just a way to reuse the visual side of the popover. Why? The RichText integration was previously tightly coupled to this component, and extracting it in a generic way is something that I don't think is possible.

Also, the URLInput component used in the previous implementation has always-on autocompletion for posts/pages, so is not usable for the MediaPlaceholder. That could also do with refactoring another time.

How has this been tested?

  • Did before/after manual tests to ensure the same functionality is kept
  • Added some unit tests (snapshots) for the new component.

Screenshots

There should be no difference in the UI/UX

Before (on master)
screen shot 2018-10-11 at 1 17 21 pm
screen shot 2018-10-11 at 1 17 29 pm
screen shot 2018-10-11 at 1 17 37 pm

After (this branch)
screen shot 2018-10-11 at 1 15 04 pm
screen shot 2018-10-11 at 1 15 20 pm
screen shot 2018-10-11 at 1 15 28 pm

Types of changes

Refactor (non-breaking change that tidies up code)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@talldan talldan added [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Code Quality Issues or PRs that relate to code quality [Type] Refactoring [Package] Editor /packages/editor labels Oct 11, 2018
@talldan talldan added this to the 4.1 milestone Oct 11, 2018
@talldan talldan self-assigned this Oct 11, 2018
IconButton,
} from '@wordpress/components';

class URLPopover extends Component {
Copy link
Copy Markdown
Contributor Author

@talldan talldan Oct 11, 2018

Choose a reason for hiding this comment

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

I had a couple of quandries about this new component.

  1. Should it be in the components package instead of editor? It does feel quite guten-specific, so I went with Editor.
  2. Technically, this could be used to edit anything. As such, I could go as far to call it something like InlineEditor, EditPopover, InlineEditPopover. Possibly worth waiting for that pattern to emerge before naming it something so generic. 🤷‍♂️

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you made the right call!

@talldan talldan requested a review from noisysocks October 11, 2018 05:30
@talldan talldan force-pushed the chore/extract-link-container-from-rich-text branch from 523ad00 to 49387e6 Compare October 12, 2018 04:27
Copy link
Copy Markdown
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

This is looking 💯! Left some small comments. Testing this locally now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not seeing anything in this example code that calls openURLPopover. Should we add a <button> that demonstrates it? Or just remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing docs for the isEditing prop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now removed the isEditingProp entirely.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could make this clearer by referencing isEditing by name.

Callback used to return the React elements that are rendered when `isEditing` is `true`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could make this clearer by referencing isEditing by name.

Callback used to return the React elements that are rendered when `isEditing` is `false`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could make this a little clearer.

Callback used to return the React elements that are rendered inside the `URLPopover` settings drawer that the user can expand open.

IconButton,
} from '@wordpress/components';

class URLPopover extends Component {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you made the right call!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bad person and this is a dumb nit but I think showSettings && ( <div /> ) looks nicer than using a ternary when in JSX.

onClickOutside={ onClickOutside }
>
<div className="editor-url-popover__row">
{ isEditing ? renderEditingState() : renderViewingState() }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any thoughts on having isEditing be entirely the responsibility of the parent component? That is, making this line:

{ renderLinkInterface() }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea and solves a problem. In the media placeholder there won't be a case where isEditing is false, so something like renderLinkInterface allows that to be expressed in a simpler way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could even use the children prop for a real 🔥 looking API:

<URLPopover
	renderSettings={ () => (
		<div></div>
	) }
>
	{ () => (
		<div></div>
	) }
</URLPopover>
``

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nice 👍

Copy link
Copy Markdown
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

This is lit 🔥

@talldan talldan merged commit 81bbd06 into master Oct 12, 2018
@talldan talldan deleted the chore/extract-link-container-from-rich-text branch October 12, 2018 06:08
mcsf pushed a commit that referenced this pull request Nov 1, 2018
* Extract rendering logic for LinkContainer into a new presentational component

* Give PositionAtSelection its own classname to uncouple it from LinkContainer

* Extract link container styles from rich-text into new link container component. Formalise class names.

* Add tests for new link container component

* Add docs

* Provide sane defaults for LinkContainer position and avoid spreading props

* Rename component to URLPopover

* Export the new component from the editor package

* Optionally render the settings button dependent on whether the renderSettings callback is provided

* Fix incorrect prop name in docs

* Update classnames used in e2e tests

* Move responsibility for managing the isEditing state completely to the implementor

* Improve docs

* Use boolean logic over a ternary

* Improve example

* Use children instead of RenderURLEditor callback

* Add docs for focusOnMount prop
@ellatrix ellatrix added [Type] Code Quality Issues or PRs that relate to code quality and removed [Type] Code Quality Issues or PRs that relate to code quality labels Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Editor /packages/editor [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants