| 1 |
import './editor.scss'; |
| 2 |
import './style.scss'; |
| 3 |
|
| 4 |
let { __ } = wp.i18n; |
| 5 |
let { PluginPostStatusInfo } = wp.editPost; |
| 6 |
let { registerPlugin } = wp.plugins; |
| 7 |
let { withSelect, withDispatch } = wp.data; |
| 8 |
let { compose } = wp.compose; |
| 9 |
let { SelectControl } = wp.components; |
| 10 |
|
| 11 |
/** |
| 12 |
* Map Custom Statuses as options for SelectControl |
| 13 |
*/ |
| 14 |
let statuses = window.EditFlowCustomStatuses.map( s => ({ label: s.name, value: s.slug }) ); |
| 15 |
|
| 16 |
let getStatusLabel = slug => statuses.find( s => s.value === slug ).label; |
| 17 |
|
| 18 |
// Hack :( |
| 19 |
// @see https://github.com/WordPress/gutenberg/issues/3144 |
| 20 |
let sideEffectL10nManipulation = status => { |
| 21 |
let node = document.querySelector('.editor-post-save-draft'); |
| 22 |
if ( node ) { |
| 23 |
document.querySelector('.editor-post-save-draft').innerText = `${__( 'Save' ) } ${status}` |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Custom status component |
| 29 |
* @param object props |
| 30 |
*/ |
| 31 |
let EditFlowCustomPostStati = ( { onUpdate, status } ) => ( |
| 32 |
<PluginPostStatusInfo |
| 33 |
className={ `edit-flow-extended-post-status edit-flow-extended-post-status-${status}` } |
| 34 |
> |
| 35 |
<h4>{ status !== 'publish' ? __( 'Extended Post Status', 'edit-flow' ) : __( 'Extended Post Status Disabled.', 'edit-flow' ) }</h4> |
| 36 |
|
| 37 |
{ status !== 'publish' ? <SelectControl |
| 38 |
label="" |
| 39 |
value={ status } |
| 40 |
options={ statuses } |
| 41 |
onChange={ onUpdate } |
| 42 |
/> : null } |
| 43 |
|
| 44 |
<small className="edit-flow-extended-post-status-note"> |
| 45 |
{ status !== 'publish' ? __( `Note: this will override all status settings above.`, 'edit-flow' ) : __( 'To select a custom status, please unpublish the content first.', 'edit-flow' ) } |
| 46 |
</small> |
| 47 |
</PluginPostStatusInfo> |
| 48 |
); |
| 49 |
|
| 50 |
let plugin = compose( |
| 51 |
withSelect((select) => ({ |
| 52 |
status: select('core/editor').getEditedPostAttribute('status'), |
| 53 |
})), |
| 54 |
withDispatch((dispatch) => ({ |
| 55 |
onUpdate(status) { |
| 56 |
dispatch('core/editor').editPost( { status } ); |
| 57 |
sideEffectL10nManipulation( getStatusLabel( status ) ); |
| 58 |
} |
| 59 |
})) |
| 60 |
)(EditFlowCustomPostStati); |
| 61 |
|
| 62 |
/** |
| 63 |
* Kick it off |
| 64 |
*/ |
| 65 |
registerPlugin( 'edit-flow-custom-status', { |
| 66 |
icon: 'edit-flow', |
| 67 |
render: plugin |
| 68 |
} ); |
| 69 |
|