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

Editor: Unify show icon labels preference #57480

Merged
merged 2 commits into from
Jan 3, 2024
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
29 changes: 7 additions & 22 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ function Header( { setEntitiesSavedStatesCallback } ) {
isPublishSidebarOpened:
select( editPostStore ).isPublishSidebarOpened(),
hasFixedToolbar: getPreference( 'core/edit-post', 'fixedToolbar' ),
showIconLabels:
select( editPostStore ).isFeatureActive( 'showIconLabels' ),
showIconLabels: getPreference( 'core', 'showIconLabels' ),
};
}, [] );

Expand Down Expand Up @@ -113,10 +112,7 @@ function Header( { setEntitiesSavedStatesCallback } ) {
transition={ { type: 'tween', delay: 0.8 } }
className="edit-post-header__toolbar"
>
<DocumentTools
disableBlockTools={ isTextEditor }
showIconLabels={ showIconLabels }
/>
<DocumentTools disableBlockTools={ isTextEditor } />
{ hasFixedToolbar && isLargeViewport && (
<>
<div
Expand Down Expand Up @@ -177,35 +173,24 @@ function Header( { setEntitiesSavedStatesCallback } ) {
// we want to prevent mounting/unmounting the PostPublishButtonOrToggle DOM node.
// We track that DOM node to return focus to the PostPublishButtonOrToggle
// when the publish sidebar has been closed.
<PostSavedState
forceIsDirty={ hasActiveMetaboxes }
showIconLabels={ showIconLabels }
/>
<PostSavedState forceIsDirty={ hasActiveMetaboxes } />
) }
<PreviewDropdown
showIconLabels={ showIconLabels }
forceIsAutosaveable={ hasActiveMetaboxes }
/>
<PreviewDropdown forceIsAutosaveable={ hasActiveMetaboxes } />
<PostPreviewButton
className="edit-post-header__post-preview-button"
forceIsAutosaveable={ hasActiveMetaboxes }
/>
<PostViewLink showIconLabels={ showIconLabels } />
<PostViewLink />
<PostPublishButtonOrToggle
forceIsDirty={ hasActiveMetaboxes }
setEntitiesSavedStatesCallback={
setEntitiesSavedStatesCallback
}
/>
{ ( isWideViewport || ! showIconLabels ) && (
<>
<PinnedItems.Slot scope="core/edit-post" />
<MoreMenu showIconLabels={ showIconLabels } />
</>
) }
{ showIconLabels && ! isWideViewport && (
<MoreMenu showIconLabels={ showIconLabels } />
<PinnedItems.Slot scope="core/edit-post" />
) }
<MoreMenu showIconLabels={ showIconLabels } />
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
</motion.div>
</div>
);
Expand Down
6 changes: 4 additions & 2 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
import { useState, useEffect, useCallback, useMemo } from '@wordpress/element';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as noticesStore } from '@wordpress/notices';
import { store as preferencesStore } from '@wordpress/preferences';

import { privateApis as commandsPrivateApis } from '@wordpress/commands';
import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands';

