Skip to content

Add/805-playlist-refactor-2#9169

Closed
antpb wants to merge 144 commits intoWordPress:masterfrom
antpb:add/8050-playlist-refactor-2
Closed

Add/805-playlist-refactor-2#9169
antpb wants to merge 144 commits intoWordPress:masterfrom
antpb:add/8050-playlist-refactor-2

Conversation

@antpb
Copy link
Copy Markdown
Contributor

@antpb antpb commented Aug 20, 2018

This is a clean PR to add the playlist block to Gutenberg. There were merge conflicts that resulted in me needing to create a new branch based on the newest version of Gutenberg. Previous conversation can be found here: #7126

There is one bug currently with notices where the mismatched type error shows 4 of the same notice. Working through that and we should be good for another review.

CC: @karmatosed @noisysocks

antpb and others added 30 commits May 30, 2018 20:42
initial commit
starting playlist over
….may need core mod >_<

storing ids in comment as ids attribute. moving to render callback....may need core mod >_<
….may need core mod >_<

storing ids in comment as ids attribute. moving to render callback....may need core mod >_<
This simply moves the playlist block in the list of blocks imported and registered in core-blocks/index.js.
This commit generally accomplishes a few thing:
- Removes any unused variables and functions
- Ensuring all used functions and variables are declared
- Simplifies some variable declarations
- Fixing spacing to conform to WP style
This fixes up code style issues, adds correct docblocks, and removes unneccessary script rendering which isn't necessary during server rendering.
This wraps the shortcode output in a `figure` element with a class of `wp-block-playlist` applied so we can style the block accordingly.
This adds an editor.scss file to the playlist block that removes margins from `.wp-playlist-block` elements, to avoid margins being added as a default style by browsers.
This adds an align attribute to the playlist block and adds the proper alignment class to the markup on the front end to support alignments. This also deletes the style.scss file, which now seems unnecessary.
Playlist block updates @joemcgill  fixed a ton of formatting and bugs. :D
}

/**
* The function is used after the editor has enqueued playlist dependencies.
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.

Nitpicks:

  • Proper JSDoc alignment should have space before each * of the body, after the tab
  • The newline between the JSDoc block and the function declaration may prevent it from being parsed correctly as associated. I suggest removing it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed :)


category: 'common',

attributes: {
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.

It is a duplication, yes. You shouldn't need to define attributes here. I'll need to take a closer look to understand where things aren't working correctly.

onSelectMedia( media ) {
const { setAttributes } = this.props;
//check if there are returned media items and set attributes when there are
if ( media && media[ 0 ].url ) {
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.

When will media be falsey?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't believe it will ever be unless there is an error maybe. We also have a similar check in the Audio block. I was matching that for consistency on the chance there was an instance I was unaware of: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/audio/edit.js#L88

onSelectMedia( media ) {
const { setAttributes } = this.props;
//check if there are returned media items and set attributes when there are
if ( media && media[ 0 ].url ) {
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.

Why do we test for a url property which we have no intention of using? Do we care about the property, or just that media.length > 0 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we shouldnt. I've removed the condition

getMimeBaseType( type ) {
const { noticeOperations } = this.props;
if ( ! type ) {
noticeOperations.createErrorNotice( 'MIME Type could not be determined' );
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.

Nitpick: Why is "Type" capitalized?

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.

Noting that this message will be shown multiple times if multiple files cannot have their mime types determined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've fixed the capitalization. Will think through the multiple messages bit. Can create an issue for it also after merge if we want to save that for future work.

uploadFromFiles( event ) {
const { noticeOperations } = this.props;
if ( ! event.target.files ) {
noticeOperations.createErrorNotice( 'Files list provided is empty' );
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.

I sense that these should be localized?

this.onUploadFiles( event.target.files );
}

getMimeBaseType( 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.

Minor: I don't expect a function prefixed with "get", particularly one like this which could theoretically be made generic (mime type has meaning outside the playlist block) to have a side-effect such as causing a notice to be created.


category: 'common',

attributes: {
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.

I tested locally and I see no obvious issues when removing attributes from this JavaScript file. Can you elaborate on what you're seeing?


// Allowed type specified by consumer
const isAllowedType = ( fileType ) => {
return ( allowedType === '*' ) || startsWith( fileType, `${ allowedType }/` );
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.

I'm not really sure I understand.

  • What failures were you seeing without these changes? You're not specifying * so I don't see why it would have any impact to leave it.
  • Regardless of whether a * is sensible, it exists and is already in use by the Files block. If we want to remove it, we need to remove any references to it. Speaking personally, I don't really like * as the wildcard. It seems like if someone wants any file to be uploaded, they should just omit the allowedType property altogether. But then again, this change has nothing to do with a Playlist block implementation and seems like it should be a separate effort.

if ( ! isEqual( prevProps, this.props ) ) {
this.fetch( this.props );
}
if ( this.state.response !== prevState.response ) {
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.

It's a bit awkward to call a prop in response to a state change in componentDidUpdate, since a component manages its own state and begs the question why isn't the prop called at the time we're calling setState ? Our current implementation of ServerSideRender#fetch doesn't make this very easy to refactor, though...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this a merge blocker? If not can we bring it to an issue after? I think there would have to be an alteration of ServerSideRender to accomplish this. I fear it may introduce more bugs

*/

