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

Update/edit flow for blocks which have a media placeholder #14918

Closed
wants to merge 15 commits into from

Conversation

draganescu
Copy link
Contributor

@draganescu draganescu commented Apr 10, 2019

Description

Closes #14795

This is a follow up to the image block edit flow update which ports the new flow to all the blocks which have media with an edit state. The blocks affected are:

  • media+text
  • cover
  • audio
  • video
  • file

How has this been tested?

For now I've only tested locally.

Types of change

New feature (non-breaking change which adds functionality)

Screenshots

Media + text

media+text

Cover

cover

Audio

audio

File

file

Video

video

Embed

embed

@talldan talldan added the [Status] In Progress Tracking issues with work in progress label Apr 11, 2019
@kjellr
Copy link
Contributor

kjellr commented Apr 11, 2019

This is looking great so far, @draganescu! I took it for a quick spin, and noticed just a couple small bugs:

  1. Would it be possible to add a "Cancel" button to the embeds?

Screen Shot 2019-04-11 at 12 02 35 PM

  1. It looks like the image preview is a little misplaced in the Media + Text block. I think we need to adjust the margins + max-width there to be a bit more comfortable:

Screen Shot 2019-04-11 at 12 06 25 PM

@draganescu draganescu added Needs Design Feedback Needs general design feedback. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). labels Apr 11, 2019
@draganescu
Copy link
Contributor Author

draganescu commented Apr 11, 2019

@kjellr so far there are three problems I know of:

  • the file block can't work with an URL the file block does work with URL!
  • the embed block doesn't have a cancel link (like you've also noticed)
  • the image in the media+text block (you found that :D I didn't see it b/c I used a square image)

Also I have marked this WIP b/c some of the code could be made more DRY and the edit/view pattern could be made the same in all blocks, maybe have an edit/view wrapper component?

@draganescu draganescu changed the title WIP: Update/edit flow for blocks which have a media placeholder Update/edit flow for blocks which have a media placeholder Apr 15, 2019
@draganescu
Copy link
Contributor Author

Rebased and updated with new snapshot so tests will pass. I think it's ready for review. Aside from code DRY-ness, there might be a point where we could make the code in these blocks more "standard" but maybe we could move ahead like this for now and refactor in a separate PR.

@kjellr if you can take it for another spin that'd be great! :)

@kjellr
Copy link
Contributor

kjellr commented Apr 18, 2019

Thanks, @draganescu! This is looking great. I noticed just one small bug:

For embed blocks, the "Cancel" link appears even before you enter a URL:

Screen Shot 2019-04-18 at 12 20 32 PM

Once that's all set, I think this is all set from a design perspective. Before we decide to move ahead for sure though, I'd love to get @jasmussen's thoughts on the DRY issue. He may have an idea for a quick fix.

@jasmussen
Copy link
Contributor

This is nice work, and it solves a problem, which is great. Like Kjell, I think it's close to shipping as an enhancement to what we have. There's just one issue that needs to be fixed before that:

Screenshot 2019-04-19 at 08 23 44

In this screenshot the edit image button appears to be part of the alignment group. The edit image button should always be its own group, and never be part of any other groups, because its behavior is different.


All this said, I feel like this interface also starts to show some of the limitations of the current placeholder interface we have, and suggests that we should separately look at improving this in a holistic way.

  • We have a generic appender for adding items, which features a dashed outline but same gray.
  • There's no dashed outline on the media placeholder, but there's a whole slew of buttons that are increasingly unwieldy and missing and some layout.
  • The flow for going from final state and back to setup state is a little inconsistent.
  • The button for going back to this state implies "Switch out", which is true, but it's still a little obtuse. And moreso, when it sits in the block toolbar it feels like it implies action on the whole block, which in the case of the Media & Text block is not the case. I wonder if it might be more clear to add the "Edit image" button to the overflow menu instead?
  • Sometimes clicking the edit button shows a preview of what's currently applied (image), other times it doesn't (embeds).

I don't feel like those issues are blockers for shipping this improvement. But it does feel like there is an opportunity to step back for a second and think: if we tackled appenders, edit buttons, and placeholder/setup states together, what could that do to improve the user experience? What could we eliminate? What could we improve?

@draganescu
Copy link
Contributor Author

draganescu commented Apr 19, 2019

rebased, fixed the button'd group (thanks @jasmussen), removed the cancel link (thanks @kjellr).
waiting on someone to review the code :)

@afercia if you could take it for a spin to make sure I didn't introduce accessibility issues with this update, that'd be awesome, thank you!

@draganescu draganescu added Needs Technical Feedback Needs testing from a developer perspective. and removed Needs Design Feedback Needs general design feedback. labels Apr 19, 2019
@draganescu draganescu requested a review from aduth as a code owner April 30, 2019 14:29
@talldan
Copy link
Contributor

