Skip to content

Commit 70eea01

Browse files
noisysocksgziolo
authored andcommitted
Reusable blocks: Mark API as experimental (#11230)
* Reusable blocks: Mark API as experimental The reusable block selectors and actions will need to change in the future. Give ourselves some breathing room to make these changes after Gutenberg 4.2 by marking them as experimental. * Add notes about deprecations added for Reusable Blocks Data API
1 parent fe51bd0 commit 70eea01

File tree

14 files changed

+193
-56
lines changed

14 files changed

+193
-56
lines changed

docs/data/data-core-editor.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ Items are returned ordered descendingly by their 'utility' and 'frecency'.
11201120

11211121
Items that appear in inserter.
11221122

1123-
### getReusableBlock
1123+
### __experimentalGetReusableBlock
11241124

11251125
Returns the reusable block with the given ID.
11261126

@@ -1133,7 +1133,7 @@ Returns the reusable block with the given ID.
11331133

11341134
The reusable block, or null if none exists.
11351135

1136-
### isSavingReusableBlock
1136+
### __experimentalIsSavingReusableBlock
11371137

11381138
Returns whether or not the reusable block with the given ID is being saved.
11391139

@@ -1146,7 +1146,7 @@ Returns whether or not the reusable block with the given ID is being saved.
11461146

11471147
Whether or not the reusable block is being saved.
11481148

1149-
### isFetchingReusableBlock
1149+
### __experimentalIsFetchingReusableBlock
11501150

11511151
Returns true if the reusable block with the given ID is being fetched, or
11521152
false otherwise.
@@ -1160,7 +1160,7 @@ false otherwise.
11601160

11611161
Whether the reusable block is being fetched.
11621162

1163-
### getReusableBlocks
1163+
### __experimentalGetReusableBlocks
11641164

11651165
Returns an array of all reusable blocks.
11661166

@@ -1649,7 +1649,7 @@ Returns an action object used to lock the editor.
16491649

16501650
* lock: Details about the post lock status, user, and nonce.
16511651

1652-
### fetchReusableBlocks
1652+
### __experimentalFetchReusableBlocks
16531653

16541654
Returns an action object used to fetch a single reusable block or all
16551655
reusable blocks from the REST API into the store.
@@ -1659,7 +1659,7 @@ reusable blocks from the REST API into the store.
16591659
* id: If given, only a single reusable block with this ID will
16601660
be fetched.
16611661

1662-
### receiveReusableBlocks
1662+
### __experimentalReceiveReusableBlocks
16631663

16641664
Returns an action object used in signalling that reusable blocks have been
16651665
received. `results` is an array of objects containing:
@@ -1670,7 +1670,7 @@ received. `results` is an array of objects containing:
16701670

16711671
* results: Reusable blocks received.
16721672

1673-
### saveReusableBlock
1673+
### __experimentalSaveReusableBlock
16741674

16751675
Returns an action object used to save a reusable block that's in the store to
16761676
the REST API.
@@ -1679,15 +1679,15 @@ the REST API.
16791679

16801680
* id: The ID of the reusable block to save.
16811681

1682-
### deleteReusableBlock
1682+
### __experimentalDeleteReusableBlock
16831683

16841684
Returns an action object used to delete a reusable block via the REST API.
16851685

16861686
*Parameters*
16871687

16881688
* id: The ID of the reusable block to delete.
16891689

1690-
### updateReusableBlockTitle
1690+
### __experimentalUpdateReusableBlockTitle
16911691

16921692
Returns an action object used in signalling that a reusable block's title is
16931693
to be updated.
@@ -1697,15 +1697,15 @@ to be updated.
16971697
* id: The ID of the reusable block to update.
16981698
* title: The new title.
16991699

1700-
### convertBlockToStatic
1700+
### __experimentalConvertBlockToStatic
17011701

17021702
Returns an action object used to convert a reusable block into a static block.
17031703

17041704
*Parameters*
17051705

17061706
* clientId: The client ID of the block to attach.
17071707

1708-
### convertBlockToReusable
1708+
### __experimentalConvertBlockToReusable
17091709

17101710
Returns an action object used to convert a static block into a reusable block.
17111711

@@ -1776,4 +1776,6 @@ Returns an action object signaling that a new term is added to the edited post.
17761776
* slug: Taxonomy slug.
17771777
* term: Term object.
17781778

1779-
### createNotice
1779+
### createNotice
1780+
1781+
### fetchReusableBlocks

docs/reference/deprecated.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo
3131
- `wp.components.CodeEditor` has been removed. Used `wp.codeEditor` directly instead.
3232
- `wp.blocks.setUnknownTypeHandlerName` has been removed. Please use `setFreeformContentHandlerName` and `setUnregisteredTypeHandlerName` instead.
3333
- `wp.blocks.getUnknownTypeHandlerName` has been removed. Please use `getFreeformContentHandlerName` and `getUnregisteredTypeHandlerName` instead.
34+
- The Reusable Blocks Data API was marked as experimental as it's subject to change in the future.
3435

3536
## 4.1.0
3637

packages/block-library/src/block/edit.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ class ReusableBlockEdit extends Component {
146146
export default compose( [
147147
withSelect( ( select, ownProps ) => {
148148
const {
149-
getReusableBlock,
150-
isFetchingReusableBlock,
151-
isSavingReusableBlock,
149+
__experimentalGetReusableBlock: getReusableBlock,
150+
__experimentalIsFetchingReusableBlock: isFetchingReusableBlock,
151+
__experimentalIsSavingReusableBlock: isSavingReusableBlock,
152152
getBlock,
153153
} = select( 'core/editor' );
154154
const { ref } = ownProps.attributes;
@@ -163,10 +163,10 @@ export default compose( [
163163
} ),
164164
withDispatch( ( dispatch, ownProps ) => {
165165
const {
166-
fetchReusableBlocks,
166+
__experimentalFetchReusableBlocks: fetchReusableBlocks,
167167
updateBlockAttributes,
168-
updateReusableBlockTitle,
169-
saveReusableBlock,
168+
__experimentalUpdateReusableBlockTitle: updateReusableBlockTitle,
169+
__experimentalSaveReusableBlock: saveReusableBlock,
170170
} = dispatch( 'core/editor' );
171171
const { ref } = ownProps.attributes;
172172

packages/editor/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 6.1.0 (Unreleased)
2+
3+
### Deprecations
4+
5+
- The Reusable Blocks Data API is marked as experimental as it's subject to change in the future ([#11230](https://github.com/WordPress/gutenberg/pull/11230)).
6+
17
## 6.0.1 (2018-10-30)
28

39
### Bug Fixes

packages/editor/src/components/block-settings-menu/reusable-block-convert-button.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export function ReusableBlockConvertButton( {
4949

5050
export default compose( [
5151
withSelect( ( select, { clientIds } ) => {
52-
const { getBlock, canInsertBlockType, getReusableBlock } = select( 'core/editor' );
52+
const {
53+
getBlock,
54+
canInsertBlockType,
55+
__experimentalGetReusableBlock: getReusableBlock,
56+
} = select( 'core/editor' );
5357
const {
5458
getFreeformFallbackBlockName,
5559
getUnregisteredFallbackBlockName,
@@ -85,8 +89,8 @@ export default compose( [
8589
} ),
8690
withDispatch( ( dispatch, { clientIds, onToggle = noop } ) => {
8791
const {
88-
convertBlockToReusable,
89-
convertBlockToStatic,
92+
__experimentalConvertBlockToReusable: convertBlockToReusable,
93+
__experimentalConvertBlockToStatic: convertBlockToStatic,
9094
} = dispatch( 'core/editor' );
9195

9296
return {

packages/editor/src/components/block-settings-menu/reusable-block-delete-button.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ export function ReusableBlockDeleteButton( { reusableBlock, onDelete } ) {
3131

3232
export default compose( [
3333
withSelect( ( select, { clientId } ) => {
34-
const { getBlock, getReusableBlock } = select( 'core/editor' );
34+
const {
35+
getBlock,
36+
__experimentalGetReusableBlock: getReusableBlock,
37+
} = select( 'core/editor' );
3538
const block = getBlock( clientId );
3639
return {
3740
reusableBlock: block && isReusableBlock( block ) ? getReusableBlock( block.attributes.ref ) : null,
3841
};
3942
} ),
4043
withDispatch( ( dispatch, { onToggle = noop } ) => {
4144
const {
42-
deleteReusableBlock,
45+
__experimentalDeleteReusableBlock: deleteReusableBlock,
4346
} = dispatch( 'core/editor' );
4447

4548
return {

packages/editor/src/components/inserter/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export default compose(
351351
};
352352
} ),
353353
withDispatch( ( dispatch ) => ( {
354-
fetchReusableBlocks: dispatch( 'core/editor' ).fetchReusableBlocks,
354+
fetchReusableBlocks: dispatch( 'core/editor' ).__experimentalFetchReusableBlocks,
355355
showInsertionPoint: dispatch( 'core/editor' ).showInsertionPoint,
356356
hideInsertionPoint: dispatch( 'core/editor' ).hideInsertionPoint,
357357
} ) ),

packages/editor/src/hooks/default-autocompleters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { blockAutocompleter, userAutocompleter } from '../components';
1717

1818
const defaultAutocompleters = [ userAutocompleter ];
1919

20-
const fetchReusableBlocks = once( () => dispatch( 'core/editor' ).fetchReusableBlocks() );
20+
const fetchReusableBlocks = once( () => dispatch( 'core/editor' ).__experimentalFetchReusableBlocks() );
2121

2222
function setDefaultCompleters( completers, blockName ) {
2323
if ( ! completers ) {

packages/editor/src/store/actions.js

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ export function updatePostLock( lock ) {
578578
*
579579
* @return {Object} Action object.
580580
*/
581-
export function fetchReusableBlocks( id ) {
581+
export function __experimentalFetchReusableBlocks( id ) {
582582
return {
583583
type: 'FETCH_REUSABLE_BLOCKS',
584584
id,
@@ -595,7 +595,7 @@ export function fetchReusableBlocks( id ) {
595595
*
596596
* @return {Object} Action object.
597597
*/
598-
export function receiveReusableBlocks( results ) {
598+
export function __experimentalReceiveReusableBlocks( results ) {
599599
return {
600600
type: 'RECEIVE_REUSABLE_BLOCKS',
601601
results,
@@ -610,7 +610,7 @@ export function receiveReusableBlocks( results ) {
610610
*
611611
* @return {Object} Action object.
612612
*/
613-
export function saveReusableBlock( id ) {
613+
export function __experimentalSaveReusableBlock( id ) {
614614
return {
615615
type: 'SAVE_REUSABLE_BLOCK',
616616
id,
@@ -624,7 +624,7 @@ export function saveReusableBlock( id ) {
624624
*
625625
* @return {Object} Action object.
626626
*/
627-
export function deleteReusableBlock( id ) {
627+
export function __experimentalDeleteReusableBlock( id ) {
628628
return {
629629
type: 'DELETE_REUSABLE_BLOCK',
630630
id,
@@ -640,7 +640,7 @@ export function deleteReusableBlock( id ) {
640640
*
641641
* @return {Object} Action object.
642642
*/
643-
export function updateReusableBlockTitle( id, title ) {
643+
export function __experimentalUpdateReusableBlockTitle( id, title ) {
644644
return {
645645
type: 'UPDATE_REUSABLE_BLOCK_TITLE',
646646
id,
@@ -655,7 +655,7 @@ export function updateReusableBlockTitle( id, title ) {
655655
*
656656
* @return {Object} Action object.
657657
*/
658-
export function convertBlockToStatic( clientId ) {
658+
export function __experimentalConvertBlockToStatic( clientId ) {
659659
return {
660660
type: 'CONVERT_BLOCK_TO_STATIC',
661661
clientId,
@@ -669,7 +669,7 @@ export function convertBlockToStatic( clientId ) {
669669
*
670670
* @return {Object} Action object.
671671
*/
672-
export function convertBlockToReusable( clientIds ) {
672+
export function __experimentalConvertBlockToReusable( clientIds ) {
673673
return {
674674
type: 'CONVERT_BLOCK_TO_REUSABLE',
675675
clientIds: castArray( clientIds ),
@@ -821,3 +821,80 @@ export const createSuccessNotice = partial( createNotice, 'success' );
821821
export const createInfoNotice = partial( createNotice, 'info' );
822822
export const createErrorNotice = partial( createNotice, 'error' );
823823
export const createWarningNotice = partial( createNotice, 'warning' );
824+
825+
//
826+
// Deprecated
827+
//
828+
829+
export function fetchReusableBlocks( id ) {
830+
deprecated( "wp.data.dispatch( 'core/editor' ).fetchReusableBlocks( id )", {
831+
alternative: "wp.data.select( 'core' ).getEntityRecords( 'postType', 'wp_block' )",
832+
plugin: 'Gutenberg',
833+
version: '4.4.0',
834+
} );
835+
836+
return __experimentalFetchReusableBlocks( id );
837+
}
838+
839+
export function receiveReusableBlocks( results ) {
840+
deprecated( "wp.data.dispatch( 'core/editor' ).receiveReusableBlocks( results )", {
841+
alternative: "wp.data.select( 'core' ).getEntityRecords( 'postType', 'wp_block' )",
842+
plugin: 'Gutenberg',
843+
version: '4.4.0',
844+
} );
845+
846+
return __experimentalReceiveReusableBlocks( results );
847+
}
848+
849+
export function saveReusableBlock( id ) {
850+
deprecated( "wp.data.dispatch( 'core/editor' ).saveReusableBlock( id )", {
851+
alternative: "wp.data.dispatch( 'core' ).saveEntityRecord( 'postType', 'wp_block', reusableBlock )",
852+
plugin: 'Gutenberg',
853+
version: '4.4.0',
854+
} );
855+
856+
return __experimentalSaveReusableBlock( id );
857+
}
858+
859+
export function deleteReusableBlock( id ) {
860+
deprecated( 'deleteReusableBlock action (`core/editor` store)', {
861+
alternative: '__experimentalDeleteReusableBlock action (`core/edtior` store)',
862+
plugin: 'Gutenberg',
863+
version: '4.4.0',
864+
hint: 'Using experimental APIs is strongly discouraged as they are subject to removal without notice.',
865+
} );
866+
867+
return __experimentalDeleteReusableBlock( id );
868+
}
869+
870+
export function updateReusableBlockTitle( id, title ) {
871+
deprecated( "wp.data.dispatch( 'core/editor' ).updateReusableBlockTitle( id, title )", {
872+
alternative: "wp.data.dispatch( 'core' ).saveEntityRecord( 'postType', 'wp_block', reusableBlock )",
873+
plugin: 'Gutenberg',
874+
version: '4.4.0',
875+
} );
876+
877+
return __experimentalUpdateReusableBlockTitle( id, title );
878+
}
879+
880+
export function convertBlockToStatic( id ) {
881+
deprecated( 'convertBlockToStatic action (`core/editor` store)', {
882+
alternative: '__experimentalConvertBlockToStatic action (`core/edtior` store)',
883+
plugin: 'Gutenberg',
884+
version: '4.4.0',
885+
hint: 'Using experimental APIs is strongly discouraged as they are subject to removal without notice.',
886+
} );
887+
888+
return __experimentalConvertBlockToStatic( id );
889+
}
890+
891+
export function convertBlockToReusable( id ) {
892+
deprecated( 'convertBlockToReusable action (`core/editor` store)', {
893+
alternative: '__experimentalConvertBlockToReusable action (`core/edtior` store)',
894+
plugin: 'Gutenberg',
895+
version: '4.4.0',
896+
hint: 'Using experimental APIs is strongly discouraged as they are subject to removal without notice.',
897+
} );
898+
899+
return __experimentalConvertBlockToReusable( id );
900+
}

packages/editor/src/store/effects/reusable-blocks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import { dispatch as dataDispatch } from '@wordpress/data';
2626
*/
2727
import { resolveSelector } from './utils';
2828
import {
29-
receiveReusableBlocks as receiveReusableBlocksAction,
29+
__experimentalReceiveReusableBlocks as receiveReusableBlocksAction,
3030
removeBlocks,
3131
replaceBlocks,
3232
receiveBlocks,
33-
saveReusableBlock,
33+
__experimentalSaveReusableBlock as saveReusableBlock,
3434
} from '../actions';
3535
import {
36-
getReusableBlock,
36+
__experimentalGetReusableBlock as getReusableBlock,
3737
getBlock,
3838
getBlocks,
3939
getBlocksByClientId,

0 commit comments

Comments
 (0)