Skip to content

Commit

Permalink
Update: Remove static defaults from complementary areas active area (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Jun 3, 2020
1 parent eab88a7 commit 5eafc79
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { BlockInspector } from '@wordpress/block-editor';
import { cog } from '@wordpress/icons';
import { Platform } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -22,6 +23,11 @@ import PluginSidebarEditPost from '../../sidebar/plugin-sidebar';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';

const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( {
web: true,
native: false,
} );

const SettingsSidebar = () => {
const { sidebarName, keyboardShortcut } = useSelect( ( select ) => {
// The settings sidebar is used by the edit-post/document and edit-post/block sidebars.
Expand Down Expand Up @@ -57,6 +63,7 @@ const SettingsSidebar = () => {
title={ __( 'Settings' ) }
toggleShortcut={ keyboardShortcut }
icon={ cog }
isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT }
>
{ sidebarName === 'edit-post/document' && (
<>
Expand Down
6 changes: 6 additions & 0 deletions packages/edit-site/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import { createSlotFill } from '@wordpress/components';
import { ComplementaryArea } from '@wordpress/interface';
import { __ } from '@wordpress/i18n';
import { cog, pencil } from '@wordpress/icons';
import { Platform } from '@wordpress/element';

const { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill(
'EditSiteSidebarInspector'
);
export const SidebarInspectorFill = InspectorFill;
const BLOCK_INSPECTOR_ACTIVE_BY_DEFAULT = Platform.select( {
web: true,
native: false,
} );
export function SidebarComplementaryAreaFills() {
return (
<>
Expand All @@ -18,6 +23,7 @@ export function SidebarComplementaryAreaFills() {
identifier="edit-site/block-inspector"
title={ __( 'Block Inspector' ) }
icon={ cog }
isActiveByDefault={ BLOCK_INSPECTOR_ACTIVE_BY_DEFAULT }
>
<InspectorSlot bubblesVirtually />
</ComplementaryArea>
Expand Down
8 changes: 7 additions & 1 deletion packages/edit-widgets/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import { useEffect, Platform } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { ComplementaryArea } from '@wordpress/interface';
import { BlockInspector } from '@wordpress/block-editor';
import { cog } from '@wordpress/icons';
import { Button } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';

const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( {
web: true,
native: false,
} );

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -131,6 +136,7 @@ export default function Sidebar() {
scope="core/edit-widgets"
identifier={ currentArea }
icon={ cog }
isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT }
>
{ currentArea === 'edit-widgets/block-areas' && <BlockAreas /> }
{ currentArea === 'edit-widgets/block-inspector' && (
Expand Down
18 changes: 14 additions & 4 deletions packages/interface/src/components/complementary-area/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function ComplementaryArea( {
smallScreenTitle,
title,
toggleShortcut,
isActiveByDefault,
} ) {
const { isActive, isPinned, activeArea, isSmall } = useSelect(
( select ) => {
Expand All @@ -117,10 +118,19 @@ function ComplementaryArea( {
isActive,
isSmall
);
const { enableComplementaryArea, disableComplementaryArea } = useDispatch(
'core/interface'
);
const { pinItem, unpinItem } = useDispatch( 'core/interface' );
const {
enableComplementaryArea,
disableComplementaryArea,
pinItem,
unpinItem,
} = useDispatch( 'core/interface' );

useEffect( () => {
if ( isActiveByDefault && activeArea === undefined && ! isSmall ) {
enableComplementaryArea( scope, identifier );
}
}, [ activeArea, isActiveByDefault, scope, identifier, isSmall ] );

return (
<>
{ isPinned && isPinnable && (
Expand Down
11 changes: 0 additions & 11 deletions packages/interface/src/store/defaults.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/interface/src/store/defaults.native.js

This file was deleted.

39 changes: 4 additions & 35 deletions packages/interface/src/store/reducer.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
/**
* External dependencies
*/
import { flow, get, isEmpty, omit } from 'lodash';
import { get } from 'lodash';

/**
* WordPress dependencies
*/
import { combineReducers } from '@wordpress/data';

/**
* Internal dependencies
*/
import { DEFAULTS } from './defaults';

/**
* Higher-order reducer creator which provides the given initial state for the
* original reducer.
*
* @param {*} initialState Initial state to provide to reducer.
*
* @return {Function} Higher-order reducer.
*/
const createWithInitialState = ( initialState ) => ( reducer ) => {
return ( state = initialState, action ) => reducer( state, action );
};

/**
* Reducer to keep tract of the active area per scope.
*
Expand All @@ -41,18 +24,6 @@ export function singleEnableItems(
return state;
}

if (
! item &&
! get( DEFAULTS.enableItems.singleEnableItems, [ itemType, scope ] )
) {
const newTypeState = omit( state[ itemType ], [ scope ] );
return isEmpty( newTypeState )
? omit( state, [ itemType ] )
: {
...state,
[ itemType ]: newTypeState,
};
}
return {
...state,
[ itemType ]: {
Expand Down Expand Up @@ -103,8 +74,6 @@ const enableItems = combineReducers( {
multipleEnableItems,
} );

export default flow( [ combineReducers, createWithInitialState( DEFAULTS ) ] )(
{
enableItems,
}
);
export default combineReducers( {
enableItems,
} );
8 changes: 2 additions & 6 deletions packages/interface/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import { get } from 'lodash';
* @param {string} itemType Type of item.
* @param {string} scope Item scope.
*
* @return {string} The item that is enabled in the passed scope and type.
* @return {?string|null} The item that is enabled in the passed scope and type.
*/
function getSingleEnableItem( state, itemType, scope ) {
return get(
state.enableItems.singleEnableItems,
[ itemType, scope ],
null
);
return get( state.enableItems.singleEnableItems, [ itemType, scope ] );
}

/**
Expand Down

0 comments on commit 5eafc79

Please sign in to comment.