Skip to content

Experimental Link creation interface#17846

Merged
talldan merged 113 commits intomasterfrom
try/unified-link-ui
Oct 30, 2019
Merged

Experimental Link creation interface#17846
talldan merged 113 commits intomasterfrom
try/unified-link-ui

Conversation

@getdave
Copy link
Copy Markdown
Contributor

@getdave getdave commented Oct 8, 2019

This PR is a working prototype for a potential new UI for adding/editing links.

It is a WIP and is not ready for review.

Closes #17557

How has this been tested?

  • Automated tests
  • Manually testing in the Playground

Screenshots

Screen Capture on 2019-10-16 at 11-34-37

Todo

  • Fix URLInput tests
  • Document changes to URLInput.
  • Increase test coverage for LinkControl.
  • Handle mailto and tel protocol plus internal anchors.
  • Fix console error when hitting ENTER key when the text input has a value and is focused.
  • Expose Posts, Pages and Categories in the default search results - as per this convo.~
  • Add publish date information to data fetch calls for search - currently, we only get bare-bones info about the found posts (see also above as may be related). Could we add publish date to the REST API in Core? Decided this was not required.
  • Add aria-hidden to the appropriate elements for entity-based results to avoid URL being read out to screen-readers.
  • Fix scrolling shadows on search suggestions. Looks odd in Safari. Maybe try this technique.
  • Implement [additional toggle draw for additional "additional settings"]
  • Avoid inline component pattern [for perf reasons]
  • Improve URL detection mechanic to recognise URLs that don't start with http or https.
    (Experimental Link creation interface #17846 (comment)).
  • The loading spinner makes the experience feel jumpy, is there a position for this that doesn't cause items below to move up and down as it toggles visibility?
  • Tweak line-height up a little on url within search suggestion items.
  • Restore visual indication of focus state when moving between items using keyboard.
  • Add into Nav Block for in situ testing.
  • Solve screen reader issue where the entire suggestion content is read out in a single sentence.
  • Truncate URLs for entity search suggestions and have them overflow with ellipsis rather than wrap.
  • Fix broken URLInput tests and check existing implementations across UI to ensure we haven't broken anything.
  • Document changes to URLInput.
  • Capitalise URL in the search results.
  • Implement ability to select an option.
  • Ability to remove a selected option.
  • Ability to edit a selected option.
  • Fix overflow issue when extra long url is entered. Because word does not break we need to handle this carefully.
  • Remove "trigger" button UI from the code - the current use cases indicated mean that this component should really only expose the link creation interface.
  • Implement "overflow" scroll on search results when many results are rendered.
  • Remove "insert" button on search results and reimplement <button>s for each result.
  • Test whether categories are returned by default in the search mechanic (doubtful). Determine whether this is actually a requirement or whether we should simply ensure we are exposing an API to allow utilisation of a custom post fetch mechanic.
  • Implement URL detection / parsing mechanic to distinguish URL entry from searches.
  • Implement URL "object" creation.
  • Implement "additional settings" UI as shown in designs.
    (Link interface iteration #17557 (comment)).
  • Fix bug where resetting input value doesn't clear the suggestions.
  • Determine whether it's feasible (for an MVP) to have URL search do a lookup of the entered site's <title> and favicon. We agreed this wasn't a hard requirement for an MVP.
  • Implement search term highlighting within search matches (eg: search is for "Foo" then the search result for Foobar Page should be formatted as "Foobar Page")

Testing Instructions

You can test this by

  • checking out this PR.
  • running npm run dev - leave this running and switch to a new terminal tab
  • [in a new terminal tab] running npm run playground:dev from the Gutenberg repo root.
  • you should see the new UI by going to http://localhost:1234

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.

@getdave getdave added the [Package] Block editor /packages/block-editor label Oct 8, 2019
@getdave getdave self-assigned this Oct 8, 2019
@youknowriad
Copy link
Copy Markdown
Contributor

Cool PR ❤️

Previously it wasn’t possible to customise the render of the search suggestions. By providing an optional render prop we now have full control over this if required.
…s render

Previously we relied on our own render of suggestions but this wasn’t hooked up to all the accessibility enhancements afforded by URLInput. By utilising the render prop exposed by URLInput to customise the rendering of suggestions, we can have the best of both worlds.
This is required to display the type of entitity in the search results for LinkControl
Previously when using the `renderSuggestions` render prop the user had to know how to put together the correct props on the correct elements in their custom render. By passing the default props for the listing element and the item element we can relieve the user of this burden by allowing them to spread the props onto the appropriate elements in their render without having to know how they are created.
Previously when a URL was entered it was deemed that no suggestions should or could be found and so the process of fetching suggestions was short circuited. Add additional prop to optionally allow developers to have URL-like values handled as suggestions.
…tcher

If the current value of the input is a URL then we conditionally pass a different handler for search results to the URLInput component. For URL based values we immediately return a “suggestion” object with values matching those entered by the user. Non URL based values are handled as previously.
retrofox pushed a commit that referenced this pull request Oct 29, 2019
retrofox pushed a commit that referenced this pull request Oct 29, 2019
retrofox pushed a commit that referenced this pull request Oct 29, 2019
We cannot assume the suggestion `id` will be unique. This is because at the moment the search results are `Post`s. However in the future we may also need to include `Category` terms and the term IDs could easily clash with the Post IDs as they are in different DB tables.

Using the `type` to differentiate the key.

Addresses #17846 (comment)
retrofox pushed a commit that referenced this pull request Oct 29, 2019
retrofox pushed a commit that referenced this pull request Oct 29, 2019
Previously `buildSuggestionItemProps` was including a key. However the implementation of `LinkControl` changed so that this was not required. However we forgot to reinstate on `URLInput`. This update ensures a key prop is set on the default output.

Note that disabling of the autofocus linting was already in place:

https://github.com/WordPress/gutenberg/blob/04e142e9cbd06a45c4ea297ec573d389955c13be/packages/block-editor/src/components/url-input/index.js#L239

Addresses #17846 (comment)
retrofox pushed a commit that referenced this pull request Oct 29, 2019
obenland and others added 5 commits October 29, 2019 14:27
Also fixes eslint errors that kept me from committing the original changes
Props @talldan

I really hope those changes I had to make in `search-input.js` don't break anything.
Copy link
Copy Markdown
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Thanks for all the hard work on this @getdave, @marekhrabe, @obenland, @retrofox!

I think it's in a good state to merge now. Any additional changes can be handled in separate smaller PRs.

@talldan
Copy link
Copy Markdown
Contributor

talldan commented Oct 30, 2019

Seems to be an issue with Travis/Github. The check says 'Canceled', but when you click into it everything (required) has passed. Merging this in spite of the weird status check.

Screen Shot 2019-10-30 at 12 18 13 pm

@talldan talldan merged commit d6ce94c into master Oct 30, 2019
@getdave
Copy link
Copy Markdown
Contributor Author

getdave commented Oct 30, 2019

Thanks @talldan and thanks for all your efforts and patience on this one 🎉🎉 🎉 🎉 🎉 🎉

isFullWidth,
hasBorder,
__experimentalRenderSuggestions: renderSuggestions,
placeholder = __( 'Paste URL or type to search' ),
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.

These new props should be documented.

See also: #11852

id: '-1',
title: value,
url: type === 'URL' ? prependHTTP( value ) : value,
type,
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.

Was there any planned usage for the various types associated with manual entry? As part of the ongoing discussion in #18061, I've been considering whether this is something where the explicit absence of the type could be a reasonably good indicator on its own for marking a value as "manual entry". The sorts of things that someone might want to do with type should be equally achievable with the @wordpress/url utilities, if a developer were so inclined. One of the issues I encountered in #19827 was trying to decide what the best complete set of these "subtypes" should be, where we would probably be better off to just not have to answer that.

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.

Was there any planned usage for the various types associated with manual entry? As part of the ongoing discussion in #18061, I've been considering whether this is something where the explicit absence of the type could be a reasonably good indicator on its own for marking a value as "manual entry". The sorts of things that someone might want to do with type should be equally achievable with the @wordpress/url utilities, if a developer were so inclined. One of the issues I encountered in #19827 was trying to decide what the best complete set of these "subtypes" should be, where we would probably be better off to just not have to answer that.

Follow-up: #20051

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) Needs Design Feedback Needs general design feedback. Needs Technical Feedback Needs testing from a developer perspective. [Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Link interface iteration