Skip to content

Commit

Permalink
Replace "core/block-directory" store name string with exposed store d…
Browse files Browse the repository at this point in the history
…efinition (#27178)

* Replace store name string with store definition

* Triggering build
  • Loading branch information
rafaelgallani authored Nov 24, 2020
1 parent df2e65b commit 3067e91
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import { unregisterBlockType } from '@wordpress/blocks';
import { useDispatch, useSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';

/**
* Internal dependencies
*/
import { store as blockDirectoryStore } from '../../store';

export default function AutoBlockUninstaller() {
const { uninstallBlockType } = useDispatch( 'core/block-directory' );
const { uninstallBlockType } = useDispatch( blockDirectoryStore );

const shouldRemoveBlockTypes = useSelect( ( select ) => {
const { isAutosavingPost, isSavingPost } = select( 'core/editor' );
return isSavingPost() && ! isAutosavingPost();
}, [] );

const unusedBlockTypes = useSelect(
( select ) => select( 'core/block-directory' ).getUnusedBlockTypes(),
( select ) => select( blockDirectoryStore ).getUnusedBlockTypes(),
[]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import DownloadableBlockAuthorInfo from '../downloadable-block-author-info';
import DownloadableBlockHeader from '../downloadable-block-header';
import DownloadableBlockInfo from '../downloadable-block-info';
import DownloadableBlockNotice from '../downloadable-block-notice';
import { store as blockDirectoryStore } from '../../store';

export default function DownloadableBlockListItem( { item, onClick } ) {
const { isLoading, isInstallable } = useSelect(
( select ) => {
const { isInstalling, getErrorNoticeForBlock } = select(
'core/block-directory'
blockDirectoryStore
);
const notice = getErrorNoticeForBlock( item.id );
const hasFatal = notice && notice.isFatal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import { __ } from '@wordpress/i18n';
import { Button, Notice } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockDirectoryStore } from '../../store';

export const DownloadableBlockNotice = ( { block, onClick } ) => {
const errorNotice = useSelect(
( select ) =>
select( 'core/block-directory' ).getErrorNoticeForBlock( block.id ),
select( blockDirectoryStore ).getErrorNoticeForBlock( block.id ),
[ block ]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { useDispatch } from '@wordpress/data';
* Internal dependencies
*/
import DownloadableBlockListItem from '../downloadable-block-list-item';
import { store as blockDirectoryStore } from '../../store';

function DownloadableBlocksList( { items, onHover = noop, onSelect } ) {
const { installBlockType } = useDispatch( 'core/block-directory' );
const { installBlockType } = useDispatch( blockDirectoryStore );
const { setIsInserterOpened } = useDispatch( 'core/edit-post' );

if ( ! items.length ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { speak } from '@wordpress/a11y';
* Internal dependencies
*/
import DownloadableBlocksList from '../downloadable-blocks-list';
import { store as blockDirectoryStore } from '../../store';

function DownloadableBlocksPanel( {
downloadableItems,
Expand Down Expand Up @@ -80,7 +81,7 @@ export default compose( [
const {
getDownloadableBlocks,
isRequestingDownloadableBlocks,
} = select( 'core/block-directory' );
} = select( blockDirectoryStore );

const hasPermission = select( 'core' ).canUser(
'read',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import { Warning } from '@wordpress/block-editor';
* Internal dependencies
*/
import InstallButton from './install-button';
import { store as blockDirectoryStore } from '../../store';

const getInstallMissing = ( OriginalComponent ) => ( props ) => {
const { originalName, originalUndelimitedContent } = props.attributes;
// Disable reason: This is a valid component, but it's mistaken for a callback.
// eslint-disable-next-line react-hooks/rules-of-hooks
const { block, hasPermission } = useSelect(
( select ) => {
const { getDownloadableBlocks } = select( 'core/block-directory' );
const { getDownloadableBlocks } = select( blockDirectoryStore );
const blocks = getDownloadableBlocks(
'block:' + originalName
).filter( ( { name } ) => originalName === name );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import { Button } from '@wordpress/components';
import { createBlock, getBlockType, parse } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockDirectoryStore } from '../../store';

export default function InstallButton( { attributes, block, clientId } ) {
const isInstallingBlock = useSelect( ( select ) =>
select( 'core/block-directory' ).isInstalling( block.id )
select( blockDirectoryStore ).isInstalling( block.id )
);
const { installBlockType } = useDispatch( 'core/block-directory' );
const { installBlockType } = useDispatch( blockDirectoryStore );
const { replaceBlock } = useDispatch( 'core/block-editor' );

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { blockDefault } from '@wordpress/icons';
* Internal dependencies
*/
import CompactList from '../../components/compact-list';
import { store as blockDirectoryStore } from '../../store';

export default function InstalledBlocksPrePublishPanel() {
const newBlockTypes = useSelect(
( select ) => select( 'core/block-directory' ).getNewBlockTypes(),
( select ) => select( blockDirectoryStore ).getNewBlockTypes(),
[]
);

Expand Down

0 comments on commit 3067e91

Please sign in to comment.