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

Migrate customize widgets feature preferences to interface package #34135

Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/customize-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@wordpress/hooks": "file:../hooks",
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/interface": "file:../interface",
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
"@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts",
"@wordpress/keycodes": "file:../keycodes",
Expand Down

This file was deleted.

28 changes: 12 additions & 16 deletions packages/customize-widgets/src/components/more-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
* WordPress dependencies
*/
import {
ToolbarDropdownMenu,
MenuGroup,
MenuItem,
ToolbarDropdownMenu,
VisuallyHidden,
} from '@wordpress/components';
import { useState } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { external, moreVertical } from '@wordpress/icons';
import { external } from '@wordpress/icons';
import { displayShortcut } from '@wordpress/keycodes';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import { MoreMenuDropdown, MoreMenuFeatureToggle } from '@wordpress/interface';

/**
* Internal dependencies
*/
import FeatureToggle from './feature-toggle';
import KeyboardShortcutHelpModal from '../keyboard-shortcut-help-modal';

const POPOVER_PROPS = {
className: 'customize-widgets-more-menu__content',
position: 'bottom left',
};
const TOGGLE_PROPS = {
tooltipPosition: 'bottom',
};

export default function MoreMenu() {
Expand All @@ -45,18 +41,16 @@ export default function MoreMenu() {

return (
<>
<ToolbarDropdownMenu
<MoreMenuDropdown
as={ ToolbarDropdownMenu }
className="customize-widgets-more-menu"
icon={ moreVertical }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Options' ) }
popoverProps={ POPOVER_PROPS }
toggleProps={ TOGGLE_PROPS }
>
{ () => (
<>
<MenuGroup label={ _x( 'View', 'noun' ) }>
<FeatureToggle
<MoreMenuFeatureToggle
scope="core/customize-widgets"
feature="fixedToolbar"
label={ __( 'Top toolbar' ) }
info={ __(
Expand All @@ -79,7 +73,8 @@ export default function MoreMenu() {
>
{ __( 'Keyboard shortcuts' ) }
</MenuItem>
<FeatureToggle
<MoreMenuFeatureToggle
scope="core/customize-widgets"
feature="welcomeGuide"
label={ __( 'Welcome Guide' ) }
/>
Expand All @@ -102,7 +97,8 @@ export default function MoreMenu() {
</MenuItem>
</MenuGroup>
<MenuGroup label={ __( 'Preferences' ) }>
<FeatureToggle
<MoreMenuFeatureToggle
scope="core/customize-widgets"
feature="keepCaretInsideBlock"
label={ __(
'Contain text cursor inside block'
Expand All @@ -120,7 +116,7 @@ export default function MoreMenu() {
</MenuGroup>
</>
) }
</ToolbarDropdownMenu>
</MoreMenuDropdown>
<KeyboardShortcutHelpModal
isModalActive={ isKeyboardShortcutsModalActive }
toggleModal={ toggleKeyboardShortcutsModal }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
__unstableBlockSettingsMenuFirstItem,
} from '@wordpress/block-editor';
import { uploadMedia } from '@wordpress/media-utils';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand All @@ -29,7 +30,6 @@ import BlockInspectorButton from '../block-inspector-button';
import Header from '../header';
import useInserter from '../inserter/use-inserter';
import SidebarEditorProvider from './sidebar-editor-provider';
import { store as customizeWidgetsStore } from '../../store';
import WelcomeGuide from '../welcome-guide';
import KeyboardShortcuts from '../keyboard-shortcuts';
import BlockAppender from '../block-appender';
Expand All @@ -47,20 +47,24 @@ export default function SidebarBlockEditor( {
keepCaretInsideBlock,
isWelcomeGuideActive,
} = useSelect( ( select ) => {
const { isFeatureActive } = select( interfaceStore );
return {
hasUploadPermissions: defaultTo(
select( coreStore ).canUser( 'create', 'media' ),
true
),
isFixedToolbarActive: select(
customizeWidgetsStore
).__unstableIsFeatureActive( 'fixedToolbar' ),
keepCaretInsideBlock: select(
customizeWidgetsStore
).__unstableIsFeatureActive( 'keepCaretInsideBlock' ),
isWelcomeGuideActive: select(
customizeWidgetsStore
).__unstableIsFeatureActive( 'welcomeGuide' ),
isFixedToolbarActive: isFeatureActive(
'core/customize-widgets',
'fixedToolbar'
),
keepCaretInsideBlock: isFeatureActive(
'core/customize-widgets',
'keepCaretInsideBlock'
),
isWelcomeGuideActive: isFeatureActive(
'core/customize-widgets',
'welcomeGuide'
),
};
}, [] );
const settings = useMemo( () => {
Expand Down
14 changes: 5 additions & 9 deletions packages/customize-widgets/src/components/welcome-guide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
import { __ } from '@wordpress/i18n';
import { Button, ExternalLink } from '@wordpress/components';
import { useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as customizeWidgetsStore } from '../../store';
import { store as interfaceStore } from '@wordpress/interface';

export default function WelcomeGuide( { sidebar } ) {
const { __unstableToggleFeature: toggleFeature } = useDispatch(
customizeWidgetsStore
);
const { toggleFeature } = useDispatch( interfaceStore );

const isEntirelyBlockWidgets = sidebar
.getWidgets()
Expand Down Expand Up @@ -51,7 +45,9 @@ export default function WelcomeGuide( { sidebar } ) {
<Button
className="customize-widgets-welcome-guide__button"
variant="primary"
onClick={ () => toggleFeature( 'welcomeGuide' ) }
onClick={ () =>
toggleFeature( 'core/customize-widgets', 'welcomeGuide' )
}
>
{ __( 'Got it' ) }
</Button>
Expand Down
7 changes: 7 additions & 0 deletions packages/customize-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
registerLegacyWidgetVariations,
} from '@wordpress/widgets';
import { setFreeformContentHandlerName } from '@wordpress/blocks';
import { dispatch } from '@wordpress/data';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand All @@ -33,6 +35,11 @@ const ENABLE_EXPERIMENTAL_FSE_BLOCKS = false;
* @param {Object} blockEditorSettings Block editor settings.
*/
export function initialize( editorName, blockEditorSettings ) {
dispatch( interfaceStore ).setFeatureDefaults( 'core/customize-widgets', {
fixedToolbar: false,
welcomeGuide: true,
} );

const coreBlocks = __experimentalGetCoreBlocks().filter( ( block ) => {
return ! (
DISABLED_BLOCKS.includes( block.name ) ||
Expand Down
18 changes: 0 additions & 18 deletions packages/customize-widgets/src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/**
* Returns an action object used to toggle a feature flag.
*
* This function is unstable, as it is mostly copied from the edit-post
* package. Editor features and preferences have a lot of scope for
* being generalized and refactored.
*
* @param {string} feature Feature name.
*
* @return {Object} Action object.
*/
export function __unstableToggleFeature( feature ) {
return {
type: 'TOGGLE_FEATURE',
feature,
};
}

/**
* Returns an action object used to open/close the inserter.
*
Expand Down
6 changes: 0 additions & 6 deletions packages/customize-widgets/src/store/defaults.js

This file was deleted.

47 changes: 0 additions & 47 deletions packages/customize-widgets/src/store/reducer.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
/**
* External dependencies
*/
import { flow } from 'lodash';

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

/**
* Internal dependencies
*/
import { PREFERENCES_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 tracking whether the inserter is open.
*
Expand All @@ -39,31 +17,6 @@ function blockInserterPanel( state = false, action ) {
return state;
}

/**
* Reducer returning the user preferences.
*
* @param {Object} state Current state.
* @param {Object} action Dispatched action.
*
* @return {Object} Updated state.
*/
export const preferences = flow( [
combineReducers,
createWithInitialState( PREFERENCES_DEFAULTS ),
] )( {
features( state, action ) {
if ( action.type === 'TOGGLE_FEATURE' ) {
return {
...state,
[ action.feature ]: ! state[ action.feature ],
};
}

return state;
},
} );

export default combineReducers( {
blockInserterPanel,
preferences,
} );
21 changes: 0 additions & 21 deletions packages/customize-widgets/src/store/selectors.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* Returns whether the given feature is enabled or not.
*
* This function is unstable, as it is mostly copied from the edit-post
* package. Editor features and preferences have a lot of scope for
* being generalized and refactored.
*
* @param {Object} state Global application state.
* @param {string} feature Feature slug.
*
* @return {boolean} Is active.
*/
export function __unstableIsFeatureActive( state, feature ) {
return get( state.preferences.features, [ feature ], false );
}

/**
* Returns true if the inserter is opened.
*
Expand Down
4 changes: 4 additions & 0 deletions packages/data/src/plugins/persistence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ persistencePlugin.__unstableMigrate = ( pluginOptions ) => {
persistence,
'core/edit-widgets'
);
migrateFeaturePreferencesToInterfaceStore(
persistence,
'core/customize-widgets'
);
};

export default persistencePlugin;
Loading