Skip to content

Commit

Permalink
Replace all occurrences of templateLock prop with getLocking.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed May 29, 2018
1 parent 816f43c commit 4487774
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 41 deletions.
7 changes: 3 additions & 4 deletions editor/components/block-drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ export default compose(
},
};
} ),
withSelect( ( select ) => {
const { templateLock } = select( 'core/editor' ).getEditorSettings();

withSelect( ( select, { rootUID } ) => {
const { getLocking } = select( 'core/editor' );
return {
isLocked: !! templateLock,
isLocked: !! getLocking( rootUID ),
};
} )
)( BlockDropZone );
5 changes: 3 additions & 2 deletions editor/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,10 @@ const applyWithSelect = withSelect( ( select, { uid, rootUID } ) => {
isSelectionEnabled,
getSelectedBlocksInitialCaretPosition,
getEditorSettings,
getLocking,
} = select( 'core/editor' );
const isSelected = isBlockSelected( uid );
const { templateLock, hasFixedToolbar } = getEditorSettings();
const { hasFixedToolbar } = getEditorSettings();
const block = getBlock( uid );
const previousBlockUid = getPreviousBlockUid( uid );
const previousBlock = getBlock( previousBlockUid );
Expand All @@ -642,7 +643,7 @@ const applyWithSelect = withSelect( ( select, { uid, rootUID } ) => {
initialPosition: getSelectedBlocksInitialCaretPosition(),
isEmptyDefaultBlock: block && isUnmodifiedDefaultBlock( block ),
isPreviousBlockADefaultEmptyBlock: previousBlock && isUnmodifiedDefaultBlock( previousBlock ),
isLocked: !! templateLock,
isLocked: !! getLocking( rootUID ),
previousBlockUid,
block,
isSelected,
Expand Down
6 changes: 3 additions & 3 deletions editor/components/block-list/insertion-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default compose(
getBlock,
isBlockInsertionPointVisible,
isTyping,
getEditorSettings,
getLocking,
} = select( 'core/editor' );
const blockIndex = uid ? getBlockIndex( uid, rootUID ) : -1;
const insertIndex = blockIndex;
Expand All @@ -92,13 +92,13 @@ export default compose(
);

return {
templateLock: getEditorSettings().templateLock,
locking: getLocking( insertionPoint.rootUID ),
showInserter: ! isTyping() && canShowInserter,
index: insertIndex,
showInsertionPoint,
};
} ),
ifCondition( ( { templateLock } ) => ! templateLock ),
ifCondition( ( { locking } ) => ! locking ),
withDispatch( ( dispatch ) => {
const { insertDefaultBlock, startTyping } = dispatch( 'core/editor' );
return {
Expand Down
5 changes: 2 additions & 3 deletions editor/components/block-mover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ export class BlockMover extends Component {

export default compose(
withSelect( ( select, { uids, rootUID } ) => {
const { getBlock, getBlockIndex, getEditorSettings } = select( 'core/editor' );
const { getBlock, getBlockIndex, getLocking } = select( 'core/editor' );
const firstUID = first( castArray( uids ) );
const block = getBlock( firstUID );
const { templateLock } = getEditorSettings();

return {
firstIndex: getBlockIndex( firstUID, rootUID ),
blockType: block ? getBlockType( block.name ) : null,
isLocked: templateLock === 'all',
isLocked: getLocking( rootUID ) === 'all',
};
} ),
withDispatch( ( dispatch, { uids, rootUID } ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ export function BlockDuplicateButton( { blocks, onDuplicate, onClick = noop, isL

export default compose(
withSelect( ( select, { uids, rootUID } ) => {
const { getBlocksByUID, getBlockIndex, getEditorSettings } = select( 'core/editor' );
const { templateLock } = getEditorSettings();
const { getBlocksByUID, getBlockIndex, getLocking } = select( 'core/editor' );
return {
blocks: getBlocksByUID( uids ),
index: getBlockIndex( last( castArray( uids ) ), rootUID ),
isLocked: !! templateLock,
isLocked: !! getLocking( rootUID ),
};
} ),
withDispatch( ( dispatch, { blocks, index, rootUID } ) => ( {
Expand Down
11 changes: 6 additions & 5 deletions editor/components/block-settings-menu/block-remove-button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { flow, noop } from 'lodash';
import { castArray, flow, noop, some } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -36,11 +36,12 @@ export default compose(
dispatch( 'core/editor' ).removeBlocks( uids );
},
} ) ),
withSelect( ( select ) => {
const { templateLock } = select( 'core/editor' ).getEditorSettings();

withSelect( ( select, { uids } ) => {
const { getBlockRootUID, getLocking } = select( 'core/editor' );
return {
isLocked: !! templateLock,
isLocked: some( castArray( uids ), ( uid ) => {
return !! getLocking( getBlockRootUID( uid ) );
} ),
};
} ),
)( BlockRemoveButton );
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { noop } from 'lodash';
import { noop, some } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -52,10 +52,9 @@ function BlockTransformations( { blocks, small = false, onTransform, onClick = n
}
export default compose( [
withSelect( ( select, { uids } ) => {
const { getEditorSettings, getBlocksByUID } = select( 'core/editor' );
const { templateLock } = getEditorSettings();
const { getBlockRootUID, getBlocksByUID, getLocking } = select( 'core/editor' );
return {
isLocked: !! templateLock,
isLocked: some( uids, ( uid ) => !! getLocking( getBlockRootUID( uid ) ) ),
blocks: getBlocksByUID( uids ),
};
} ),
Expand Down
10 changes: 7 additions & 3 deletions editor/components/block-switcher/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { castArray, some } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -98,11 +103,10 @@ export function BlockSwitcher( { blocks, onTransform, isLocked } ) {

export default compose(
withSelect( ( select, ownProps ) => {
const { getBlock, getEditorSettings } = select( 'core/editor' );
const { templateLock } = getEditorSettings();
const { getBlock, getBlockRootUID, getLocking } = select( 'core/editor' );
return {
blocks: ownProps.uids.map( getBlock ),
isLocked: !! templateLock,
isLocked: some( castArray( ownProps.uids ), ( uid ) => !! getLocking( getBlockRootUID( uid ) ) ),
};
} ),
withDispatch( ( dispatch, ownProps ) => ( {
Expand Down
5 changes: 3 additions & 2 deletions editor/components/default-block-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ export default compose(
getBlockCount,
getBlock,
getEditorSettings,
getLocking,
} = select( 'core/editor' );
const isEmpty = ! getBlockCount( ownProps.rootUID );
const lastBlock = getBlock( ownProps.lastBlockUID );
const isLastBlockDefault = get( lastBlock, [ 'name' ] ) === getDefaultBlockName();
const { templateLock, bodyPlaceholder } = getEditorSettings();
const { bodyPlaceholder } = getEditorSettings();

return {
isVisible: isEmpty || ! isLastBlockDefault,
showPrompt: isEmpty,
isLocked: !! templateLock,
isLocked: !! getLocking( ownProps.rootUID ),
placeholder: bodyPlaceholder,
};
} ),
Expand Down
12 changes: 6 additions & 6 deletions editor/components/editor-global-keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { first, last } from 'lodash';
import { first, last, some } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -98,15 +98,15 @@ export default compose( [
getBlockOrder,
getMultiSelectedBlockUids,
hasMultiSelection,
getEditorSettings,
getBlockRootUID,
getLocking,
} = select( 'core/editor' );
const { templateLock } = getEditorSettings();

const multiSelectedBlockUids = getMultiSelectedBlockUids();
return {
uids: getBlockOrder(),
multiSelectedBlockUids: getMultiSelectedBlockUids(),
multiSelectedBlockUids,
hasMultiSelection: hasMultiSelection(),
isLocked: !! templateLock,
isLocked: some( multiSelectedBlockUids, ( uid ) => !! getLocking( getBlockRootUID( uid ) ) ),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
5 changes: 2 additions & 3 deletions editor/components/inserter-with-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ function InserterWithShortcuts( { items, isLocked, onInsert } ) {

export default compose(
withSelect( ( select, { rootUID } ) => {
const { getEditorSettings, getInserterItems } = select( 'core/editor' );
const { templateLock } = getEditorSettings();
const { getInserterItems, getLocking } = select( 'core/editor' );
return {
items: getInserterItems( rootUID ),
isLocked: !! templateLock,
isLocked: !! getLocking( rootUID ),
};
} ),
withDispatch( ( dispatch, ownProps ) => {
Expand Down
6 changes: 3 additions & 3 deletions editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1230,15 +1230,15 @@ export const canInsertBlockType = createSelector(
return false;
}

const { allowedBlockTypes, templateLock } = getEditorSettings( state );
const { allowedBlockTypes } = getEditorSettings( state );

const isBlockAllowedInEditor = checkAllowList( allowedBlockTypes, blockName, true );
if ( ! isBlockAllowedInEditor ) {
return false;
}

const isEditorLocked = !! templateLock;
if ( isEditorLocked ) {
const isLocked = !! getLocking( state, parentUID );
if ( isLocked ) {
return false;
}

Expand Down

0 comments on commit 4487774

Please sign in to comment.