Skip to content

Commit 5eafc79

Browse files
Update: Remove static defaults from complementary areas active area (WordPress#22381)
1 parent eab88a7 commit 5eafc79

File tree

8 files changed

+40
-67
lines changed

8 files changed

+40
-67
lines changed

packages/edit-post/src/components/sidebar/settings-sidebar/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import { BlockInspector } from '@wordpress/block-editor';
55
import { cog } from '@wordpress/icons';
6+
import { Platform } from '@wordpress/element';
67

78
/**
89
* Internal dependencies
@@ -22,6 +23,11 @@ import PluginSidebarEditPost from '../../sidebar/plugin-sidebar';
2223
import { __ } from '@wordpress/i18n';
2324
import { useSelect } from '@wordpress/data';
2425

26+
const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( {
27+
web: true,
28+
native: false,
29+
} );
30+
2531
const SettingsSidebar = () => {
2632
const { sidebarName, keyboardShortcut } = useSelect( ( select ) => {
2733
// The settings sidebar is used by the edit-post/document and edit-post/block sidebars.
@@ -57,6 +63,7 @@ const SettingsSidebar = () => {
5763
title={ __( 'Settings' ) }
5864
toggleShortcut={ keyboardShortcut }
5965
icon={ cog }
66+
isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT }
6067
>
6168
{ sidebarName === 'edit-post/document' && (
6269
<>

packages/edit-site/src/components/sidebar/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import { createSlotFill } from '@wordpress/components';
55
import { ComplementaryArea } from '@wordpress/interface';
66
import { __ } from '@wordpress/i18n';
77
import { cog, pencil } from '@wordpress/icons';
8+
import { Platform } from '@wordpress/element';
89

910
const { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill(
1011
'EditSiteSidebarInspector'
1112
);
1213
export const SidebarInspectorFill = InspectorFill;
14+
const BLOCK_INSPECTOR_ACTIVE_BY_DEFAULT = Platform.select( {
15+
web: true,
16+
native: false,
17+
} );
1318
export function SidebarComplementaryAreaFills() {
1419
return (
1520
<>
@@ -18,6 +23,7 @@ export function SidebarComplementaryAreaFills() {
1823
identifier="edit-site/block-inspector"
1924
title={ __( 'Block Inspector' ) }
2025
icon={ cog }
26+
isActiveByDefault={ BLOCK_INSPECTOR_ACTIVE_BY_DEFAULT }
2127
>
2228
<InspectorSlot bubblesVirtually />
2329
</ComplementaryArea>

packages/edit-widgets/src/components/sidebar/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ import classnames from 'classnames';
77
/**
88
* WordPress dependencies
99
*/
10-
import { useEffect } from '@wordpress/element';
10+
import { useEffect, Platform } from '@wordpress/element';
1111
import { __, sprintf } from '@wordpress/i18n';
1212
import { ComplementaryArea } from '@wordpress/interface';
1313
import { BlockInspector } from '@wordpress/block-editor';
1414
import { cog } from '@wordpress/icons';
1515
import { Button } from '@wordpress/components';
1616
import { useSelect, useDispatch } from '@wordpress/data';
1717

18+
const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( {
19+
web: true,
20+
native: false,
21+
} );
22+
1823
/**
1924
* Internal dependencies
2025
*/
@@ -131,6 +136,7 @@ export default function Sidebar() {
131136
scope="core/edit-widgets"
132137
identifier={ currentArea }
133138
icon={ cog }
139+
isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT }
134140
>
135141
{ currentArea === 'edit-widgets/block-areas' && <BlockAreas /> }
136142
{ currentArea === 'edit-widgets/block-inspector' && (

packages/interface/src/components/complementary-area/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function ComplementaryArea( {
9292
smallScreenTitle,
9393
title,
9494
toggleShortcut,
95+
isActiveByDefault,
9596
} ) {
9697
const { isActive, isPinned, activeArea, isSmall } = useSelect(
9798
( select ) => {
@@ -117,10 +118,19 @@ function ComplementaryArea( {
117118
isActive,
118119
isSmall
119120
);
120-
const { enableComplementaryArea, disableComplementaryArea } = useDispatch(
121-
'core/interface'
122-
);
123-
const { pinItem, unpinItem } = useDispatch( 'core/interface' );
121+
const {
122+
enableComplementaryArea,
123+
disableComplementaryArea,
124+
pinItem,
125+
unpinItem,
126+
} = useDispatch( 'core/interface' );
127+
128+
useEffect( () => {
129+
if ( isActiveByDefault && activeArea === undefined && ! isSmall ) {
130+
enableComplementaryArea( scope, identifier );
131+
}
132+
}, [ activeArea, isActiveByDefault, scope, identifier, isSmall ] );
133+
124134
return (
125135
<>
126136
{ isPinned && isPinnable && (

packages/interface/src/store/defaults.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/interface/src/store/defaults.native.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/interface/src/store/reducer.js

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
11
/**
22
* External dependencies
33
*/
4-
import { flow, get, isEmpty, omit } from 'lodash';
4+
import { get } from 'lodash';
55

66
/**
77
* WordPress dependencies
88
*/
99
import { combineReducers } from '@wordpress/data';
1010

11-
/**
12-
* Internal dependencies
13-
*/
14-
import { DEFAULTS } from './defaults';
15-
16-
/**
17-
* Higher-order reducer creator which provides the given initial state for the
18-
* original reducer.
19-
*
20-
* @param {*} initialState Initial state to provide to reducer.
21-
*
22-
* @return {Function} Higher-order reducer.
23-
*/
24-
const createWithInitialState = ( initialState ) => ( reducer ) => {
25-
return ( state = initialState, action ) => reducer( state, action );
26-
};
27-
2811
/**
2912
* Reducer to keep tract of the active area per scope.
3013
*
@@ -41,18 +24,6 @@ export function singleEnableItems(
4124
return state;
4225
}
4326

44-
if (
45-
! item &&
46-
! get( DEFAULTS.enableItems.singleEnableItems, [ itemType, scope ] )
47-
) {
48-
const newTypeState = omit( state[ itemType ], [ scope ] );
49-
return isEmpty( newTypeState )
50-
? omit( state, [ itemType ] )
51-
: {
52-
...state,
53-
[ itemType ]: newTypeState,
54-
};
55-
}
5627
return {
5728
...state,
5829
[ itemType ]: {
@@ -103,8 +74,6 @@ const enableItems = combineReducers( {
10374
multipleEnableItems,
10475
} );
10576

106-
export default flow( [ combineReducers, createWithInitialState( DEFAULTS ) ] )(
107-
{
108-
enableItems,
109-
}
110-
);
77+
export default combineReducers( {
78+
enableItems,
79+
} );

packages/interface/src/store/selectors.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ import { get } from 'lodash';
1010
* @param {string} itemType Type of item.
1111
* @param {string} scope Item scope.
1212
*
13-
* @return {string} The item that is enabled in the passed scope and type.
13+
* @return {?string|null} The item that is enabled in the passed scope and type.
1414
*/
1515
function getSingleEnableItem( state, itemType, scope ) {
16-
return get(
17-
state.enableItems.singleEnableItems,
18-
[ itemType, scope ],
19-
null
20-
);
16+
return get( state.enableItems.singleEnableItems, [ itemType, scope ] );
2117
}
2218

2319
/**

0 commit comments

Comments
 (0)