Skip to content

Commit

Permalink
MediaReplaceFlow: improve error customization (#22995)
Browse files Browse the repository at this point in the history
* media-replace-flow: add filter

* media-replace-placeholder: add onFilesUpload prop

* media-replace-flow: doc improvement
  • Loading branch information
retrofox authored Jun 10, 2020
1 parent 2e814da commit 4e0a8e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Comma delimited list of MIME types accepted for upload.
- Type: `string`
- Required: Yes

### onFilesUpload

Callback called before to start to upload the files. It receives an array with the files to upload before to the final process.

### onSelect

Callback used when media is replaced from the Media Library or when a new media is uploaded. It is called with one argument `media` which is an object with all the media details.
Expand Down Expand Up @@ -71,4 +75,4 @@ Creates a media replace notice.
Removes a media replace notice.

- Type: `func`
- Required: No
- Required: No
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { uniqueId } from 'lodash';
import { uniqueId, noop } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -16,6 +16,7 @@ import {
ToolbarGroup,
ToolbarButton,
Dropdown,
withFilters,
} from '@wordpress/components';
import { withDispatch, useSelect } from '@wordpress/data';
import { DOWN } from '@wordpress/keycodes';
Expand All @@ -36,6 +37,7 @@ const MediaReplaceFlow = ( {
accept,
onSelect,
onSelectURL,
onFilesUpload = noop,
name = __( 'Replace' ),
createNotice,
removeNotice,
Expand Down Expand Up @@ -86,6 +88,7 @@ const MediaReplaceFlow = ( {

const uploadFiles = ( event ) => {
const files = event.target.files;
onFilesUpload( files );
const setMedia = ( [ media ] ) => {
selectMedia( media );
};
Expand Down Expand Up @@ -199,4 +202,5 @@ export default compose( [
removeNotice,
};
} ),
withFilters( 'editor.MediaReplaceFlow' ),
] )( MediaReplaceFlow );

0 comments on commit 4e0a8e7

Please sign in to comment.