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

MediaReplaceFlow: improve error customization #22995

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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,
Button,
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 @@ -194,4 +197,5 @@ export default compose( [
removeNotice,
};
} ),
withFilters( 'editor.MediaReplaceFlow' ),
] )( MediaReplaceFlow );