-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix max upload size error message #4203
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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={ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems nicer! Wondering if it could make it clear things up even more if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related with #4203 (comment) although we pass a noticeUI I wanted it to be a totally optional prop and allow components to ignore it if they just want the notices without relying on the default UI we provide. |
||
this.state.noticeList.length > 0 && <NoticeList | ||
className="components-with-notices-ui" | ||
notices={ this.state.noticeList } | ||
onRemove={ this.removeNotice } | ||
/> | ||
} | ||
{ ...this.props } | ||
/> | ||
); | ||
} | ||
}; | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that still need to be passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not being used, but passing it allows a user of the HOC to create a different UI and not rely on the provided noticeUI.