initializePlaylist() {
window.wp.playlist.initialize();
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.

@youknowriad, this block depends on both WordPress global wp.playlist and ServerSideRender component which is very backend tied. We need to do something about it. There should be reusable blocks which work everywhere and blocks which are reusable but WordPress specific. If we would draw this distinction we wouldn't have to worry about Code and Freeform anymore.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, a first step would be to move it ouside of the packages like html or freeform. Later on, we'd need to rewrite wp.playlist as a Gutenberg package and then move the block to the packages as well.

'post' => $post->ID,
) );
wp_enqueue_editor();
wp_playlist_scripts( 'audio' );
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.

Shouldn't wp.playlist to be listed as a dependency of wp-block-library? It's referenced it in the code so I would assume that it needs to be.

@gziolo
Copy link
Copy Markdown
Member

gziolo commented Aug 30, 2018

Did you check how much more data users will have to load in their browser to be able to use this block? In particular, how much weigh all the files enqueued with those two lines:

wp_playlist_scripts( 'audio' );
wp_playlist_scripts( 'video' );

@antpb
Copy link
Copy Markdown
Contributor Author

antpb commented Aug 30, 2018

@gziolo there was some previous discussion about this in an earlier review. It adds about 110-120kb : #7126 (comment)

@aduth
Copy link
Copy Markdown
Member

aduth commented Aug 30, 2018

The additional weight is significant, particularly for a block which won't always be commonly used by a large subset of users.

I wonder if it's something where we should employ the technique as we did for the HTML block and CodeMirror:

function loadScript() {
return new Promise( ( resolve, reject ) => {
const handles = [ 'wp-codemirror', 'code-editor', 'htmlhint', 'csslint', 'jshint' ];
// Don't load htmlhint-kses unless we need it
if ( window._wpGutenbergCodeEditorSettings.htmlhint.kses ) {
handles.push( 'htmlhint-kses' );
}
const script = document.createElement( 'script' );
script.src = `${ siteURL }/wp-admin/load-scripts.php?load=${ handles.join( ',' ) }`;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild( script );
} );
}
function loadStyle() {
return new Promise( ( resolve, reject ) => {
const handles = [ 'wp-codemirror', 'code-editor' ];
const style = document.createElement( 'link' );
style.rel = 'stylesheet';
style.href = `${ siteURL }/wp-admin/load-styles.php?load=${ handles.join( ',' ) }`;
style.onload = resolve;
style.onerror = reject;
document.head.appendChild( style );
} );
}

Also related: #8017

@aduth
Copy link
Copy Markdown
Member

aduth commented Aug 30, 2018

Raising other options to explore / consider:

  • Simplify what we're displaying as a preview in the editor. Avoid pulling in any dependencies and just render a simplified list of file names (no in-browser preview in editor).
  • Make it the responsibility of ServerSideRender to bundle the relevant scripts, whether that's inline or as part of an embedded iframe.

@antpb
Copy link
Copy Markdown
Contributor Author

antpb commented Aug 30, 2018

@aduth After digging into this a bit today, I remember the thought process in adding the playlist enqueues to client-assets. If you remove the script calls from that file and create a playlist block, the block responds that it has encountered an error and cannot load. Saving/publishing the post and refreshing the editor magically allows it to render with it's dependencies.

Something is not triggering in ServerSideRender at the right time to enqueue the dependencies. Still digging through this, but I think the best path forward is the lazy load solution proposed earlier with a state that says that it has dependencies before render.

@joemcgill
Copy link
Copy Markdown
Member

Related to #805

@Soean Soean mentioned this pull request Jan 14, 2019
@gziolo
Copy link
Copy Markdown
Member

gziolo commented Apr 24, 2019

@melchoyce @mapk @jasmussen @karmatosed @youknowriad - what's the plan regarding this block? It isn't listed as the block planned for phase 2.

@gziolo gziolo added Needs Decision Needs a decision to be actionable or relevant and removed [Status] In Progress Tracking issues with work in progress labels Apr 24, 2019
@mapk
Copy link
Copy Markdown
Contributor

mapk commented May 8, 2019

what's the plan regarding this block? It isn't listed as the block planned for phase 2.

Definitely not on our list of priorities right now.

I'm going to close this because it hasn't been touched since September 2018. But I don't want to discourage contributors from working on something they're passionate about. If anyone feels like refactoring this and opening it back up, go ahead. 😄

@mapk mapk closed this May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Blocks Overall functionality of blocks Needs Decision Needs a decision to be actionable or relevant

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants