Skip to content

Commit

Permalink
Update: Avoid usage of editor store on block editor reusable blocks i…
Browse files Browse the repository at this point in the history
…nserter (#18784)
  • Loading branch information
jorgefilipecosta authored Nov 28, 2019
1 parent 5d8dda0 commit c97ccf0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ export class InserterMenu extends Component {
}

componentDidMount() {
// This could be replaced by a resolver.
this.props.fetchReusableBlocks();
if ( this.props.fetchReusableBlocks ) {
this.props.fetchReusableBlocks();
}
this.filter();
}

Expand Down Expand Up @@ -476,11 +477,17 @@ export default compose(
}
const destinationRootBlockName = getBlockName( destinationRootClientId );

const {
showInserterHelpPanel: showInserterHelpPanelSetting,
__experimentalFetchReusableBlocks: fetchReusableBlocks,
} = getSettings();

return {
rootChildBlocks: getChildBlockNames( destinationRootBlockName ),
items: getInserterItems( destinationRootClientId ),
showInserterHelpPanel: showInserterHelpPanel && getSettings().showInserterHelpPanel,
showInserterHelpPanel: showInserterHelpPanel && showInserterHelpPanelSetting,
destinationRootClientId,
fetchReusableBlocks,
};
} ),
withDispatch( ( dispatch, ownProps, { select } ) => {
Expand All @@ -489,11 +496,6 @@ export default compose(
hideInsertionPoint,
} = dispatch( 'core/block-editor' );

// This should be an external action provided in the editor settings.
const {
__experimentalFetchReusableBlocks: fetchReusableBlocks,
} = dispatch( 'core/editor' );

// To avoid duplication, getInsertionIndex is extracted and used in two event handlers
// This breaks the withDispatch not containing any logic rule.
// Since it's a function only called when the event handlers are called,
Expand Down Expand Up @@ -523,7 +525,6 @@ export default compose(
}

return {
fetchReusableBlocks,
showInsertionPoint() {
const index = getInsertionIndex();
showInsertionPoint( ownProps.destinationRootClientId, index );
Expand Down
6 changes: 6 additions & 0 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class EditorProvider extends Component {
getBlockEditorSettings(
settings,
reusableBlocks,
__experimentalFetchReusableBlocks,
hasUploadPermissions,
canUserUseUnfilteredHTML
) {
Expand Down Expand Up @@ -111,6 +112,7 @@ class EditorProvider extends Component {
] ),
mediaUpload: hasUploadPermissions ? mediaUpload : undefined,
__experimentalReusableBlocks: reusableBlocks,
__experimentalFetchReusableBlocks,
__experimentalFetchLinkSuggestions: fetchLinkSuggestions,
__experimentalCanUserUseUnfilteredHTML: canUserUseUnfilteredHTML,
};
Expand Down Expand Up @@ -158,6 +160,7 @@ class EditorProvider extends Component {
reusableBlocks,
resetEditorBlocksWithoutUndoLevel,
hasUploadPermissions,
__experimentalFetchReusableBlocks,
} = this.props;

if ( ! isReady ) {
Expand All @@ -167,6 +170,7 @@ class EditorProvider extends Component {
const editorSettings = this.getBlockEditorSettings(
settings,
reusableBlocks,
__experimentalFetchReusableBlocks,
hasUploadPermissions,
canUserUseUnfilteredHTML,
);
Expand Down Expand Up @@ -222,6 +226,7 @@ export default compose( [
updatePostLock,
resetEditorBlocks,
updateEditorSettings,
__experimentalFetchReusableBlocks,
__experimentalTearDownEditor,
} = dispatch( 'core/editor' );
const { createWarningNotice } = dispatch( 'core/notices' );
Expand All @@ -239,6 +244,7 @@ export default compose( [
} );
},
tearDownEditor: __experimentalTearDownEditor,
__experimentalFetchReusableBlocks,
};
} ),
] )( EditorProvider );

0 comments on commit c97ccf0

Please sign in to comment.