2020-06-05 14:36:07 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Icon, external } from '@woocommerce/icons';
|
|
|
|
import { ADMIN_URL } from '@woocommerce/settings';
|
|
|
|
import { InspectorControls } from '@wordpress/block-editor';
|
2020-06-11 09:02:00 +00:00
|
|
|
import { useProductDataContext } from '@woocommerce/shared-context';
|
2020-06-05 14:36:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to render an edit product link in the sidebar.
|
2020-06-11 09:02:00 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Component props.
|
2020-06-05 14:36:07 +00:00
|
|
|
*/
|
2020-06-11 09:02:00 +00:00
|
|
|
const EditProductLink = ( props ) => {
|
|
|
|
const productDataContext = useProductDataContext();
|
|
|
|
const product = productDataContext.product || {};
|
|
|
|
const productId = product.id || props.productId || 0;
|
|
|
|
|
|
|
|
if ( ! productId ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-06-05 14:36:07 +00:00
|
|
|
return (
|
|
|
|
<InspectorControls>
|
|
|
|
<div className="wc-block-single-product__edit-card">
|
|
|
|
<div className="wc-block-single-product__edit-card-title">
|
|
|
|
<a
|
|
|
|
href={ `${ ADMIN_URL }post.php?post=${ productId }&action=edit` }
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
"Edit this product's details",
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
<Icon srcElement={ external } size={ 16 } />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div className="wc-block-single-product__edit-card-description">
|
|
|
|
{ __(
|
|
|
|
'Edit details such as title, price, description and more.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</InspectorControls>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EditProductLink;
|