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

Nav Block - show recent pages as default suggestions when creating Nav Links #19458

Merged
merged 29 commits into from
Jan 15, 2020

Conversation

getdave
Copy link
Contributor

@getdave getdave commented Jan 7, 2020

Screenshot 2020-01-08 at 11 37 27

Description

Closes #18899.

When first creating a Nav Link ("item") Block the hyperlink UI presents a blank search field. To better serve the default use case of adding pages, this PR updates the implementation to display a list of the most recently created Pages.

This involves a refactor of the URLInput to add a new boolean prop initialSuggestions which (internally) affords the ability to trigger rendering of search results without anything being entered into the <input> field (for more on this see the original Issue) triggers a call for default search results when the input field is empty.

How has this been tested?

  1. Add Nav Block
  2. Insert new Nav Link Block.
  3. See a list of most recently created Pages displayed as the default search results in the hyperlink creation UI.

Screencapture

Screen Capture on 2020-01-08 at 11-35-37

Types of changes

New feature (non-breaking change which adds functionality).

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .

@getdave getdave added the [Block] Navigation Affects the Navigation Block label Jan 7, 2020
@getdave getdave self-assigned this Jan 7, 2020
@getdave getdave marked this pull request as ready for review January 7, 2020 14:03
@getdave
Copy link
Contributor Author

getdave commented Jan 7, 2020

Pinging @youknowriad because I know he's concerned about ongoing changes to LinkControl.

@shaunandrews
Copy link
Contributor

I wonder if 5 items is too many. With the way things fade out, it looks a little awkward. Maybe 3 suggestions would help clean up the default view of this popover, making it visually simpler by default.

@jeryj
Copy link
Contributor

jeryj commented Jan 7, 2020

I much prefer this implementation to the empty state. Nice work, @getdave! Here are the few things I found during my functional review. The first and second likely the only one that seems worth addressing within this PR.

Always update text from selected link?

selecting link should update text

When selecting a new suggestion off of a page that already has text, I think the text should default to being replaced by the selected title. Currently it remains the same. I can see how this would be maybe be preferable if they entered custom content, but I think it's probably more likely they just want the text replaced.

Keyboard navigation?

At the moment there is no way (that I saw) to access the pages list via the keyboard. The tab key cycles between the input and the X to clear the link.

First initialization of empty menu doesn't show the recommended links

first initialization on empty menu doesn't show recommended pages

I'm not sure what is causing this one, but the initialization of an empty menu on a new page doesn't show the pages list. Any subsequent ones show the list. If the page already has a nav block, it also shows the list fine. It appears to only occur on the first initialization and then the auto-opening of the link field.

Account for items already in the menu?

Suggested pages are already in the menu

This isn't necessarily an issue, but do we want to handle the suggestions based on what items are already in the menu? The most recently published items are already within the menu in this screenshot.

@getdave
Copy link
Contributor Author

getdave commented Jan 8, 2020

I wonder if 5 items is too many. With the way things fade out, it looks a little awkward. Maybe 3 suggestions would help clean up the default view of this popover, making it visually simpler by default.

@shaunandrews I've updated to 3 as suggested (see updated screencapture in PR desc)

@getdave
Copy link
Contributor Author

getdave commented Jan 8, 2020

@jeryj Thanks for the review.

First initialization of empty menu doesn't show the recommended links

Nice catch. This was a bug in my implementation. I've resolved this and you can see it working in the screencapture in the PR desc.

Keyboard navigation?

Another great catch. I've also fixed this but I'd appreciate you confirming via a manual test. Thanks.

Always update text from selected link?

I think this is a good point but not for this PR. Would it be possible for you to raise an Issue and then we can discuss the desired behaviour?

Account for items already in the menu?

We don't but we could...I'm thinking maybe in a followup PR so as not to block the basic working implementation but I could be persuaded...

@getdave
Copy link
Contributor Author

getdave commented Jan 8, 2020

I've broken the tests. Am going to look at this tomorrow.

@apeatling
Copy link
Contributor

apeatling commented Jan 8, 2020

I had a good test of this. I think having the recent pages there is a good addition. Plus one to @jeryj's feedback above.

I think this could merge as it exists because it works well, however I've opened another issue with some visual improvements that I think should be discussed and iterated on as a follow up:

#19513

As per the GH thread below, this refactors the code to avoid the need to introduce a new fetch API around `__experimentalInitialSuggestions`. Now instead we simply reuse the existing fetchSuggestions handler to get the initial results. The only different being we introduce an arguments object to queries to restrict the number of results displayed for initial Suggestions.

See #19458 (comment)
This is a temp fix and I’ve raised an Issue to solve the core issue which will then make this fix redundant.

#19634
@getdave getdave merged commit b448074 into master Jan 15, 2020
@getdave getdave deleted the add/show-pages-default-when-creating-nav-links branch January 15, 2020 11:12
@getdave
Copy link
Contributor Author

getdave commented Jan 15, 2020

I neglected to update the Nav Block to use the renamed showSuggestions prop. Created a followup PR here.

Comment on lines +30 to +36
const { keyCode } = event;

event.stopPropagation();

if ( keyCode === ENTER ) {

}
Copy link
Member

Choose a reason for hiding this comment

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

Were these changes intended to have been included? Looks like dead code to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dead code. Being removed elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block Needs Technical Feedback Needs testing from a developer perspective. [Tool] E2E Test Utils /packages/e2e-test-utils [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation Link: Default to list of pages