Skip to content

Commit

Permalink
edit-widgets: fix no-string-literal warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed May 24, 2021
1 parent 6a09db4 commit 456724f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import {
} from '@wordpress/keyboard-shortcuts';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';

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

function KeyboardShortcuts() {
const { redo, undo } = useDispatch( 'core' );
const { redo, undo } = useDispatch( coreStore );
const { saveEditedWidgetAreas } = useDispatch( editWidgetsStore );

useShortcut(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';
* Internal dependencies
*/
import KeyboardShortcuts from '../keyboard-shortcuts';
import { useEntityBlockEditor } from '@wordpress/core-data';
import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';
import { buildWidgetAreasPostId, KIND, POST_TYPE } from '../../store/utils';
import useLastSelectedWidgetArea from '../../hooks/use-last-selected-widget-area';
import { store as editWidgetsStore } from '../../store';
Expand All @@ -38,12 +38,12 @@ export default function WidgetAreasBlockEditorProvider( {
} = useSelect(
( select ) => ( {
hasUploadPermissions: defaultTo(
select( 'core' ).canUser( 'create', 'media' ),
select( coreStore ).canUser( 'create', 'media' ),
true
),
widgetAreas: select( editWidgetsStore ).getWidgetAreas(),
widgets: select( editWidgetsStore ).getWidgets(),
reusableBlocks: select( 'core' ).getEntityRecords(
reusableBlocks: select( coreStore ).getEntityRecords(
'postType',
'wp_block'
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -17,7 +19,7 @@ import { buildWidgetAreasPostId, KIND, POST_TYPE } from '../store/utils';
const useLastSelectedWidgetArea = () =>
useSelect( ( select ) => {
const { getBlockSelectionEnd, getBlockParents, getBlockName } = select(
'core/block-editor'
blockEditorStore
);
const blockSelectionEndClientId = getBlockSelectionEnd();

Expand All @@ -41,7 +43,7 @@ const useLastSelectedWidgetArea = () =>

// If no widget area has been selected, return the clientId of the first
// area.
const { getEntityRecord } = select( 'core' );
const { getEntityRecord } = select( coreStore );
const widgetAreasPost = getEntityRecord(
KIND,
POST_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -12,7 +13,7 @@ import { buildWidgetAreasPostId, KIND, POST_TYPE } from '../store/utils';
const useWidgetLibraryInsertionPoint = () => {
const firstRootId = useSelect( ( select ) => {
// Default to the first widget area
const { getEntityRecord } = select( 'core' );
const { getEntityRecord } = select( coreStore );
const widgetAreasPost = getEntityRecord(
KIND,
POST_TYPE,
Expand Down
22 changes: 12 additions & 10 deletions packages/edit-widgets/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { get, keyBy } from 'lodash';
*/
import { createRegistrySelector } from '@wordpress/data';
import { getWidgetIdFromBlock } from '@wordpress/widgets';
import { store as coreStore } from '@wordpress/core-data';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -23,7 +25,7 @@ import {
import { STORE_NAME as editWidgetsStoreName } from './constants';

export const getWidgets = createRegistrySelector( ( select ) => () => {
const widgets = select( 'core' ).getEntityRecords(
const widgets = select( coreStore ).getEntityRecords(
'root',
'widget',
buildWidgetsQuery()
Expand All @@ -47,7 +49,7 @@ export const getWidget = createRegistrySelector(

export const getWidgetAreas = createRegistrySelector( ( select ) => () => {
const query = buildWidgetAreasQuery();
return select( 'core' ).getEntityRecords(
return select( coreStore ).getEntityRecords(
KIND,
WIDGET_AREA_ENTITY_TYPE,
query
Expand All @@ -64,7 +66,7 @@ export const getWidgetAreaForWidgetId = createRegistrySelector(
( select ) => ( state, widgetId ) => {
const widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();
return widgetAreas.find( ( widgetArea ) => {
const post = select( 'core' ).getEditedEntityRecord(
const post = select( coreStore ).getEditedEntityRecord(
KIND,
POST_TYPE,
buildWidgetAreaPostId( widgetArea.id )
Expand All @@ -90,14 +92,14 @@ export const getEditedWidgetAreas = createRegistrySelector(
}
return widgetAreas
.filter( ( { id } ) =>
select( 'core' ).hasEditsForEntityRecord(
select( coreStore ).hasEditsForEntityRecord(
KIND,
POST_TYPE,
buildWidgetAreaPostId( id )
)
)
.map( ( { id } ) =>
select( 'core' ).getEditedEntityRecord(
select( coreStore ).getEditedEntityRecord(
KIND,
WIDGET_AREA_ENTITY_TYPE,
id
Expand All @@ -117,7 +119,7 @@ export const getReferenceWidgetBlocks = createRegistrySelector(
const results = [];
const widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();
for ( const _widgetArea of widgetAreas ) {
const post = select( 'core' ).getEditedEntityRecord(
const post = select( coreStore ).getEditedEntityRecord(
KIND,
POST_TYPE,
buildWidgetAreaPostId( _widgetArea.id )
Expand Down Expand Up @@ -146,7 +148,7 @@ export const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {
}

for ( const id of widgetAreasIds ) {
const isSaving = select( 'core' ).isSavingEntityRecord(
const isSaving = select( coreStore ).isSavingEntityRecord(
KIND,
WIDGET_AREA_ENTITY_TYPE,
id
Expand All @@ -161,7 +163,7 @@ export const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {
undefined, // account for new widgets without an ID
];
for ( const id of widgetIds ) {
const isSaving = select( 'core' ).isSavingEntityRecord(
const isSaving = select( coreStore ).isSavingEntityRecord(
'root',
'widget',
id
Expand Down Expand Up @@ -208,13 +210,13 @@ export function isInserterOpened( state ) {
export const canInsertBlockInWidgetArea = createRegistrySelector(
( select ) => ( state, blockName ) => {
// Widget areas are always top-level blocks, which getBlocks will return.
const widgetAreas = select( 'core/block-editor' ).getBlocks();
const widgetAreas = select( blockEditorStore ).getBlocks();

// Makes an assumption that a block that can be inserted into one
// widget area can be inserted into any widget area. Uses the first
// widget area for testing whether the block can be inserted.
const [ firstWidgetArea ] = widgetAreas;
return select( 'core/block-editor' ).canInsertBlockType(
return select( blockEditorStore ).canInsertBlockType(
blockName,
firstWidgetArea.clientId
);
Expand Down

0 comments on commit 456724f

Please sign in to comment.