Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove unstable selector
  • Loading branch information
youknowriad committed Nov 8, 2023
commit 336e8b3707333e5b0ad5b637b8c22657fe7524be
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { privateApis as editorPrivateApis } from '@wordpress/editor';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand Down Expand Up @@ -102,10 +103,10 @@ export default function useSiteEditorSettings() {
const {
getEditedPostType,
getEditedPostId,
__unstableGetPreference,
getCanvasMode,
getSettings,
} = unlock( select( editSiteStore ) );
const { get: getPreference } = select( preferencesStore );
const { getEditedEntityRecord } = select( coreStore );
const usedPostType = getEditedPostType();
const usedPostId = getEditedPostId();
Expand All @@ -116,10 +117,17 @@ export default function useSiteEditorSettings() {
);
return {
templateSlug: _record.slug,
focusMode: !! __unstableGetPreference( 'focusMode' ),
isDistractionFree: !! __unstableGetPreference( 'distractionFree' ),
hasFixedToolbar: !! __unstableGetPreference( 'fixedToolbar' ),
keepCaretInsideBlock: !! __unstableGetPreference(
focusMode: !! getPreference( 'core/edit-site', 'focusMode' ),
isDistractionFree: !! getPreference(
'core/edit-site',
'distractionFree'
),
hasFixedToolbar: !! getPreference(
'core/edit-site',
'fixedToolbar'
),
keepCaretInsideBlock: !! getPreference(
'core/edit-site',
'keepCaretInsideBlock'
),
canvasMode: getCanvasMode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import {
ComplementaryAreaMoreMenuItem,
} from '@wordpress/interface';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../store';
import { store as preferencesStore } from '@wordpress/preferences';

export default function DefaultSidebar( {
className,
Expand All @@ -25,7 +21,8 @@ export default function DefaultSidebar( {
} ) {
const showIconLabels = useSelect(
( select ) =>
!! select( editSiteStore ).__unstableGetPreference(
!! select( preferencesStore ).get(
'core/edit-site',
'showIconLabels'
),
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
*/
import { ComplementaryArea } from '@wordpress/interface';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../../store';
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 @@ -77,7 +73,8 @@ import { store as editSiteStore } from '../../../store';
export default function PluginSidebarEditSite( { className, ...props } ) {
const showIconLabels = useSelect(
( select ) =>
!! select( editSiteStore ).__unstableGetPreference(
!! select( preferencesStore ).get(
'core/edit-site',
'showIconLabels'
),
[]
Expand Down
36 changes: 12 additions & 24 deletions packages/edit-site/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ import { TEMPLATE_PART_POST_TYPE } from '../utils/constants';
* @typedef {'template'|'template_type'} TemplateType Template type.
*/

/**
* Helper for getting a preference from the preferences store.
*
* This is only present so that `getSettings` doesn't need to be made a
* registry selector.
*
* It's unstable because the selector needs to be exported and so part of the
* public API to work.
*/
export const __unstableGetPreference = createRegistrySelector(
( select ) => ( state, name ) =>
select( preferencesStore ).get( 'core/edit-site', name )
);

/**
* Returns whether the given feature is enabled or not.
*
Expand All @@ -40,14 +26,16 @@ export const __unstableGetPreference = createRegistrySelector(
*
* @return {boolean} Is active.
*/
export function isFeatureActive( state, featureName ) {
deprecated( `select( 'core/edit-site' ).isFeatureActive`, {
since: '6.0',
alternative: `select( 'core/preferences' ).get`,
} );
export const isFeatureActive = createRegistrySelector(
( select ) => ( _, featureName ) => {
deprecated( `select( 'core/edit-site' ).isFeatureActive`, {
since: '6.0',
alternative: `select( 'core/preferences' ).get`,
} );

return !! __unstableGetPreference( state, featureName );
}
return select( preferencesStore ).get( 'core/edit-site', featureName );
}
);

/**
* Returns the current editing canvas device type.
Expand Down Expand Up @@ -257,9 +245,9 @@ export const getCurrentTemplateTemplateParts = createRegistrySelector(
*
* @return {string} Editing mode.
*/
export function getEditorMode( state ) {
return __unstableGetPreference( state, 'editorMode' );
}
export const getEditorMode = createRegistrySelector( ( select ) => () => {
return select( preferencesStore ).get( 'core/edit-site', 'editorMode' );
} );

/**
* @deprecated
Expand Down
5 changes: 0 additions & 5 deletions packages/edit-site/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,19 @@ import {
getReusableBlocks,
isInserterOpened,
isListViewOpened,
__unstableGetPreference,
isPage,
hasPageContentFocus,
} from '../selectors';

describe( 'selectors', () => {
const canUser = jest.fn( () => true );
const getEntityRecords = jest.fn( () => [] );
const get = jest.fn();
getCanUserCreateMedia.registry = {
select: jest.fn( () => ( { canUser } ) ),
};
getReusableBlocks.registry = {
select: jest.fn( () => ( { getEntityRecords } ) ),
};
__unstableGetPreference.registry = {
select: jest.fn( () => ( { get } ) ),
};

describe( 'getCanUserCreateMedia', () => {
it( "selects `canUser( 'create', 'media' )` from the core store", () => {
Expand Down