Update/link control show preview of attachment in suggestion list #57824
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This is PR modifies LinkControl component to render preview of attachments instead of generic icon. But only if suggestion item type is attachment and mime type tells the component suggestion is indeed an image
Why?
Closes #57776
Issue was brought up by the linked issue.
Not in any way major new feature but this PR adds nice cherry on top of the editor experience.
How?
First problem was to figure out to know when it is okay to render preview image and when not (media library can contain other files than images). This was achieved by tracking the code which does the REST API call and purges bloating data from return data. Here I added new field
mineType
. See diff on__experimental-fetch-link-suggestions
Now that there is clear way of knowing what kind of attachment it is
SearchItemIcon
component is able to switch icon to img tag. As a side note clarity img tag has width and height attribute(s) but the block-editor styles overwrite height attribute to auto. I left it there to be extra transparent that image is going use 1/1 aspect ratioTesting Instructions
Testing Instructions for Keyboard
Screenshots or screencast