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

Editor: Enable linking to existing content #3197

Merged
merged 8 commits into from
Mar 1, 2016

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Feb 9, 2016

Closes #303
Blocked by #3193, #3575
Cherry-picks dcc54689123a09985fb9cf9f208ff3ac6fd95521 from #2472

This pull request seeks to enable a user to add a link by selecting existing content from their site to which the link should target.

Link to existing

Testing instructions:

Note that there are design flaws that cause the post selector to occupy more space than desirable, likely preventing you from confirming the link selection. These will be remedied with the merge of #3193.

  1. Navigate to the Calypso post editor
  2. Select a site, if prompted
  3. (Optional) Enter text in the post content area and highlight it
  4. Click Add / Insert Link in the editor toolbar
  5. Note that a selector field is made available to choose existing site content
  6. Click an option from the post selector
  7. Note that the URL field is populated with the URL of the selected content
  8. Note that if you are not adding a link to existing text, i.e. you skipped Step 3, that the title of the content is used as the Text field
  9. Note that the radio option is selected for the chosen content

@aduth aduth added [Feature] Post/Page Editor The editor for editing posts and pages. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 9, 2016
@aduth aduth self-assigned this Feb 9, 2016
@aduth aduth force-pushed the add/303-editor-link-to-existing branch from ceb6d47 to 3fd70dc Compare February 10, 2016 13:37
posts: {
items: {
'3d097cb7c5473c169bba0eb8e3c6cb64': { ID: 841, site_ID: 2916284, global_ID: '3d097cb7c5473c169bba0eb8e3c6cb64', title: 'Hello World' },
'6c831c187ffef321eb43a67761a525a3': { ID: 413, site_ID: 2916284, global_ID: '6c831c187ffef321eb43a67761a525a3', title: 'Ribs & Chicken' }
Copy link
Contributor

Choose a reason for hiding this comment

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

🍗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🍖 & 🐔

@timmyc
Copy link
Contributor

timmyc commented Feb 10, 2016

Very excited to see this becoming a reality - and the PostSelector has been used again :)

A few items:

  • I think we should label this with a design review because it does feel a little rough as-is right now
  • When I have a long-list of content to choose from, the dialog is quite vertically long once the content is loaded ( which might be a bad experience on mobile ), and while searching, the modal collapses and expands. Perhaps having a fixed height container around the selector, like we have in the page editor sidebar would be a quick fix
  • Did you consider having the post selector conditionally shown like it is in wp-admin? So users have to toggle the selector open ( could save some network requests if they don't plan on linking to existing content ).

Some of the experience above can be seen in this .gif - where I also encountered a bug it seems:

link-to

Steps to reproduce:

  • Type in some content
  • Highlight Content, click link button in toolbar
  • Use the search box to experience the growing/shrinking modal
  • I select some content from the list, radio selects 👍
  • Then click cancel
  • Any subsequent attempts to open the link dialog do not work. The dialog is not shown again but no errors are logged in the console.

@timmyc timmyc added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 10, 2016
@aduth aduth force-pushed the add/303-editor-link-to-existing branch from 3fd70dc to ff4eb60 Compare February 10, 2016 23:36
@aduth
Copy link
Contributor Author

aduth commented Feb 10, 2016

Thanks for the review, @timmyc !

Now that #3193 has been merged, the appearance is now much approved, and I've added a screenshot to the original comment.

Link to existing

I've added the design label in case there's feedback about the current appearance.

When I have a long-list of content to choose from, the dialog is quite vertically long once the content is loaded

I've set the height as fixed at 24vh. Admittedly, I've not tested this on mobile yet, which I'll plan to do in the morning.

Did you consider having the post selector conditionally shown like it is in wp-admin?

It's an option, but I quite like the idea of eliminating this extra step. The additional network request is pretty negligible on our end. To be clear, the request is not made until the dialog is opened.

where I also encountered a bug

I ran into a few bugs myself 😄 The one you noted was due to the fact that the dialog was quite "impure", and was not being properly re-rendered due to react-redux defaulting to pure render for any component wrapped using connect. It's not perfectly pure now, though there should be no issues with opening or closing the dialog as of 849ec23.

The behavior of assigning the link text was also pretty unpredictable. As of ff4eb60, the link text will only be assigned if existing text cannot be determined, either if editing an existing link, or if the user has set a custom link text.

Tomorrow, I'll plan to add some improvements to the <PostSelector /> component in a separate pull request to include a label describing the type of content if type="any" to improve clarity of content types and for consistency with wp-admin.

@aduth aduth added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Status] Needs Design Review Add this when you'd like to get a review / feedback from the Design team on your PR and removed [Status] Needs Author Reply [Triage] Needs Visuals labels Feb 10, 2016
@timmyc
Copy link
Contributor

timmyc commented Feb 11, 2016

Thanks for the notes - I'll do some more testing and do so on mobile and the :transformer: too :)

Since you brought up type="any" - when we have support for CPT's how would that operate? Is any just "post,page"?

@timmyc
Copy link
Contributor

timmyc commented Feb 11, 2016

iphone_6s_plus_-_iphone_6s_plus___ios_9_2__13c75_

Looking good on the simulator, and with the fixed heigh it is much better. Moving the visibility out of the state and into a prop has fixed the other issue I was seeing too - nice job.

I'll give it a spin on Edge/IE11 as well but this is looking great to me.

One other minor change that might be nice is to add some GA Events / and tracks to these actions. Tracking how often links are added, and if they are linking to existing content would be great data to have.

@aduth
Copy link
Contributor Author

aduth commented Feb 11, 2016

Since you brought up type="any" - when we have support for CPT's how would that operate? Is any just "post,page"?

Ideally, the REST API simply returns any known posts, regardless of type, if passed type=any. This unfortunately is not the case currently it seems, so only posts and pages will be returned (which is a shame).

Spoke too soon. The REST API already supports custom post types, but Jetpack sites must whitelist any custom post types using the rest_api_allowed_post_types filter:

https://developer.wordpress.com/2013/04/26/custom-post-type-and-metadata-support-in-the-rest-api/

@timmyc
Copy link
Contributor

timmyc commented Feb 11, 2016

Spoke too soon. The REST API already supports custom post types, but Jetpack sites must whitelist any custom post types using the rest_api_allowed_post_types

Which will be replaced by show_in_rest in WP-API, but does bring up the question of supporting that filter in WP-API endpoints, or requiring developers to switch over to the WP-API registration syntax.

@aduth
Copy link
Contributor Author

aduth commented Feb 11, 2016

but does bring up the question of supporting that filter in WP-API endpoints, or requiring developers to switch over to the WP-API registration syntax.

I imagine we could provide some backwards-compatibility for plugin authors who have already whitelisted with the Jetpack filter.

// See: WPCOM_JSON_API_Endpoint
function jetpack_allowed_post_types_compat( $args, $post_type ) {
    if ( in_array( $post_type, $this->_get_whitelisted_post_types() ) ) {
        $args['show_in_rest'] = true;
    }

    return $args;
}
add_filter( 'register_post_type_args', 'jetpack_allowed_post_types_compat', 10, 2 );

@timmyc
Copy link
Contributor

timmyc commented Feb 16, 2016

@aduth just tested out on Edge and it looks good. I'm good with this getting merged in, wasn't sure if @hugobaeta wanted to give it a quick design review - but will mark ready to merge.

@timmyc timmyc 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 Feb 16, 2016
@aduth
Copy link
Contributor Author

aduth commented Feb 17, 2016

Thanks @timmyc . I'll hold off a bit in case we can get #3264 and related changes in to improve the initial experience, but will plan to move forward with merging if those turn out to be rabbit holes.

@aduth
Copy link
Contributor Author

aduth commented Feb 19, 2016

Some last-minute testing revealed a few bugs with <PostSelector /> ordering, especially as subsequent pages were received. @timmyc , would you mind eyeing over the last three commits to see if they make sense to you (f50a44c, 4c4d172, 67b3a9d)? With these changes, the ordering should exactly match that of wp-admin, with the exception of our <PostSelector /> reflecting parent-child relationships in the display of options. It also allows rendering results with search terms as a hierarchy (detached children are shown as top-level).

@aduth aduth added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Ready to Merge labels Feb 19, 2016
@timmyc
Copy link
Contributor

timmyc commented Feb 24, 2016

@aduth would it make sense to save the sorted state in redux? Even if it were just a sorted set of global_ID pointers? That is the only thing that feels strange after reading over the last 3 commits

@aduth
Copy link
Contributor Author

aduth commented Feb 24, 2016

@aduth would it make sense to save the sorted state in redux? Even if it were just a sorted set of global_ID pointers?

Relevant to this point: #3522

We tend to encourage using selectors in place of redundant data in the state tree. If we were to introduce something like reselect, it would be reasonable to create a memoized selector for retrieving the treeify'd posts hierarchy. Maybe we should hold off and see where that pull request goes...

@aduth
Copy link
Contributor Author

aduth commented Feb 29, 2016

There's been some blockers parallel to this pull request which have since been merged, so this is once again ready for final review.

Rebased changes account for:

Also included analytics tracking in 9c4e1b8, as requested by @timmyc.

import { getSelectedSite } from 'state/ui/selectors';
import { getSitePosts } from 'state/posts/selectors';
import { decodeEntities } from 'lib/formatting';
import { recordEvent, recordStat } from 'lib/posts/stats';
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 Thanks for tidying.

@gwwar
Copy link
Contributor

gwwar commented Mar 1, 2016

👍 Code looks good and I tested the linking functionality. Should be good to 🚢 once you get the design +1

@aduth aduth force-pushed the add/303-editor-link-to-existing branch from 9c4e1b8 to 3e3ff60 Compare March 1, 2016 19:47
@aduth aduth force-pushed the add/303-editor-link-to-existing branch from 3e3ff60 to d864566 Compare March 1, 2016 19:51
@aduth
Copy link
Contributor Author

aduth commented Mar 1, 2016

once you get the design +1

I'm going to go ahead and remove that label. Iterations on the design of the <PostSelector /> have occurred separately from this pull request, particularly in #3193.

@aduth aduth added [Status] Ready to Merge and removed [Status] Needs Design Review Add this when you'd like to get a review / feedback from the Design team on your PR [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Mar 1, 2016
aduth added a commit that referenced this pull request Mar 1, 2016
@aduth aduth merged commit f81c9c5 into master Mar 1, 2016
@aduth aduth deleted the add/303-editor-link-to-existing branch March 1, 2016 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Post/Page Editor The editor for editing posts and pages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants