-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add max upload size error message (#4203)
Add a onError handler to media handler. Used the handler to validate max file size and general upload problems. Passed max upload size from in client assets to allow max file size validation. Added the ability for blocks to display error notices.
- Loading branch information
1 parent
cd5779d
commit deabbc3
Showing
13 changed files
with
293 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import uuid from 'uuid/v4'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component, createHigherOrderComponent } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NoticeList from '../../notice/list'; | ||
|
||
/** | ||
* Override the default edit UI to include notices if supported. | ||
* | ||
* @param {function|Component} OriginalComponent Original component. | ||
* @return {Component} Wrapped component. | ||
*/ | ||
export default createHigherOrderComponent( ( OriginalComponent ) => { | ||
return class WrappedBlockEdit extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.createNotice = this.createNotice.bind( this ); | ||
this.createErrorNotice = this.createErrorNotice.bind( this ); | ||
this.removeNotice = this.removeNotice.bind( this ); | ||
this.removeAllNotices = this.removeAllNotices.bind( this ); | ||
|
||
this.state = { | ||
noticeList: [], | ||
}; | ||
|
||
this.noticeOperations = { | ||
createNotice: this.createNotice, | ||
createErrorNotice: this.createErrorNotice, | ||
removeAllNotices: this.removeAllNotices, | ||
removeNotice: this.removeNotice, | ||
}; | ||
} | ||
|
||
/** | ||
* Function passed down as a prop that adds a new notice. | ||
* | ||
* @param {Object} notice Notice to add. | ||
*/ | ||
createNotice( notice ) { | ||
const noticeToAdd = notice.id ? notice : { ...notice, id: uuid() }; | ||
this.setState( ( state ) => ( { | ||
noticeList: [ ...state.noticeList, noticeToAdd ], | ||
} ) ); | ||
} | ||
|
||
/** | ||
* Function passed as a prop that adds a new error notice. | ||
* | ||
* @param {string} msg Error message of the notice. | ||
*/ | ||
createErrorNotice( msg ) { | ||
this.createNotice( { status: 'error', content: msg } ); | ||
} | ||
|
||
/** | ||
* Removes a notice by id. | ||
* | ||
* @param {string} id Id of the notice to remove. | ||
*/ | ||
removeNotice( id ) { | ||
this.setState( ( state ) => ( { | ||
noticeList: state.noticeList.filter( ( notice ) => notice.id !== id ), | ||
} ) ); | ||
} | ||
|
||
/** | ||
* Removes all notices | ||
*/ | ||
removeAllNotices() { | ||
this.setState( { | ||
noticeList: [], | ||
} ); | ||
} | ||
|
||
render() { | ||
return ( | ||
<OriginalComponent | ||
noticeList={ this.state.noticeList } | ||
noticeOperations={ this.noticeOperations } | ||
noticeUI={ | ||
this.state.noticeList.length > 0 && <NoticeList | ||
className="components-with-notices-ui" | ||
notices={ this.state.noticeList } | ||
onRemove={ this.removeNotice } | ||
/> | ||
} | ||
{ ...this.props } | ||
/> | ||
); | ||
} | ||
}; | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.