-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use experiment locking/unlocking system for block interface selector …
…and actions (#47375) * Update block editor store to make the block interface API properly experimental * Unlock experimental block interface API before usage * Fix tests * Remove __experimental prefix from locked APIs * Update documentation Co-authored-by: Adam Zielinski <[email protected]> * Fix incorrect `privateSettings` key --------- Co-authored-by: Adam Zielinski <[email protected]>
- Loading branch information
Showing
11 changed files
with
136 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Platform } from '@wordpress/element'; | ||
|
||
/** | ||
* A list of private/experimental block editor settings that | ||
* should not become a part of the WordPress public API. | ||
* BlockEditorProvider will remove these settings from the | ||
* settings object it receives. | ||
* | ||
* @see https://github.com/WordPress/gutenberg/pull/46131 | ||
*/ | ||
const privateSettings = [ 'inserterMediaCategories' ]; | ||
|
||
/** | ||
* Action that updates the block editor settings and | ||
* conditionally preserves the experimental ones. | ||
* | ||
* @param {Object} settings Updated settings | ||
* @param {boolean} stripExperimentalSettings Whether to strip experimental settings. | ||
* @return {Object} Action object | ||
*/ | ||
export function __experimentalUpdateSettings( | ||
settings, | ||
stripExperimentalSettings = false | ||
) { | ||
let cleanSettings = settings; | ||
// There are no plugins in the mobile apps, so there is no | ||
// need to strip the experimental settings: | ||
if ( stripExperimentalSettings && Platform.OS === 'web' ) { | ||
cleanSettings = {}; | ||
for ( const key in settings ) { | ||
if ( ! privateSettings.includes( key ) ) { | ||
cleanSettings[ key ] = settings[ key ]; | ||
} | ||
} | ||
} | ||
return { | ||
type: 'UPDATE_SETTINGS', | ||
settings: cleanSettings, | ||
}; | ||
} | ||
|
||
/** | ||
* Hides the block interface (eg. toolbar, outline, etc.) | ||
* | ||
* @return {Object} Action object. | ||
*/ | ||
export function hideBlockInterface() { | ||
return { | ||
type: 'HIDE_BLOCK_INTERFACE', | ||
}; | ||
} | ||
|
||
/** | ||
* Shows the block interface (eg. toolbar, outline, etc.) | ||
* | ||
* @return {Object} Action object. | ||
*/ | ||
export function showBlockInterface() { | ||
return { | ||
type: 'SHOW_BLOCK_INTERFACE', | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Returns true if the block interface is hidden, or false otherwise. | ||
* | ||
* @param {Object} state Global application state. | ||
* | ||
* @return {boolean} Whether the block toolbar is hidden. | ||
*/ | ||
export function isBlockInterfaceHidden( state ) { | ||
return state.isBlockInterfaceHidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { hideBlockInterface, showBlockInterface } from '../private-actions'; | ||
|
||
describe( 'private actions', () => { | ||
describe( 'hideBlockInterface', () => { | ||
it( 'should return the HIDE_BLOCK_INTERFACE action', () => { | ||
expect( hideBlockInterface() ).toEqual( { | ||
type: 'HIDE_BLOCK_INTERFACE', | ||
} ); | ||
} ); | ||
} ); | ||
|
||
describe( 'showBlockInterface', () => { | ||
it( 'should return the SHOW_BLOCK_INTERFACE action', () => { | ||
expect( showBlockInterface() ).toEqual( { | ||
type: 'SHOW_BLOCK_INTERFACE', | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { isBlockInterfaceHidden } from '../private-selectors'; | ||
|
||
describe( 'private selectors', () => { | ||
describe( 'isBlockInterfaceHidden', () => { | ||
it( 'should return the true if toggled true in state', () => { | ||
const state = { | ||
isBlockInterfaceHidden: true, | ||
}; | ||
|
||
expect( isBlockInterfaceHidden( state ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return false if toggled false in state', () => { | ||
const state = { | ||
isBlockInterfaceHidden: false, | ||
}; | ||
|
||
expect( isBlockInterfaceHidden( state ) ).toBe( false ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fa0da6a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in fa0da6a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4042566598
📝 Reported issues:
specs/editor/various/multi-block-selection.test.js