Skip to content

Commit

Permalink
Gutenberg: Add WP.com shortlinks extension (#29475)
Browse files Browse the repository at this point in the history
* Gutenberg: Add WP.com shortlinks

* Drop prettier pragmas
  • Loading branch information
tyxla authored Dec 18, 2018
1 parent d7f8f75 commit 9df0718
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/gutenberg/extensions/presets/jetpack/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"beta": [
"related-posts",
"shortlinks",
"subscriptions",
"tiled-gallery",
"vr"
Expand Down
7 changes: 7 additions & 0 deletions client/gutenberg/extensions/shortlinks/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Internal dependencies
*/
import { name, settings } from '.';
import registerJetpackPlugin from 'gutenberg/extensions/presets/jetpack/utils/register-jetpack-plugin';

registerJetpackPlugin( name, settings );
15 changes: 15 additions & 0 deletions client/gutenberg/extensions/shortlinks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Internal dependencies
*/
import JetpackPluginSidebar from 'gutenberg/extensions/presets/jetpack/editor-shared/jetpack-plugin-sidebar';
import ShortlinksPanel from './panel';

export const name = 'shortlinks';

export const settings = {
render: () => (
<JetpackPluginSidebar>
<ShortlinksPanel />
</JetpackPluginSidebar>
),
};
37 changes: 37 additions & 0 deletions client/gutenberg/extensions/shortlinks/panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* External dependencies
*/
import { Component } from '@wordpress/element';
import { get } from 'lodash';
import { PanelBody, TextControl } from '@wordpress/components';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { __ } from 'gutenberg/extensions/presets/jetpack/utils/i18n';

class ShortlinksPanel extends Component {
onFocus = event => event.target.select();

render() {
const { shortlink } = this.props;

if ( ! shortlink ) {
return null;
}

return (
<PanelBody title={ __( 'Shortlink' ) }>
<TextControl readOnly onFocus={ this.onFocus } value={ shortlink } />
</PanelBody>
);
}
}

export default withSelect( select => {
const currentPost = select( 'core/editor' ).getCurrentPost();
return {
shortlink: get( currentPost, 'jetpack_shortlink', '' ),
};
} )( ShortlinksPanel );

0 comments on commit 9df0718

Please sign in to comment.