From a950a79355dc4c9fd47ca70b5d1793296df7083c Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 10 Jun 2021 12:36:01 +1000 Subject: [PATCH 1/4] Initial commit. Added `showBlockBreadcrumbs` feature to the more menu in the Widgets Editor. Importing it into the Widgets interface, but waiting on #32498 to merge before final integration. --- .../src/components/layout/interface.js | 9 ++++- .../src/components/more-menu/index.js | 13 +++++++ packages/edit-widgets/src/store/selectors.js | 2 +- .../edit-widgets/src/store/test/selectors.js | 36 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 packages/edit-widgets/src/store/test/selectors.js diff --git a/packages/edit-widgets/src/components/layout/interface.js b/packages/edit-widgets/src/components/layout/interface.js index cf69328dd414a..b925578f981bf 100644 --- a/packages/edit-widgets/src/components/layout/interface.js +++ b/packages/edit-widgets/src/components/layout/interface.js @@ -47,12 +47,19 @@ function Interface( { blockEditorSettings } ) { ); const { rootClientId, insertionIndex } = useWidgetLibraryInsertionPoint(); - const { hasSidebarEnabled, isInserterOpened } = useSelect( + const { + hasBlockBreadCrumbsEnabled, + hasSidebarEnabled, + isInserterOpened, + } = useSelect( ( select ) => ( { hasSidebarEnabled: !! select( interfaceStore ).getActiveComplementaryArea( editWidgetsStore.name ), isInserterOpened: !! select( editWidgetsStore ).isInserterOpened(), + hasBlockBreadCrumbsEnabled: select( + editWidgetsStore + ).__unstableIsFeatureActive( 'showBlockBreadcrumbs' ), } ), [] ); diff --git a/packages/edit-widgets/src/components/more-menu/index.js b/packages/edit-widgets/src/components/more-menu/index.js index 1a4dc6a8703bf..2c93b5589232b 100644 --- a/packages/edit-widgets/src/components/more-menu/index.js +++ b/packages/edit-widgets/src/components/more-menu/index.js @@ -117,6 +117,19 @@ export default function MoreMenu() { 'Contain text cursor inside block deactivated' ) } /> + ) } diff --git a/packages/edit-widgets/src/store/selectors.js b/packages/edit-widgets/src/store/selectors.js index 70d315cac456c..76cd031993600 100644 --- a/packages/edit-widgets/src/store/selectors.js +++ b/packages/edit-widgets/src/store/selectors.js @@ -238,5 +238,5 @@ export const canInsertBlockInWidgetArea = createRegistrySelector( * @return {boolean} Is active. */ export function __unstableIsFeatureActive( state, feature ) { - return get( state.preferences.features, [ feature ], false ); + return get( state.preferences, [ 'features', feature ], false ); } diff --git a/packages/edit-widgets/src/store/test/selectors.js b/packages/edit-widgets/src/store/test/selectors.js new file mode 100644 index 0000000000000..c684364fccd95 --- /dev/null +++ b/packages/edit-widgets/src/store/test/selectors.js @@ -0,0 +1,36 @@ +/** + * Internal dependencies + */ + +import { __unstableIsFeatureActive } from '../selectors'; + +describe( 'selectors', () => { + describe( '__unstableIsFeatureActive', () => { + it( 'should return the feature value when present', () => { + const state = { + preferences: { + features: { isNightVisionActivated: true }, + }, + }; + expect( + __unstableIsFeatureActive( state, 'isNightVisionActivated' ) + ).toBe( true ); + } ); + + it( 'should return false where feature is not found', () => { + const state = { + preferences: {}, + }; + expect( + __unstableIsFeatureActive( state, 'didILeaveTheOvenOn' ) + ).toBe( false ); + } ); + + it( 'should return false where the state is empty', () => { + const state = {}; + expect( + __unstableIsFeatureActive( state, 'didILeaveTheOvenOn' ) + ).toBe( false ); + } ); + } ); +} ); From ef3b68da30f26d4f93b50bc9539b2735ff774760 Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 10 Jun 2021 14:51:29 +1000 Subject: [PATCH 2/4] Adding a `hasBlockBreadCrumbsEnabled` check to the Widgets Block Bread crumb --- packages/edit-widgets/src/components/layout/interface.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/edit-widgets/src/components/layout/interface.js b/packages/edit-widgets/src/components/layout/interface.js index b925578f981bf..cb5d7a805aa2b 100644 --- a/packages/edit-widgets/src/components/layout/interface.js +++ b/packages/edit-widgets/src/components/layout/interface.js @@ -120,6 +120,7 @@ function Interface( { blockEditorSettings } ) { /> } footer={ + hasBlockBreadCrumbsEnabled && ! isMobileViewport && (
From 26d29b682976bc1d8b6206c1560033a49dfd5437 Mon Sep 17 00:00:00 2001 From: ramonjd Date: Fri, 11 Jun 2021 20:27:33 +1000 Subject: [PATCH 3/4] Reverting the path change to lodash's get in the `__unstableIsFeatureActive` selector and associated test. We should know that the reducer hasn't initialized the state via an error rather than have that error swallowed. --- packages/edit-widgets/src/store/selectors.js | 2 +- packages/edit-widgets/src/store/test/selectors.js | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/edit-widgets/src/store/selectors.js b/packages/edit-widgets/src/store/selectors.js index 76cd031993600..70d315cac456c 100644 --- a/packages/edit-widgets/src/store/selectors.js +++ b/packages/edit-widgets/src/store/selectors.js @@ -238,5 +238,5 @@ export const canInsertBlockInWidgetArea = createRegistrySelector( * @return {boolean} Is active. */ export function __unstableIsFeatureActive( state, feature ) { - return get( state.preferences, [ 'features', feature ], false ); + return get( state.preferences.features, [ feature ], false ); } diff --git a/packages/edit-widgets/src/store/test/selectors.js b/packages/edit-widgets/src/store/test/selectors.js index c684364fccd95..47c96c0943dec 100644 --- a/packages/edit-widgets/src/store/test/selectors.js +++ b/packages/edit-widgets/src/store/test/selectors.js @@ -25,12 +25,5 @@ describe( 'selectors', () => { __unstableIsFeatureActive( state, 'didILeaveTheOvenOn' ) ).toBe( false ); } ); - - it( 'should return false where the state is empty', () => { - const state = {}; - expect( - __unstableIsFeatureActive( state, 'didILeaveTheOvenOn' ) - ).toBe( false ); - } ); } ); } ); From 31f53d5b039b979b09322e324a83cdb6a9737b72 Mon Sep 17 00:00:00 2001 From: ramonjd Date: Sat, 12 Jun 2021 08:23:19 +1000 Subject: [PATCH 4/4] Enabling the block bread crumb by default in the widget editor --- packages/edit-widgets/src/store/defaults.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/edit-widgets/src/store/defaults.js b/packages/edit-widgets/src/store/defaults.js index 61227800b91f7..eac9b38f44480 100644 --- a/packages/edit-widgets/src/store/defaults.js +++ b/packages/edit-widgets/src/store/defaults.js @@ -2,5 +2,6 @@ export const PREFERENCES_DEFAULTS = { features: { fixedToolbar: false, welcomeGuide: true, + showBlockBreadcrumbs: true, }, };