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

Add/805-playlist-refactor-2 #9169

Closed
wants to merge 144 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
ef14b27
initial commit
antpb May 31, 2018
963e1c4
playlist init
antpb May 31, 2018
56d89ef
storing ids in comment as ids attribute. moving to render callback...…
antpb Jun 3, 2018
8024ef6
storing ids in comment as ids attribute. moving to render callback...…
antpb Jun 3, 2018
2b5a083
playlist_block_callback_dependencies function. adds index.php
antpb Jun 4, 2018
f35d9ef
cleaning up attributes and logging code. removes mediaelement component
Jun 4, 2018
387a964
serversiderender component being used now in edit...workign through a…
Jun 4, 2018
b3f4f67
removes client-asset changes meant for mediaelement component
Jun 4, 2018
67e55d3
adds media-upload changes to support playlist modal
Jun 4, 2018
a41060d
adds type attribute for video/audio conditional for the render callback
Jun 4, 2018
bdb9040
fixed edit state and now when you edit post, it acts as expected - co…
antpb Jun 9, 2018
204421f
Adjusted some of the wording to include video language...not just audio
antpb Jun 11, 2018
ca9776f
Group coding by antpb - noisysocks - soean
antpb Jun 14, 2018
9289d24
Fixing noisysocks suggested changes
antpb Jun 14, 2018
56b7d46
Load playlist block alphabetically
joemcgill Jun 15, 2018
b8d8e1a
Clean up lint errors
joemcgill Jun 15, 2018
bc65ce2
Clean up dynamic rendering PHP code
joemcgill Jun 15, 2018
52437ff
Wrap server rendered playlists in figure element
joemcgill Jun 15, 2018
dca6449
Remove non-playlist styles from the playlist stylesheet.
joemcgill Jun 15, 2018
4561b5c
Fix playlist margins in the editor
joemcgill Jun 15, 2018
f7d7cfe
Fix alignment support for the playlist block
joemcgill Jun 15, 2018
e74ab60
Merge pull request #1 from joemcgill/add/playlist-block
antpb Jun 16, 2018
4c8efb9
Fixed edit button to auto populate media modal
antpb Jun 16, 2018
7dbe010
cleaned up spacing issues
antpb Jun 16, 2018
ed19672
fixes Soean's suggestions and adding attributes to fix settings issue
antpb Jun 19, 2018
9f03842
removes some silly test code
antpb Jun 19, 2018
936732b
Add controls and fix lint errors
Soean Jun 19, 2018
92c2306
Merge branch 'master' into add/playlist-block-805
antpb Jun 20, 2018
87d9fee
removes `SettingsView` from Playlist Media view
antpb Jun 20, 2018
3d5cabb
fixes gallery mutiple bug - Nice find @noisysocks !
antpb Jun 20, 2018
5807b58
sets defaults to on for tracklist, images, artist as per Core defaults
antpb Jun 20, 2018
9ef6fe9
sets defaults for front end render as well as fixes lint errors (some…
antpb Jun 20, 2018
acc9d07
removes silly array of arrays and adds back in SettingsView to make b…
antpb Jun 21, 2018
c21a650
adds style control for playlist: dark, light
antpb Jun 21, 2018
009b015
should fix merge conflict
antpb Jun 21, 2018
0bcda76
changes edit-post/hooks/blocks to components for merge conflict
antpb Jun 21, 2018
bd4aaf0
fixes more merge conflicts
antpb Jun 21, 2018
64ec71d
Merge branch 'master' into add/playlist-block-805
antpb Jun 21, 2018
066b423
uses new IconButton component to match gallery
antpb Jun 21, 2018
0fd27e6
Merge branch 'add/playlist-block-805' of https://github.com/antpb/gut…
antpb Jun 21, 2018
8a48a5d
fixes `ServerSideRender` update for settings
antpb Jun 21, 2018
9eff5be
@soean provided me the golden snippet of code to fix uploads
antpb Jun 21, 2018
b0016d6
removes `SettingsView`
antpb Jun 21, 2018
9893f67
linting fix from spaces to tabs
antpb Jun 21, 2018
e071f4e
Fixes WPCS warnings
Soean Jun 21, 2018
4eb9933
Remove isPlainObject and map from SSR
Soean Jun 21, 2018
2028558
fixes `Media Library` button
antpb Jun 21, 2018
d657801
auto sets type based on first item in media array passed back from up…
antpb Jun 21, 2018
37dfe3e
adds type attribute to edit button to pass back to the media views...…
antpb Jun 21, 2018
7bbb05d
adds edit condition for videos so media view focuses on video's and n…
antpb Jun 21, 2018
3483f51
changes frame to select since that is what a user would probably want…
antpb Jun 22, 2018
d822609
adds @karmatosed design recommendations and fixes an upload bug intro…
antpb Jun 25, 2018
3d88be5
Improve toggle functions
Soean Jun 27, 2018
cbbc013
hides settings in media modal on gutenberg editor pages. ¯\_(ツ)_/¯
antpb Jun 27, 2018
ad28c14
Fix toggle style
Soean Jun 27, 2018
f9b38ca
fixing merge conflict
antpb Jun 28, 2018
bb73b01
fixing merge issue of including package-lock
antpb Jun 28, 2018
6258f6e
updating package-lock to match master because my local environment wa…
antpb Jun 28, 2018
71e4ab0
Merge branch 'master' into add/playlist-block-805
antpb Jun 28, 2018
a04b1a3
final changes to remove package-lock.json from this PR
antpb Jun 28, 2018
be9e249
removing extra =
antpb Jun 28, 2018
f59b124
Alow upload video and audio files
Soean Jun 29, 2018
fcb7720
Refactor Code
Soean Jun 29, 2018
3b53f4c
Add tests
Soean Jun 29, 2018
4495b53
changes playlist icons to better indicate both video AND audio.
antpb Jun 29, 2018
ecda6d8
Revert "changes playlist icons to better indicate both video AND audio."
antpb Jun 29, 2018
b8f1f4c
refactor naming of editing state and code tweak
antpb Jul 5, 2018
a0d7c63
fixes conditional in onFileChange
antpb Jul 5, 2018
259c877
refactors naming of addFiles to onUploadFiles and removes unnecessary…
antpb Jul 5, 2018
472c114
adds period to Placeholder instructions
antpb Jul 5, 2018
376d17c
fixes accepted types to comma-separated string
antpb Jul 5, 2018
c56dcb9
fixes style options to be inline. maybe more styles some day :D
antpb Jul 5, 2018
d3350ee
sets type default to audio to initialize media modal
antpb Jul 5, 2018
2109b12
sets mediaUpload value correctly using `mediaIds`
antpb Jul 5, 2018
657002d
spaces child of component correctly
antpb Jul 5, 2018
2f60476
removes lint rules
antpb Jul 5, 2018
49bedca
css spacing
antpb Jul 5, 2018
e40103c
simplifies margin css
antpb Jul 5, 2018
2fa9892
renames artists attribute to better indicate action
antpb Jul 5, 2018
fc8f94e
fixes typo
antpb Jul 5, 2018
e18032b
fixes sneaky tab
antpb Jul 5, 2018
361feac
fixes other sneaky tab
antpb Jul 5, 2018
b5d8e33
renames `playlistItemObject` to `slimPlaylistItemObject`
antpb Jul 5, 2018
37a2579
fixes abbreviations
antpb Jul 5, 2018
6f6c4c2
fixes strcuture of `multiple` and `playlist` checks in mediaupload
antpb Jul 5, 2018
f3006b3
fixes slimPlaylistItemObject
antpb Jul 5, 2018
18a0a87
adds castArray to utils/mediaupload
antpb Jul 5, 2018
67cad1b
Merge branch 'master' into add/playlist-block-805
antpb Jul 5, 2018
c0e0a1a
fixes `showArtists` in index.php
antpb Jul 5, 2018
b6a17d4
sets default for php render to default 'audio' fixes a bug introduced…
antpb Jul 5, 2018
dcec18d
adds space again to css file
antpb Jul 5, 2018
dac419c
fixes upload issue adding back in mime_type removed from merge conflict
antpb Jul 5, 2018
0dab772
renames mime_type to mimeType
antpb Jul 5, 2018
393d614
removes test code for another issue...
antpb Jul 5, 2018
162a554
sets attribute 'artists' as 'showArtists' as the shortcodes expects. …
antpb Jul 9, 2018
bfd8bc7
adds showTrackNumbers attribute to expose more of the shortcode options
antpb Jul 9, 2018
cb19ef1
uses this.props.attributes to fix edit state bug.
antpb Jul 9, 2018
d9524cd
changes playlist block description to exclude `core` verbiage
antpb Jul 9, 2018
24b9fcd
Merge branch 'add/playlist-block-805' into add/805-playlist-refactor
antpb Aug 2, 2018
3431902
php coding standards fix
antpb Aug 3, 2018
93c2505
Added more tabs to comply with coding standards
ianbelanger79 Aug 3, 2018
5ce74cc
Moved => inline with the rest
ianbelanger79 Aug 3, 2018
9ad4efd
First pass at error notices on inconsistent type
antpb Aug 9, 2018
f15dc98
should use proper mediaUpload function. attempting to refresh master.…
antpb Aug 16, 2018
9769bc7
Merge branch 'add/805-playlist-refactor' into add/8050-playlist-refac…
antpb Aug 16, 2018
568add4
fixes css and adopts new block structure
antpb Aug 17, 2018
30cf066
updates code to new standards in latest Gutenberg while fixing Notice…
antpb Aug 17, 2018
2c9bc77
removes some from lodash because we dont want THAT some :)
antpb Aug 17, 2018
6f2c39d
fixes fixture issue Travis CI identified
antpb Aug 20, 2018
b23e209
fixes snapshots for Travis
antpb Aug 20, 2018
9f74b21
fixes more fixture things for tests
antpb Aug 20, 2018
d8d44ff
trying to make phpcs happy
antpb Aug 20, 2018
52eea61
fixes linting issue with blockEditRender now properly being imported
antpb Aug 20, 2018
fffe8c3
attempting to appease Travis
antpb Aug 20, 2018
c758bae
fixing blockEditRender path and bringing php function to one line
antpb Aug 20, 2018
a85e022
fixes eslint issue
antpb Aug 20, 2018
c289c0d
adding hasError state to help with duplicate notices being thrown for…
antpb Aug 20, 2018
0c6367a
takes condition out of render and adds componentDidUpdate to trigger …
antpb Aug 21, 2018
2e46097
moves resetting the state to onSelectMedia. Now producing one notice …
antpb Aug 23, 2018
b1862bd
removes error state from else condition on consistent type check
antpb Aug 23, 2018
3fe54a0
fixes bug where any upload produced error message regardless of type …
antpb Aug 23, 2018
130bd80
moves first type and isConsisstentType const outside of the onFileCha…
antpb Aug 23, 2018
1b8e285
adds suggestions on setting state
antpb Aug 23, 2018
3676520
fixes mismatched type issues by changing condition to check type and …
antpb Aug 23, 2018
e7e3fee
fixes type check
antpb Aug 23, 2018
302899f
fixes state issue where null was accepted as ids
antpb Aug 23, 2018
e4bf110
fixes weirdness where we needed to stringify and json encode the ids …
antpb Aug 23, 2018
ccff39f
fixes tests for new ids array
antpb Aug 23, 2018
d59638e
fixes tests for ids array
antpb Aug 23, 2018
848bae3
fixes js tests
antpb Aug 24, 2018
36755a4
removes mediaIds as it is no longer needed
antpb Aug 24, 2018
b1b26fc
refactor based on review by @aduth
antpb Aug 24, 2018
094b917
removes isEditing state completely
antpb Aug 24, 2018
d4ab87a
adds initializePlaylist documentation
antpb Aug 24, 2018
b5743f3
pulls getMimeBaseType out of the component
antpb Aug 24, 2018
06d0e90
adds condition to verify type is passed from the files uploaded
antpb Aug 24, 2018
f3b25c8
adds check to if files list exists
antpb Aug 24, 2018
32fb80d
fixes JS tests
antpb Aug 24, 2018
7ebde3c
removes attributes from index.js to make things tidy
antpb Aug 29, 2018
3c60c35
fixes comment spacing for JS standards
antpb Aug 29, 2018
612ddce
removes condition
antpb Aug 29, 2018
c2e9ec5
fixes error message capitalization
antpb Aug 29, 2018
bb9ae00
adds localization, fixes gallery view defaults, and fixes upload issu…
antpb Aug 29, 2018
4119c5a
conditionally loads playlist dependencies instead of doing it in clie…
antpb Oct 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions block-library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import * as latestPosts from '../packages/block-library/src/latest-posts';
import * as list from '../packages/block-library/src/list';
import * as more from '../packages/block-library/src/more';
import * as nextpage from '../packages/block-library/src/nextpage';
import * as playlist from '../packages/block-library/src/playlist';
import * as preformatted from '../packages/block-library/src/preformatted';
import * as pullquote from '../packages/block-library/src/pullquote';
import * as reusableBlock from '../packages/block-library/src/block';
Expand Down Expand Up @@ -82,6 +83,7 @@ export const registerCoreBlocks = () => {
latestPosts,
more,
nextpage,
playlist,
preformatted,
pullquote,
separator,
Expand Down
127 changes: 119 additions & 8 deletions edit-post/hooks/components/media-upload/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External Dependencies
*/
import { castArray, pick } from 'lodash';
import { castArray, defaults, pick } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -37,7 +37,7 @@ const getGalleryDetailsMediaFrame = () => {
multiple: 'add',
editable: false,

library: wp.media.query( _.defaults( {
library: wp.media.query( defaults( {
type: 'image',
}, this.options.library ) ),
} ),
Expand All @@ -56,11 +56,103 @@ const getGalleryDetailsMediaFrame = () => {
} );
};

const getPlaylistDetailsMediaFrame = () => {
/**
* Custom Playlist details frame.
*
* @link https://github.com/xwp/wp-core-media-widgets/blob/905edbccfc2a623b73a93dac803c5335519d7837/wp-admin/js/widgets/media-gallery-widget.js
* @class PlaylistDetailsMediaFrame
* @constructor
*/
return wp.media.view.MediaFrame.Post.extend( {

/**
* Create the default states.
*
* @return {void}
*/
createStates: function createStates() {
this.states.add( [
new wp.media.controller.Library( {
id: 'playlist',
title: wp.media.view.l10n.createPlaylistTitle,
priority: 60,
toolbar: 'main-playlist',
filterable: 'uploaded',
multiple: 'add',
editable: false,

library: wp.media.query( defaults( {
type: 'audio',
}, this.options.library ) ),
} ),

new wp.media.controller.CollectionEdit( {
type: 'audio',
collectionType: 'playlist',
title: wp.media.view.l10n.editPlaylistTitle,
library: this.options.selection,
SettingsView: wp.media.view.Settings.Playlist,
editing: this.options.editing,
menu: 'playlist',
dragInfoText: wp.media.view.l10n.playlistDragInfo,
dragInfo: true,
} ),

new wp.media.controller.CollectionAdd( {
type: 'audio',
collectionType: 'playlist',
title: wp.media.view.l10n.addToPlaylistTitle,
} ),

new wp.media.controller.Library( {
id: 'video-playlist',
title: wp.media.view.l10n.createVideoPlaylistTitle,
priority: 60,
toolbar: 'main-video-playlist',
filterable: 'uploaded',
multiple: 'add',
editable: false,

library: wp.media.query( defaults( {
type: 'video',
}, this.options.library ) ),
} ),

new wp.media.controller.CollectionEdit( {
type: 'video',
collectionType: 'playlist',
title: wp.media.view.l10n.editVideoPlaylistTitle,
library: this.options.selection,
editing: this.options.editing,
SettingsView: wp.media.view.Settings.Playlist,
menu: 'video-playlist',
dragInfoText: wp.media.view.l10n.videoPlaylistDragInfo,
dragInfo: false,
} ),

new wp.media.controller.CollectionAdd( {
type: 'video',
collectionType: 'playlist',
title: wp.media.view.l10n.addToVideoPlaylistTitle,
} ),

] );
},
} );
};

// the media library image object contains numerous attributes
// we only need this set to display the image in the library
const slimImageObject = ( img ) => {
const attrSet = [ 'sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption' ];
return pick( img, attrSet );
const attributeSet = [ 'sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption' ];
return pick( img, attributeSet );
};

// the playlist object contains attributes required for render. These will be used for playlist
const slimPlaylistItemObject = ( playlistMedia ) => {
const attributeSet = [ 'sizes', 'mime', 'type', 'subtype', 'id', 'url', 'link', 'caption', 'album', 'artist', 'image', 'title' ];
return pick( playlistMedia, attributeSet );
};

const getAttachmentsCollection = ( ids ) => {
Expand All @@ -75,7 +167,7 @@ const getAttachmentsCollection = ( ids ) => {
};

class MediaUpload extends Component {
constructor( { multiple = false, type, gallery = false, title = __( 'Select or Upload Media' ), modalClass, value } ) {
constructor( { multiple = false, type, gallery = false, playlist = false, title = __( 'Select or Upload Media' ), modalClass, value } ) {
super( ...arguments );
this.openModal = this.openModal.bind( this );
this.onOpen = this.onOpen.bind( this );
Expand Down Expand Up @@ -115,6 +207,24 @@ class MediaUpload extends Component {
this.frame = wp.media( frameConfig );
}

if ( playlist ) {
const PlaylistDetailsMediaFrame = getPlaylistDetailsMediaFrame();
if ( type === 'video' ) {
this.frame = new PlaylistDetailsMediaFrame( {
frame: 'select',
mimeType: 'video',
state: 'video-playlist',
} );
} else {
this.frame = new PlaylistDetailsMediaFrame( {
frame: 'select',
mimeType: 'audio',
state: 'playlist',
} );
}
wp.media.frame = this.frame;
}

if ( modalClass ) {
this.frame.$el.addClass( modalClass );
}
Expand All @@ -131,15 +241,17 @@ class MediaUpload extends Component {
}

onUpdate( selections ) {
const { onSelect, multiple = false } = this.props;
const { onSelect, multiple = false, playlist = false } = this.props;
const state = this.frame.state();
const selectedImages = selections || state.get( 'selection' );

if ( ! selectedImages || ! selectedImages.models.length ) {
return;
}

if ( multiple ) {
if ( playlist ) {
onSelect( selectedImages.models.map( ( model ) => slimPlaylistItemObject( model.toJSON() ) ) );
} else if ( multiple ) {
onSelect( selectedImages.models.map( ( model ) => this.processMediaCaption( slimImageObject( model.toJSON() ) ) ) );
} else {
onSelect( this.processMediaCaption( slimImageObject( ( selectedImages.models[ 0 ].toJSON() ) ) ) );
Expand Down Expand Up @@ -197,4 +309,3 @@ class MediaUpload extends Component {
}

export default MediaUpload;

1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import "./list/editor.scss";
@import "./more/editor.scss";
@import "./nextpage/editor.scss";
@import "./playlist/editor.scss";
@import "./preformatted/editor.scss";
@import "./pullquote/editor.scss";
@import "./quote/editor.scss";
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as latestPosts from './latest-posts';
import * as list from './list';
import * as more from './more';
import * as nextpage from './nextpage';
import * as playlist from './playlist';
import * as preformatted from './preformatted';
import * as pullquote from './pullquote';
import * as reusableBlock from './block';
Expand Down Expand Up @@ -70,6 +71,7 @@ export const registerCoreBlocks = () => {
latestPosts,
more,
nextpage,
playlist,
preformatted,
pullquote,
separator,
Expand Down
Loading