Expand Down Expand Up @@ -164,6 +166,7 @@ function Layout() {
documentLabel,
hasHistory,
} = useSelect( ( select ) => {
const { get } = select( preferencesStore );
const { getEditorSettings, getPostTypeLabel } = select( editorStore );
const editorSettings = getEditorSettings();
const postTypeLabel = getPostTypeLabel();
Expand All @@ -189,8 +192,7 @@ function Layout() {
nextShortcut: select(
keyboardShortcutsStore
).getAllShortcutKeyCombinations( 'core/edit-post/next-region' ),
showIconLabels:
select( editPostStore ).isFeatureActive( 'showIconLabels' ),
showIconLabels: get( 'core', 'showIconLabels' ),
isDistractionFree:
select( editPostStore ).isFeatureActive( 'distractionFree' ),
showBlockBreadcrumbs: select( editPostStore ).isFeatureActive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export default function EditPostPreferencesModal() {
</PreferencesModalSection>
<PreferencesModalSection title={ __( 'Interface' ) }>
<EnableFeature
scope="core"
featureName="showIconLabels"
label={ __( 'Show button text labels' ) }
help={ __(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { __ } from '@wordpress/i18n';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';

/**
* Renders a sidebar when activated. The contents within the `PluginSidebar` will appear as content within the sidebar.
* It also automatically renders a corresponding `PluginSidebarMenuItem` component when `isPinnable` flag is set to `true`.
Expand Down Expand Up @@ -78,14 +73,12 @@ import { store as editPostStore } from '../../../store';
* ```
*/
export default function PluginSidebarEditPost( { className, ...props } ) {
const { postTitle, shortcut, showIconLabels } = useSelect( ( select ) => {
const { postTitle, shortcut } = useSelect( ( select ) => {
return {
postTitle: select( editorStore ).getEditedPostAttribute( 'title' ),
shortcut: select(
keyboardShortcutsStore
).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' ),
showIconLabels:
select( editPostStore ).isFeatureActive( 'showIconLabels' ),
};
}, [] );
return (
Expand All @@ -95,7 +88,6 @@ export default function PluginSidebarEditPost( { className, ...props } ) {
smallScreenTitle={ postTitle || __( '(no title)' ) }
scope="core/edit-post"
toggleShortcut={ shortcut }
showIconLabels={ showIconLabels }
{ ...props }
/>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export function initializeEditor(
openPanels: [ 'post-status' ],
preferredStyleVariations: {},
showBlockBreadcrumbs: true,
showIconLabels: false,
showListViewByDefault: false,
themeStyles: true,
welcomeGuide: true,
Expand All @@ -72,6 +71,7 @@ export function initializeEditor(

dispatch( preferencesStore ).setDefaults( 'core', {
allowRightClickOverrides: true,
showIconLabels: false,
} );

dispatch( blocksStore ).reapplyBlockTypeFilters();
Expand Down
8 changes: 3 additions & 5 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default function Editor( { isLoading } ) {
const { getEntityRecord } = select( coreDataStore );
const { getRenderingMode, isInserterOpened, isListViewOpened } =
select( editorStore );
const { get } = select( preferencesStore );
const _context = getEditedPostContext();

// The currently selected entity to display.
Expand All @@ -138,11 +139,8 @@ export default function Editor( { isLoading } ) {
isRightSidebarOpen: getActiveComplementaryArea(
editSiteStore.name
),
showIconLabels: select( preferencesStore ).get(
'core/edit-site',
'showIconLabels'
),
showBlockBreadcrumbs: select( preferencesStore ).get(
showIconLabels: get( 'core', 'showIconLabels' ),
showBlockBreadcrumbs: get(
'core/edit-site',
'showBlockBreadcrumbs'
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default function DocumentTools( {
blockEditorMode,
hasFixedToolbar,
isDistractionFree,
showIconLabels,
} ) {
const { isVisualMode } = useSelect( ( select ) => {
const { getEditorMode } = select( editSiteStore );
Expand All @@ -42,7 +41,6 @@ export default function DocumentTools( {

return (
<EditorDocumentTools
showIconLabels={ showIconLabels }
disableBlockTools={ ! isVisualMode }
listViewLabel={ __( 'List View' ) }
>
Expand Down
9 changes: 2 additions & 7 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ export default function HeaderEditMode() {
templateType: getEditedPostType(),
blockEditorMode: __unstableGetEditorMode(),
blockSelectionStart: getBlockSelectionStart(),
showIconLabels: getPreference(
editSiteStore.name,
'showIconLabels'
),
showIconLabels: getPreference( 'core', 'showIconLabels' ),
editorCanvasView: unlock(
select( editSiteStore )
).getEditorCanvasContainerView(),
Expand Down Expand Up @@ -136,7 +133,6 @@ export default function HeaderEditMode() {
<DocumentTools
blockEditorMode={ blockEditorMode }
isDistractionFree={ isDistractionFree }
showIconLabels={ showIconLabels }
/>
{ isTopToolbar && (
<>
Expand Down Expand Up @@ -209,14 +205,13 @@ export default function HeaderEditMode() {
) }
>
<PreviewDropdown
showIconLabels={ showIconLabels }
disabled={
isFocusMode || ! hasDefaultEditorCanvasView
}
/>
</div>
) }
<PostViewLink showIconLabels={ showIconLabels } />
<PostViewLink />
<SaveButton />
{ ! isDistractionFree && (
<PinnedItems.Slot scope="core/edit-site" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export default function EditSitePreferencesModal() {
</PreferencesModalSection>
<PreferencesModalSection title={ __( 'Interface' ) }>
<EnableFeature
namespace="core"
featureName="showIconLabels"
label={ __( 'Show button text labels' ) }
help={ __(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
ComplementaryArea,
ComplementaryAreaMoreMenuItem,
} from '@wordpress/interface';
import { useSelect } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';

export default function DefaultSidebar( {
className,
Expand All @@ -19,15 +17,6 @@ export default function DefaultSidebar( {
headerClassName,
panelClassName,
} ) {
const showIconLabels = useSelect(
( select ) =>
!! select( preferencesStore ).get(
'core/edit-site',
'showIconLabels'
),
[]
);

return (
<>
<ComplementaryArea
Expand All @@ -41,7 +30,6 @@ export default function DefaultSidebar( {
header={ header }
headerClassName={ headerClassName }
panelClassName={ panelClassName }
showIconLabels={ showIconLabels }
>
{ children }
</ComplementaryArea>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* WordPress dependencies
*/
import { ComplementaryArea } from '@wordpress/interface';
import { useSelect } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Renders a sidebar when activated. The contents within the `PluginSidebar` will appear as content within the sidebar.
Expand Down Expand Up @@ -71,21 +69,11 @@ import { store as preferencesStore } from '@wordpress/preferences';
* ```
*/
export default function PluginSidebarEditSite( { className, ...props } ) {
const showIconLabels = useSelect(
( select ) =>
!! select( preferencesStore ).get(
'core/edit-site',
'showIconLabels'
),
[]
);

return (
<ComplementaryArea
panelClassName={ className }
className="edit-site-sidebar-edit-mode"
scope="core/edit-site"
showIconLabels={ showIconLabels }
{ ...props }
/>
);
Expand Down
5 changes: 4 additions & 1 deletion packages/editor/src/components/document-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Button, ToolbarItem } from '@wordpress/components';
import { listView, plus } from '@wordpress/icons';
import { useRef, useCallback } from '@wordpress/element';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand All @@ -36,7 +37,6 @@ const preventDefault = ( event ) => {

function DocumentTools( {
className,
showIconLabels,
disableBlockTools = false,
children,
// This is a temporary prop until the list view is fully unified between post and site editors.
Expand All @@ -51,8 +51,10 @@ function DocumentTools( {
listViewShortcut,
listViewToggleRef,
hasFixedToolbar,
showIconLabels,
} = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const { get } = select( preferencesStore );
const { isListViewOpened, getListViewToggleRef } = unlock(
select( editorStore )
);
Expand All @@ -66,6 +68,7 @@ function DocumentTools( {
),
listViewToggleRef: getListViewToggleRef(),
hasFixedToolbar: getSettings().hasFixedToolbar,
showIconLabels: get( 'core', 'showIconLabels' ),
};
}, [] );

Expand Down
16 changes: 8 additions & 8 deletions packages/editor/src/components/post-saved-state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Icon, check, cloud, cloudUpload } from '@wordpress/icons';
import { displayShortcut } from '@wordpress/keycodes';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand All @@ -27,16 +28,12 @@ import { store as editorStore } from '../../store';
* Component showing whether the post is saved or not and providing save
* buttons.
*
* @param {Object} props Component props.
* @param {?boolean} props.forceIsDirty Whether to force the post to be marked
* as dirty.
* @param {?boolean} props.showIconLabels Whether interface buttons show labels instead of icons
* @param {Object} props Component props.
* @param {?boolean} props.forceIsDirty Whether to force the post to be marked
* as dirty.
* @return {import('react').ComponentType} The component.
*/
export default function PostSavedState( {
forceIsDirty,
showIconLabels = false,
} ) {
export default function PostSavedState( { forceIsDirty } ) {
const [ forceSavedMessage, setForceSavedMessage ] = useState( false );
const isLargeViewport = useViewportMatch( 'small' );

Expand All @@ -50,6 +47,7 @@ export default function PostSavedState( {
isSaving,
isScheduled,
hasPublishAction,
showIconLabels,
} = useSelect(
( select ) => {
const {
Expand All @@ -63,6 +61,7 @@ export default function PostSavedState( {
isAutosavingPost,
getEditedPostAttribute,
} = select( editorStore );
const { get } = select( preferencesStore );

return {
isAutosaving: isAutosavingPost(),
Expand All @@ -75,6 +74,7 @@ export default function PostSavedState( {
isScheduled: isCurrentPostScheduled(),
hasPublishAction:
getCurrentPost()?._links?.[ 'wp:action-publish' ] ?? false,
showIconLabels: get( 'core', 'showIconLabels' ),
};
},
[ forceIsDirty ]
Expand Down
Loading
Loading