Skip to content

Commit

Permalink
Merge pull request #5996 from WordPress/update/rename-reusableBlocks-…
Browse files Browse the repository at this point in the history
…to-sharedBlocks

Code clean-up: Rename 'reusable blocks' to 'shared blocks'
  • Loading branch information
noisysocks authored Apr 5, 2018
2 parents f539288 + ee1b374 commit 0782f09
Show file tree
Hide file tree
Showing 30 changed files with 443 additions and 444 deletions.
2 changes: 1 addition & 1 deletion blocks/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export {
getBlockTypes,
getBlockSupport,
hasBlockSupport,
isReusableBlock,
isSharedBlock,
} from './registration';
export {
isUnmodifiedDefaultBlock,
Expand Down
10 changes: 5 additions & 5 deletions blocks/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ export function hasBlockSupport( nameOrType, feature, defaultSupports ) {
}

/**
* Determines whether or not the given block is a reusable block. This is a
* special block type that is used to point to a global block stored via
* the API.
* Determines whether or not the given block is a shared block. This is a
* special block type that is used to point to a global block stored via the
* API.
*
* @param {Object} blockOrType Block or Block Type to test.
*
* @return {boolean} Whether the given block is a reusable block.
* @return {boolean} Whether the given block is a shared block.
*/
export function isReusableBlock( blockOrType ) {
export function isSharedBlock( blockOrType ) {
return blockOrType.name === 'core/block';
}
10 changes: 5 additions & 5 deletions blocks/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
getBlockTypes,
getBlockSupport,
hasBlockSupport,
isReusableBlock,
isSharedBlock,
} from '../registration';

describe( 'blocks', () => {
Expand Down Expand Up @@ -491,15 +491,15 @@ describe( 'blocks', () => {
} );
} );

describe( 'isReusableBlock', () => {
it( 'should return true for a reusable block', () => {
describe( 'isSharedBlock', () => {
it( 'should return true for a shared block', () => {
const block = { name: 'core/block' };
expect( isReusableBlock( block ) ).toBe( true );
expect( isSharedBlock( block ) ).toBe( true );
} );

it( 'should return false for other blocks', () => {
const block = { name: 'core/paragraph' };
expect( isReusableBlock( block ) ).toBe( false );
expect( isSharedBlock( block ) ).toBe( false );
} );
} );
} );
18 changes: 9 additions & 9 deletions blocks/library/block/edit-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import './style.scss';
*/
const { ESCAPE } = keycodes;

class ReusableBlockEditPanel extends Component {
class SharedBlockEditPanel extends Component {
constructor() {
super( ...arguments );

Expand Down Expand Up @@ -58,22 +58,22 @@ class ReusableBlockEditPanel extends Component {
return (
<Fragment>
{ ( ! isEditing && ! isSaving ) && (
<div className="reusable-block-edit-panel">
<b className="reusable-block-edit-panel__info">
<div className="shared-block-edit-panel">
<b className="shared-block-edit-panel__info">
{ title }
</b>
<Button isLarge className="reusable-block-edit-panel__button" onClick={ onEdit }>
<Button isLarge className="shared-block-edit-panel__button" onClick={ onEdit }>
{ __( 'Edit' ) }
</Button>
</div>
) }
{ ( isEditing || isSaving ) && (
<form className="reusable-block-edit-panel" onSubmit={ this.handleFormSubmit }>
<form className="shared-block-edit-panel" onSubmit={ this.handleFormSubmit }>
<input
ref={ this.bindTitleRef }
type="text"
disabled={ isSaving }
className="reusable-block-edit-panel__title"
className="shared-block-edit-panel__title"
value={ title }
onChange={ this.handleTitleChange }
onKeyDown={ this.handleTitleKeyDown }
Expand All @@ -84,15 +84,15 @@ class ReusableBlockEditPanel extends Component {
isLarge
isBusy={ isSaving }
disabled={ ! title || isSaving }
className="reusable-block-edit-panel__button"
className="shared-block-edit-panel__button"
onClick={ onSave }
>
{ __( 'Save' ) }
</Button>
<Button
isLarge
disabled={ isSaving }
className="reusable-block-edit-panel__button"
className="shared-block-edit-panel__button"
onClick={ onCancel }
>
{ __( 'Cancel' ) }
Expand All @@ -104,4 +104,4 @@ class ReusableBlockEditPanel extends Component {
}
}

export default ReusableBlockEditPanel;
export default SharedBlockEditPanel;
10 changes: 5 additions & 5 deletions blocks/library/block/edit-panel/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.reusable-block-edit-panel {
.shared-block-edit-panel {
align-items: center;
background: $light-gray-100;
color: $dark-gray-500;
Expand All @@ -11,15 +11,15 @@
position: relative;
top: $block-padding;

.reusable-block-edit-panel__spinner {
.shared-block-edit-panel__spinner {
margin: 0 5px;
}

.reusable-block-edit-panel__info {
.shared-block-edit-panel__info {
margin-right: auto;
}

.reusable-block-edit-panel__title {
.shared-block-edit-panel__title {
flex-grow: 1;
font-size: 14px;
height: 30px;
Expand All @@ -28,7 +28,7 @@
}

// Needs specificity to override the margin-bottom set by .button
.wp-core-ui & .reusable-block-edit-panel__button {
.wp-core-ui & .shared-block-edit-panel__button {
margin: 0 0 0 5px;
}
}
70 changes: 35 additions & 35 deletions blocks/library/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import BlockEdit from '../../block-edit';
import ReusableBlockEditPanel from './edit-panel';
import ReusableBlockIndicator from './indicator';
import SharedBlockEditPanel from './edit-panel';
import SharedBlockIndicator from './indicator';

class ReusableBlockEdit extends Component {
constructor( { reusableBlock } ) {
class SharedBlockEdit extends Component {
constructor( { sharedBlock } ) {
super( ...arguments );

this.startEditing = this.startEditing.bind( this );
Expand All @@ -29,24 +29,24 @@ class ReusableBlockEdit extends Component {
this.save = this.save.bind( this );

this.state = {
isEditing: !! ( reusableBlock && reusableBlock.isTemporary ),
isEditing: !! ( sharedBlock && sharedBlock.isTemporary ),
title: null,
changedAttributes: null,
};
}

componentDidMount() {
if ( ! this.props.reusableBlock ) {
this.props.fetchReusableBlock();
if ( ! this.props.sharedBlock ) {
this.props.fetchSharedBlock();
}
}

startEditing() {
const { reusableBlock } = this.props;
const { sharedBlock } = this.props;

this.setState( {
isEditing: true,
title: reusableBlock.title,
title: sharedBlock.title,
changedAttributes: {},
} );
}
Expand All @@ -72,10 +72,10 @@ class ReusableBlockEdit extends Component {
}

save() {
const { reusableBlock, onUpdateTitle, updateAttributes, block, onSave } = this.props;
const { sharedBlock, onUpdateTitle, updateAttributes, block, onSave } = this.props;
const { title, changedAttributes } = this.state;

if ( title !== reusableBlock.title ) {
if ( title !== sharedBlock.title ) {
onUpdateTitle( title );
}

Expand All @@ -86,14 +86,14 @@ class ReusableBlockEdit extends Component {
}

render() {
const { isSelected, reusableBlock, block, isFetching, isSaving } = this.props;
const { isSelected, sharedBlock, block, isFetching, isSaving } = this.props;
const { isEditing, title, changedAttributes } = this.state;

if ( ! reusableBlock && isFetching ) {
if ( ! sharedBlock && isFetching ) {
return <Placeholder><Spinner /></Placeholder>;
}

if ( ! reusableBlock || ! block ) {
if ( ! sharedBlock || ! block ) {
return <Placeholder>{ __( 'Block has been deleted or is unavailable.' ) }</Placeholder>;
}

Expand All @@ -116,57 +116,57 @@ class ReusableBlockEdit extends Component {
<Fragment>
{ element }
{ ( isSelected || isEditing ) && (
<ReusableBlockEditPanel
<SharedBlockEditPanel
isEditing={ isEditing }
title={ title !== null ? title : reusableBlock.title }
isSaving={ isSaving && ! reusableBlock.isTemporary }
title={ title !== null ? title : sharedBlock.title }
isSaving={ isSaving && ! sharedBlock.isTemporary }
onEdit={ this.startEditing }
onChangeTitle={ this.setTitle }
onSave={ this.save }
onCancel={ this.stopEditing }
/>
) }
{ ! isSelected && ! isEditing && <ReusableBlockIndicator title={ reusableBlock.title } /> }
{ ! isSelected && ! isEditing && <SharedBlockIndicator title={ sharedBlock.title } /> }
</Fragment>
);
}
}

const EnhancedReusableBlockEdit = compose( [
const EnhancedSharedBlockEdit = compose( [
withSelect( ( select, ownProps ) => {
const {
getReusableBlock,
isFetchingReusableBlock,
isSavingReusableBlock,
getSharedBlock,
isFetchingSharedBlock,
isSavingSharedBlock,
getBlock,
} = select( 'core/editor' );
const { ref } = ownProps.attributes;
const reusableBlock = getReusableBlock( ref );
const sharedBlock = getSharedBlock( ref );

return {
reusableBlock,
isFetching: isFetchingReusableBlock( ref ),
isSaving: isSavingReusableBlock( ref ),
block: reusableBlock ? getBlock( reusableBlock.uid ) : null,
sharedBlock,
isFetching: isFetchingSharedBlock( ref ),
isSaving: isSavingSharedBlock( ref ),
block: sharedBlock ? getBlock( sharedBlock.uid ) : null,
};
} ),
withDispatch( ( dispatch, ownProps ) => {
const {
fetchReusableBlocks,
fetchSharedBlocks,
updateBlockAttributes,
updateReusableBlockTitle,
saveReusableBlock,
updateSharedBlockTitle,
saveSharedBlock,
} = dispatch( 'core/editor' );
const { ref } = ownProps.attributes;

return {
fetchReusableBlock: partial( fetchReusableBlocks, ref ),
fetchSharedBlock: partial( fetchSharedBlocks, ref ),
updateAttributes: updateBlockAttributes,
onUpdateTitle: partial( updateReusableBlockTitle, ref ),
onSave: partial( saveReusableBlock, ref ),
onUpdateTitle: partial( updateSharedBlockTitle, ref ),
onSave: partial( saveSharedBlock, ref ),
};
} ),
] )( ReusableBlockEdit );
] )( SharedBlockEdit );

export const name = 'core/block';

Expand All @@ -186,6 +186,6 @@ export const settings = {
html: false,
},

edit: EnhancedReusableBlockEdit,
edit: EnhancedSharedBlockEdit,
save: () => null,
};
10 changes: 5 additions & 5 deletions blocks/library/block/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
*
* @return string Rendered HTML of the referenced block.
*/
function gutenberg_render_block_core_reusable_block( $attributes ) {
function render_block_core_block( $attributes ) {
if ( empty( $attributes['ref'] ) ) {
return '';
}

$reusable_block = get_post( $attributes['ref'] );
if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) {
$shared_block = get_post( $attributes['ref'] );
if ( ! $shared_block || 'wp_block' !== $shared_block->post_type ) {
return '';
}

$blocks = gutenberg_parse_blocks( $reusable_block->post_content );
$blocks = gutenberg_parse_blocks( $shared_block->post_content );

$block = array_shift( $blocks );
if ( ! $block ) {
Expand All @@ -39,5 +39,5 @@ function gutenberg_render_block_core_reusable_block( $attributes ) {
),
),

'render_callback' => 'gutenberg_render_block_core_reusable_block',
'render_callback' => 'render_block_core_block',
) );
6 changes: 3 additions & 3 deletions blocks/library/block/indicator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { __, sprintf } from '@wordpress/i18n';
*/
import './style.scss';

function ReusableBlockIndicator( { title } ) {
function SharedBlockIndicator( { title } ) {
return (
<Tooltip text={ sprintf( __( 'Shared Block: %s' ), title ) }>
<span className="reusable-block-indicator">
<span className="shared-block-indicator">
<Dashicon icon="controls-repeat" />
</span>
</Tooltip>
);
}

export default ReusableBlockIndicator;
export default SharedBlockIndicator;
2 changes: 1 addition & 1 deletion blocks/library/block/indicator/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.reusable-block-indicator {
.shared-block-indicator {
background: $white;
border-left: 1px dashed $light-gray-500;
color: $dark-gray-500;
Expand Down
4 changes: 2 additions & 2 deletions blocks/library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as list from './list';
import * as more from './more';
import * as preformatted from './preformatted';
import * as pullquote from './pullquote';
import * as reusableBlock from './block';
import * as sharedBlock from './block';
import * as separator from './separator';
import * as shortcode from './shortcode';
import * as subhead from './subhead';
Expand Down Expand Up @@ -62,8 +62,8 @@ export const registerCoreBlocks = () => {
more,
preformatted,
pullquote,
reusableBlock,
separator,
sharedBlock,
subhead,
table,
textColumns,
Expand Down
2 changes: 1 addition & 1 deletion edit-post/assets/stylesheets/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $z-layers: (

// Should have higher index than the inset/underlay used for dragging
'.components-placeholder__fieldset': 1,
'.editor-block-list__block-edit .reusable-block-edit-panel *': 1,
'.editor-block-list__block-edit .shared-block-edit-panel *': 1,

// Show drop zone above most standard content, but below any overlays
'.components-drop-zone': 100,
Expand Down
Loading

0 comments on commit 0782f09

Please sign in to comment.