Skip to content

Commit

Permalink
adds editor wide error notice for upload errors
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Jan 6, 2020
1 parent 8417c49 commit 11adc05
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/block-editor/src/components/media-replace-flow/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useState, createRef } from '@wordpress/element';
import { useState, createRef, renderToString } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';
import {
Expand All @@ -11,7 +11,6 @@ import {
ToolbarGroup,
Button,
Dropdown,
withNotices,
} from '@wordpress/components';
import {
LEFT,
Expand All @@ -21,7 +20,7 @@ import {
BACKSPACE,
ENTER,
} from '@wordpress/keycodes';
import { useSelect } from '@wordpress/data';
import { withDispatch, useSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';

/**
Expand All @@ -38,10 +37,9 @@ const MediaReplaceFlow = (
allowedTypes,
accept,
onSelect,
noticeOperations,
noticeUI,
onSelectURL,
name = __( 'Replace' ),
createNotice,
}
) => {
const [ showURLInput, setShowURLInput ] = useState( false );
Expand All @@ -64,8 +62,11 @@ const MediaReplaceFlow = (
};

const onError = ( message ) => {
noticeOperations.removeAllNotices();
noticeOperations.createErrorNotice( message );
createNotice( 'error', renderToString( message ), {
speak: true,
isDismissible: true,
__unstableHTML: true,
} );
};

const selectMedia = ( media ) => {
Expand Down Expand Up @@ -191,15 +192,17 @@ const MediaReplaceFlow = (
{ showURLInput && <div className="block-editor-media-flow__url-input">
{ urlInputUIContent }
</div> }
{ noticeUI && <div className="block-editor-media-flow__error">
{ noticeUI }
</div> }
</>
) }
/>
);
};

export default compose(
withNotices,
)( MediaReplaceFlow );
export default compose( [
withDispatch( ( dispatch ) => {
const { createNotice } = dispatch( 'core/notices' );
return {
createNotice,
};
} ),
] )( MediaReplaceFlow );

0 comments on commit 11adc05

Please sign in to comment.