Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface: Replace store name string with exposed store definition #28041

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
ComplementaryArea,
FullscreenMode,
InterfaceSkeleton,
store as interfaceStore,
} from '@wordpress/interface';
import { useState, useEffect, useCallback, useRef } from '@wordpress/element';
import { close } from '@wordpress/icons';
Expand Down Expand Up @@ -99,7 +100,7 @@ function Layout( { styles } ) {
'fixedToolbar'
),
sidebarIsOpened: !! (
select( 'core/interface' ).getActiveComplementaryArea(
select( interfaceStore ).getActiveComplementaryArea(
editPostStore.name
) || select( editPostStore ).isPublishSidebarOpened()
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BlockInspector } from '@wordpress/block-editor';
import { cog } from '@wordpress/icons';
import { Platform } from '@wordpress/element';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand Down Expand Up @@ -39,7 +40,7 @@ const SettingsSidebar = () => {
// component, besides being used to render the sidebar, also renders the toggle button. In that case sidebarName
// should contain the sidebar that will be active when the toggle button is pressed. If a block
// is selected, that should be edit-post/block otherwise it's edit-post/document.
let sidebar = select( 'core/interface' ).getActiveComplementaryArea(
let sidebar = select( interfaceStore ).getActiveComplementaryArea(
editPostStore.name
);
if (
Expand Down
5 changes: 3 additions & 2 deletions packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { castArray, reduce } from 'lodash';
*/
import { __ } from '@wordpress/i18n';
import { apiFetch } from '@wordpress/data-controls';
import { store as interfaceStore } from '@wordpress/interface';
import { controls, dispatch, select, subscribe } from '@wordpress/data';
import { speak } from '@wordpress/a11y';

Expand All @@ -25,7 +26,7 @@ import { store as editPostStore } from '.';
*/
export function* openGeneralSidebar( name ) {
yield controls.dispatch(
'core/interface',
interfaceStore.name,
'enableComplementaryArea',
editPostStore.name,
name
Expand All @@ -39,7 +40,7 @@ export function* openGeneralSidebar( name ) {
*/
export function* closeGeneralSidebar() {
yield controls.dispatch(
'core/interface',
interfaceStore.name,
'disableComplementaryArea',
editPostStore.name
);
Expand Down
10 changes: 5 additions & 5 deletions packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { get, includes, some, flatten, values } from 'lodash';
* WordPress dependencies
*/
import { createRegistrySelector } from '@wordpress/data';

import { store as interfaceStore } from '@wordpress/interface';
/**
* Returns the current editing mode.
*
Expand All @@ -30,7 +30,7 @@ export function getEditorMode( state ) {
export const isEditorSidebarOpened = createRegistrySelector(
( select ) => () => {
const activeGeneralSidebar = select(
'core/interface'
interfaceStore
).getActiveComplementaryArea( 'core/edit-post' );
return includes(
[ 'edit-post/document', 'edit-post/block' ],
Expand All @@ -48,7 +48,7 @@ export const isEditorSidebarOpened = createRegistrySelector(
export const isPluginSidebarOpened = createRegistrySelector(
( select ) => () => {
const activeGeneralSidebar = select(
'core/interface'
interfaceStore
).getActiveComplementaryArea( 'core/edit-post' );
return (
!! activeGeneralSidebar &&
Expand Down Expand Up @@ -76,7 +76,7 @@ export const isPluginSidebarOpened = createRegistrySelector(
*/
export const getActiveGeneralSidebarName = createRegistrySelector(
( select ) => () => {
return select( 'core/interface' ).getActiveComplementaryArea(
return select( interfaceStore ).getActiveComplementaryArea(
'core/edit-post'
);
}
Expand Down Expand Up @@ -201,7 +201,7 @@ export function isFeatureActive( state, feature ) {
*/
export const isPluginItemPinned = createRegistrySelector(
( select ) => ( pluginName ) => {
return select( 'core/interface' ).isItemPinned(
return select( interfaceStore ).isItemPinned(
'core/edit-post',
pluginName
);
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
FullscreenMode,
InterfaceSkeleton,
ComplementaryArea,
store as interfaceStore,
} from '@wordpress/interface';
import { EntitiesSavedStates, UnsavedChangesWarning } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -87,7 +88,7 @@ function Editor() {
isFullscreenActive: isFeatureActive( 'fullscreenMode' ),
deviceType: __experimentalGetPreviewDeviceType(),
sidebarIsOpened: !! select(
'core/interface'
interfaceStore
).getActiveComplementaryArea( 'core/edit-site' ),
settings: getSettings(),
templateType: postType,
Expand Down
8 changes: 6 additions & 2 deletions packages/edit-widgets/src/components/layout/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
} from '@wordpress/block-editor';
import { useEffect, useRef } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { InterfaceSkeleton, ComplementaryArea } from '@wordpress/interface';
import {
InterfaceSkeleton,
ComplementaryArea,
store as interfaceStore,
} from '@wordpress/interface';
import { __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -42,7 +46,7 @@ function Interface( { blockEditorSettings } ) {

const { hasSidebarEnabled, isInserterOpened } = useSelect( ( select ) => ( {
hasSidebarEnabled: !! select(
'core/interface'
interfaceStore
).getActiveComplementaryArea( 'core/edit-widgets' ),
isInserterOpened: !! select( 'core/edit-widgets' ).isInserterOpened(),
} ) );
Expand Down
11 changes: 7 additions & 4 deletions packages/edit-widgets/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import classnames from 'classnames';
*/
import { useEffect, Platform } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { ComplementaryArea } from '@wordpress/interface';
import {
ComplementaryArea,
store as interfaceStore,
} from '@wordpress/interface';
import { BlockInspector } from '@wordpress/block-editor';
import { cog } from '@wordpress/icons';
import { Button } from '@wordpress/components';
Expand All @@ -31,7 +34,7 @@ const WIDGET_AREAS_IDENTIFIER = 'edit-widgets/block-areas';
import WidgetAreas from './widget-areas';

function ComplementaryAreaTab( { identifier, label, isActive } ) {
const { enableComplementaryArea } = useDispatch( 'core/interface' );
const { enableComplementaryArea } = useDispatch( interfaceStore );
return (
<Button
onClick={ () =>
Expand All @@ -54,7 +57,7 @@ function ComplementaryAreaTab( { identifier, label, isActive } ) {
}

export default function Sidebar() {
const { enableComplementaryArea } = useDispatch( 'core/interface' );
const { enableComplementaryArea } = useDispatch( interfaceStore );
const {
currentArea,
hasSelectedNonAreaBlock,
Expand All @@ -66,7 +69,7 @@ export default function Sidebar() {
getBlock,
getBlockParentsByBlockName,
} = select( 'core/block-editor' );
const { getActiveComplementaryArea } = select( 'core/interface' );
const { getActiveComplementaryArea } = select( interfaceStore );

const selectedBlock = getSelectedBlock();

Expand Down
4 changes: 2 additions & 2 deletions packages/edit-widgets/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { invert } from 'lodash';
import { __, sprintf } from '@wordpress/i18n';
import { dispatch as dataDispatch } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';

import { store as interfaceStore } from '@wordpress/interface';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -334,7 +334,7 @@ export function setIsInserterOpened( value ) {
*/
export function* closeGeneralSidebar() {
yield dispatch(
'core/interface',
interfaceStore.name,
'disableComplementaryArea',
'core/edit-widgets'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { store as interfaceStore } from '../../store';
import complementaryAreaContext from '../complementary-area-context';

function ComplementaryAreaToggle( {
Expand All @@ -25,12 +26,12 @@ function ComplementaryAreaToggle( {
const ComponentToUse = as;
const isSelected = useSelect(
( select ) =>
select( 'core/interface' ).getActiveComplementaryArea( scope ) ===
select( interfaceStore ).getActiveComplementaryArea( scope ) ===
identifier,
[ identifier ]
);
const { enableComplementaryArea, disableComplementaryArea } = useDispatch(
'core/interface'
interfaceStore
);
return (
<ComponentToUse
Expand Down
7 changes: 4 additions & 3 deletions packages/interface/src/components/complementary-area/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ComplementaryAreaHeader from '../complementary-area-header';
import ComplementaryAreaToggle from '../complementary-area-toggle';
import withComplementaryAreaContext from '../complementary-area-context';
import PinnedItems from '../pinned-items';
import { store as interfaceStore } from '../../store';

function ComplementaryAreaSlot( { scope, ...props } ) {
return <Slot name={ `ComplementaryArea/${ scope }` } { ...props } />;
Expand All @@ -43,7 +44,7 @@ function useAdjustComplementaryListener(
const previousIsSmall = useRef( false );
const shouldOpenWhenNotSmall = useRef( false );
const { enableComplementaryArea, disableComplementaryArea } = useDispatch(
'core/interface'
interfaceStore
);
useEffect( () => {
// If the complementary area is active and the editor is switching from a big to a small window size.
Expand Down Expand Up @@ -98,7 +99,7 @@ function ComplementaryArea( {
const { isActive, isPinned, activeArea, isSmall, isLarge } = useSelect(
( select ) => {
const { getActiveComplementaryArea, isItemPinned } = select(
'core/interface'
interfaceStore
);
const _activeArea = getActiveComplementaryArea( scope );
return {
Expand All @@ -123,7 +124,7 @@ function ComplementaryArea( {
disableComplementaryArea,
pinItem,
unpinItem,
} = useDispatch( 'core/interface' );
} = useDispatch( interfaceStore );

useEffect( () => {
if ( isActiveByDefault && activeArea === undefined && ! isSmall ) {
Expand Down