talldan commented May 2, 2019

This one might be easier to review (and ship) if it were one PR per block.

I'll post some observations from testing as a comment and then loop back to a code review:

Media & Text

  • Some space is needed between the Media Library and Insert From URL buttons (seems to also apply to other blocks). This does seem to be an issue with the image block as well, so could always fix it after this PR for all blocks:
    Screen Shot 2019-05-02 at 5 13 06 pm

  • I have access to the Insert from URL option when logged in as a contributor, but the image is not added when I use it (it appears blank):
    Screen Shot 2019-05-02 at 5 23 29 pm

Cover

  • As a contributor, the edit image toolbar button doesn't show up after inserting from a URL (seems to work nicely as an admin, though):
    Screen Shot 2019-05-02 at 5 26 40 pm

Audio

  • The media library seems to be able to get a 'poster' for an audio clip. A future improvement might be to see if we can also access this and use it as the preview on the placeholder. The same may also be true for videos:
    Screen Shot 2019-05-02 at 5 30 20 pm

File

  • I'm seeing an issue using the Upload button from the placeholder. The upload seems to take place but the block immediately shows the placeholder again.

  • The filename and file link isn't updated when adding or replacing a file using 'Insert from URL' (could just use the url).

  • As a contributor, there's no cancel button when replacing a file. (seems to be an issue for multiple blocks)

Copy link
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.

I've made my way through about half the code, but there's quite a lot. I defo feel this could be split up into a PR per block. It'd be much easier to refine and ship each one indivdually.

One thing that having all the changes in one PR makes clear is how different yet the same all the media based blocks are. It'd be great to see some steps towards making the code the same across each one, even if it's just using the same style of code (methods vs inline functions, naming conventions).

Then it'd be easier at a later point to try to refactor them all to use some common code.

@@ -103,7 +107,7 @@ class AudioEdit extends Component {
const { setAttributes, isSelected, className, noticeOperations, noticeUI } = this.props;
const { editing } = this.state;
const switchToEditing = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The function should probably be renamed to something like toggleEditing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also noticed this function doesn't speak when switching while some of the other blocks do.

<BlockControls>
{ !! src && ( <Toolbar>
<IconButton
className={ classnames( 'components-icon-button components-toolbar__control', { 'is-active': this.state.editing } ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to add the components-icon-button classname, this is added by the IconButton component itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it seems like is-active would always be true as this is within an if statement if ( editing ) {

@@ -143,7 +160,7 @@ class AudioEdit extends Component {
className="components-icon-button components-toolbar__control"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issue with the components-icon-button classname. Looks like it was an existing issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems a shame to have to duplicate the code for this IconButton. Maybe it can be extracted to a separate component in the same file? Or the rendering logic could be reworked.

onDoubleClick={ this.toggleIsEditing }
onCancel={ !! url && this.toggleIsEditing }
notices={ noticeUI }
onError={ this.onUploadError }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this right? I couldn't see an onUploadError method.

<BlockControls>
<Toolbar>
{ !! href && ( <IconButton
className={ classnames( 'components-icon-button components-toolbar__control', { 'is-active': this.state.isEditing } ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

components-icon-button again


if ( ! href || hasError ) {
if ( ! href || isEditing || hasError ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be able to drop ! href here, since isEditing is now initialised to the right value.

@draganescu
Copy link
Contributor Author

Thanks @talldan! It feels like a great moment to refactor some code indeed, my fear is that other PRs on these blocks plus refactoring will make some mega conflicts given time :D. I will try to split in more than one PR and see how that goes.

Not sure about the issues when logged in as a contributor and how the media placeholder could have caused them :/

@talldan
Copy link
Contributor

talldan commented May 7, 2019

@draganescu - we can try to push this through for all the blocks, but based on experience I've seen that smaller PRs tend to ship more quickly and are more likely to be reviewed. They're also much easier to test.

Focussing on one block at a time is what I'd personally try to do.

A good way to do it might be to checkout the files from this branch for one block onto a separate branch. Haven't tried it but something like this might work to bring the changes across onto a new branch:

> git checkout master
> git pull
> git checkout -b update/edit-flow-for-audio-block
> git checkout update/edit-flow-for-media -- packages/block-library/src/audio/

@draganescu
Copy link
Contributor Author

@talldan as suggested I've split this into multiple PRs for easier review. I have also incorporated the bits collected from your past reviews (hopefully) in the new PRs.

Here they are:

Audio Block

#15520

Cover Block

#15519

Embed block

#15518

Media + Text Block

#15517

Video block

#15516

File block

#15515

@draganescu draganescu closed this May 8, 2019
@youknowriad youknowriad deleted the update/edit-flow-for-media branch May 27, 2020 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Needs Technical Feedback Needs testing from a developer perspective.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expand the new replace image flow out to other blocks
5 participants