-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance link control UI with rich URL previews (#31464)
* Add new helper to utilise new REST endpoint * Provide docblock * Provide docblock * Get title tag contents from remote URL * Create distinct data object for rich meta rather than rely on overiding suggestion result data. * Add example of adding rich details to the link preview * Add icon, image and description * Add icon, image and description * Add in description * Remove url data to hook and prevent setting state on unmounted * Avoid ref destructure * Add loading animation * Clear richdata on url change * Avoid rich data in search items * Account for preview layout variation requirements * Only fetch if fetchRemoteUrlData is available * Fix text overflow ellipsis * Improve icon visual scaling * Manage fetching as state * Add tests for rich data and resolve exposed bugs * Fix broken async/await code and restore test running * Tidy code comments * Updates to use visually truncated description text * Clip image height, center and provide border-radius and background * Apply correct spacing as per design provided * Allow text to flow (almost) to edge of `Edit` button before ellipsis * Constrain image height to 140px as per Figma design * Add tests to cover missing data edge cases * Fix cancel pending fetch when URL changes. * Remove isMounted anti pattern in favour of explictly cancelled promise pattern See https://reactjs.org/blog/2015/12/16/ismounted-antipattern.html * Update comments to make reason for cancelling on URL change clearer * Fix broken tests by disabling rich reviews in those tests which do not exercise this feature * Move make cancelable util into own file * Allow for passing options to fetchRemoteUrlData This enables the usage of AbortController signal * Use AbortController to cancel requests rather than cancellable promise wrapper * Force remount preview when the URL changes Previously a URL might change and the component would not remount which could lead to edge cases. Addresses #31464 (comment) * Implement simpler hook via abortable fetch Based on https://codesandbox.io/s/dry-pond-43qy2?file=/src/link-control.js:187-201 * Fix to ensure correct handling of aborted vs standard fetch errors Avoid situation where requests which 404 do not result in the fetching UI being reset. * Add test to cover resetting fetching state if rich data requests fails * Simplify hook implementation * Guard for legacy browsers * Refactor to useReducer * Disable rich previews by default and enable only in inline text by default * Update packages/editor/src/components/provider/use-block-editor-settings.js Co-authored-by: Kai Hao <[email protected]> * Update to hasRichPreviews Address feedback from #31464 (comment) * Use correct prop to enable rich previews in rich text * Fix e2e test to allow unlinking when rich data obscures block toolbar * Add permenant missing data placeholders with loading animation * Fix tests * Update snapshots * Update doc block Co-authored-by: Kai Hao <[email protected]> * Restore makecancellable to a local util Co-authored-by: Kai Hao <[email protected]>
- Loading branch information
1 parent
7709d7b
commit 6530dfc
Showing
10 changed files
with
876 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.