-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'enhancement/award-inventory-block' into develop
- Loading branch information
Showing
5 changed files
with
170 additions
and
1 deletion.
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
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,21 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "hrswp/er-award-inventory", | ||
"title": "ER Award Inventory", | ||
"category": "widgets", | ||
"description": "Inventory tracking for a length-of-service award.", | ||
"keywords": [ "text" ], | ||
"textdomain": "default", | ||
"attributes": { | ||
"isQuantityEditable": { | ||
"type": "boolean", | ||
"default": true | ||
} | ||
}, | ||
"supports": { | ||
"html": false, | ||
"inserter": false | ||
}, | ||
"editorScript": "hrswp-employee-recognition" | ||
} |
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,79 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
PanelBody, | ||
ToggleControl, | ||
RangeControl, | ||
} from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { InspectorControls, useBlockProps } from "@wordpress/block-editor"; | ||
import { box, pin } from "@wordpress/icons"; | ||
|
||
function ERAwardMetaInventoryEdit( { attributes, setAttributes } ) { | ||
const { isQuantityEditable } = attributes; | ||
const blockProps = useBlockProps(); | ||
const postType = useSelect( ( select ) => | ||
select( 'core/editor' ).getCurrentPostType(), | ||
[] ); | ||
|
||
const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' ); | ||
const quantityMetaFieldValue = meta.hrswp_er_awards_quantity; | ||
const reserveMetaFieldValue = meta.hrswp_er_awards_reserve; | ||
|
||
const updateQuantityMetaValue = ( newValue ) => { | ||
setMeta( { ...meta, hrswp_er_awards_quantity: Number( newValue ) } ); | ||
}; | ||
const updateReserveMetaValue = ( newValue ) => { | ||
setMeta( { ...meta, hrswp_er_awards_reserve: Number( newValue ) } ); | ||
} | ||
|
||
return ( | ||
<> | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Inventory Management' ) }> | ||
<ToggleControl | ||
label={ __( 'Allow editing inventory' ) } | ||
checked={ !! isQuantityEditable } | ||
onChange={ () => | ||
setAttributes( { | ||
isQuantityEditable: ! isQuantityEditable, | ||
} ) | ||
} | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
<div { ...blockProps }> | ||
<RangeControl | ||
label={ __( 'ER Award Quantity' ) } | ||
help={ __( 'The number of awards in inventory.' ) } | ||
beforeIcon={ box } | ||
value={ quantityMetaFieldValue } | ||
onChange={ updateQuantityMetaValue } | ||
min={ 0 } | ||
max={ 9999 } | ||
step={ 1 } | ||
withInputField={ true } | ||
disabled={ ! isQuantityEditable } | ||
/> | ||
<RangeControl | ||
label={ __( 'ER Award Reserve' ) } | ||
help={ __( 'The inventory amount at which an admin is notified.' ) } | ||
beforeIcon={ pin } | ||
value={ reserveMetaFieldValue } | ||
onChange={ updateReserveMetaValue } | ||
min={ 0 } | ||
max={ 9999 } | ||
step={ 1 } | ||
withInputField={ true } | ||
disabled={ ! isQuantityEditable } | ||
separatorType={ 'topFullWidth' } | ||
/> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default ERAwardMetaInventoryEdit; |
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,19 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { store as icon } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
import metadata from './block.json'; | ||
|
||
const { name } = metadata; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
icon, | ||
edit, | ||
}; |
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