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 site editor feature preferences to interface package #34191

Closed
Closed
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
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/data/src/plugins/persistence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ persistencePlugin.__unstableMigrate = ( pluginOptions ) => {
'core/customize-widgets'
);
migrateFeaturePreferencesToInterfaceStore( persistence, 'core/edit-post' );
migrateFeaturePreferencesToInterfaceStore( persistence, 'core/edit-site' );
};

export default persistencePlugin;
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/src/click-on-more-menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { toggleMoreMenu } from './toggle-more-menu';
export async function clickOnMoreMenuItem( buttonLabel ) {
await toggleMoreMenu();
const moreMenuContainerSelector =
'//*[contains(concat(" ", @class, " "), " edit-post-more-menu__content ")]';
'//*[contains(concat(" ", @class, " "), " interface-more-menu-dropdown__content ")]';
const elementToClick = first(
await page.$x(
`${ moreMenuContainerSelector }//span[contains(concat(" ", @class, " "), " components-menu-item__item ")][contains(text(), "${ buttonLabel }")]`
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/src/toggle-more-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*/
export async function toggleMoreMenu() {
await expect( page ).toClick(
'.edit-post-more-menu [aria-label="Options"]'
'.interface-more-menu-dropdown [aria-label="Options"]'
);
}
20 changes: 0 additions & 20 deletions packages/e2e-tests/experimental-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,6 @@ export const siteEditor = {
await page.waitForSelector( '.edit-site-visual-editor iframe' );
},

async toggleMoreMenu() {
// eslint-disable-next-line jest/no-standalone-expect
await expect( page ).toClick(
'.edit-site-more-menu [aria-label="More tools & options"]'
);
},

async clickOnMoreMenuItem( buttonLabel ) {
await this.toggleMoreMenu();
const moreMenuContainerSelector =
'//*[contains(concat(" ", @class, " "), " edit-site-more-menu__content ")]';
const elementToClick = (
await page.$x(
`${ moreMenuContainerSelector }//span[contains(concat(" ", @class, " "), " components-menu-item__item ")][contains(text(), "${ buttonLabel }")]`
)
)[ 0 ];

await elementToClick.click();
},

async getEditedPostContent() {
return page.evaluate( async () => {
const postId = window.wp.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import os from 'os';
/**
* WordPress dependencies
*/
import { trashAllPosts, activateTheme } from '@wordpress/e2e-test-utils';
import {
clickOnMoreMenuItem,
trashAllPosts,
activateTheme,
} from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,7 +56,7 @@ describe( 'Site Editor Templates Export', () => {
downloadPath: directory,
} );

await siteEditor.clickOnMoreMenuItem( 'Export' );
await clickOnMoreMenuItem( 'Export' );
const filePath = path.join( directory, 'edit-site-export.zip' );
await waitForFileExists( filePath );
expect( fs.existsSync( filePath ) ).toBe( true );
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@wordpress/core-data": "file:../core-data",
"@wordpress/data": "file:../data",
"@wordpress/data-controls": "file:../data-controls",
"@wordpress/deprecated": "file:../deprecated",
"@wordpress/editor": "file:../editor",
"@wordpress/element": "file:../element",
"@wordpress/hooks": "file:../hooks",
Expand Down
31 changes: 28 additions & 3 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useCallback, useRef } from '@wordpress/element';
import { useCallback, useMemo, useRef } from '@wordpress/element';
import { useEntityBlockEditor } from '@wordpress/core-data';
import {
BlockEditorProvider,
Expand All @@ -18,6 +18,7 @@ import {
__unstableIframe as Iframe,
} from '@wordpress/block-editor';
import { useMergeRefs } from '@wordpress/compose';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand All @@ -35,7 +36,14 @@ const LAYOUT = {
};

export default function BlockEditor( { setIsInserterOpen } ) {
const { settings, templateType, page, deviceType } = useSelect(
const {
settings,
templateType,
page,
deviceType,
isFixedToolbarActive,
isFocusModeActive,
} = useSelect(
( select ) => {
const {
getSettings,
Expand All @@ -44,6 +52,14 @@ export default function BlockEditor( { setIsInserterOpen } ) {
__experimentalGetPreviewDeviceType,
} = select( editSiteStore );
return {
isFixedToolbarActive: select( interfaceStore ).isFeatureActive(
'core/edit-site',
'fixedToolbar'
),
isFocusModeActive: select( interfaceStore ).isFeatureActive(
'core/edit-site',
'focusMode'
),
settings: getSettings( setIsInserterOpen ),
templateType: getEditedPostType(),
page: getPage(),
Expand All @@ -62,9 +78,18 @@ export default function BlockEditor( { setIsInserterOpen } ) {
const contentRef = useRef();
const mergedRefs = useMergeRefs( [ contentRef, useTypingObserver() ] );

const editorSettings = useMemo(
() => ( {
...settings,
hasFixedToolbar: isFixedToolbarActive,
focusMode: isFocusModeActive,
} ),
[ settings, isFixedToolbarActive, isFocusModeActive ]
);

return (
<BlockEditorProvider
settings={ settings }
settings={ editorSettings }
value={ blocks }
onInput={ onInput }
onChange={ onChange }
Expand Down
55 changes: 0 additions & 55 deletions packages/edit-site/src/components/header/feature-toggle/index.js

This file was deleted.

27 changes: 12 additions & 15 deletions packages/edit-site/src/components/header/more-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { moreVertical } from '@wordpress/icons';
import { DropdownMenu, MenuGroup } from '@wordpress/components';
import { ActionItem } from '@wordpress/interface';
import { MenuGroup } from '@wordpress/components';
import {
ActionItem,
MoreMenuDropdown,
MoreMenuFeatureToggle,
} from '@wordpress/interface';

/**
* Internal dependencies
*/
import FeatureToggle from '../feature-toggle';
import ToolsMoreMenuGroup from '../tools-more-menu-group';

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

const MoreMenu = () => (
<DropdownMenu
<MoreMenuDropdown
className="edit-site-more-menu"
icon={ moreVertical }
label={ __( 'More tools & options' ) }
popoverProps={ POPOVER_PROPS }
toggleProps={ TOGGLE_PROPS }
>
{ ( { onClose } ) => (
<>
<MenuGroup label={ _x( 'View', 'noun' ) }>
<FeatureToggle
<MoreMenuFeatureToggle
scope="core/edit-site"
feature="fixedToolbar"
label={ __( 'Top toolbar' ) }
info={ __(
Expand All @@ -40,7 +36,8 @@ const MoreMenu = () => (
messageActivated={ __( 'Top toolbar activated' ) }
messageDeactivated={ __( 'Top toolbar deactivated' ) }
/>
<FeatureToggle
<MoreMenuFeatureToggle
scope="core/edit-site"
feature="focusMode"
label={ __( 'Spotlight mode' ) }
info={ __( 'Focus on one block at a time' ) }
Expand All @@ -59,7 +56,7 @@ const MoreMenu = () => (
<ToolsMoreMenuGroup.Slot fillProps={ { onClose } } />
</>
) }
</DropdownMenu>
</MoreMenuDropdown>
);

export default MoreMenu;
7 changes: 7 additions & 0 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from '@wordpress/block-library';
import { render, unmountComponentAtNode } from '@wordpress/element';
import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
import { dispatch } from '@wordpress/data';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand Down Expand Up @@ -44,6 +46,11 @@ export function initialize( id, settings ) {
fetchLinkSuggestions( search, searchOptions, settings );
settings.__experimentalSpotlightEntityBlocks = [ 'core/template-part' ];

dispatch( interfaceStore ).setFeatureDefaults( 'core/edit-site', {
fixedToolbar: false,
focusMode: false,
} );

const target = document.getElementById( id );
const reboot = reinitializeEditor.bind( null, target, settings );

Expand Down
25 changes: 18 additions & 7 deletions packages/edit-site/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
*/
import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
import { controls, dispatch } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';
import { apiFetch } from '@wordpress/data-controls';
import { addQueryArgs, getPathAndQueryString } from '@wordpress/url';
import { __ } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { store as coreStore } from '@wordpress/core-data';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand All @@ -19,14 +21,23 @@ import isTemplateRevertable from '../utils/is-template-revertable';
* Returns an action object used to toggle a feature flag.
*
* @param {string} feature Feature name.
*
* @return {Object} Action object.
*/
export function toggleFeature( feature ) {
return {
type: 'TOGGLE_FEATURE',
feature,
};
export function* toggleFeature( feature ) {
deprecated(
'`dispatch( editSiteStore ).toggleFeature( myFeature )` action',
{
since: '11.3',
alternative:
"`dispatch( interfaceStore ).toggleFeature( 'core/edit-site', myFeature )` action",
}
);

yield controls.dispatch(
interfaceStore.name,
'toggleFeature',
'core/edit-site',
feature
);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions packages/edit-site/src/store/defaults.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/edit-site/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const storeConfig = {
actions,
selectors,
controls,
persist: [ 'preferences' ],
};

export const store = createReduxStore( STORE_NAME, storeConfig );
Expand Down
24 changes: 0 additions & 24 deletions packages/edit-site/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,8 @@ import { combineReducers } from '@wordpress/data';
/**
* Internal dependencies
*/
import { PREFERENCES_DEFAULTS } from './defaults';
import { MENU_ROOT } from '../components/navigation-sidebar/navigation-panel/constants';

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

/**
* Reducer returning the editing canvas device type.
*
Expand Down Expand Up @@ -207,7 +184,6 @@ export function listViewPanel( state = false, action ) {
}

export default combineReducers( {
preferences,
deviceType,
settings,
editedPost,
Expand Down
Loading