Skip to content

Commit 2cda95b

Browse files
authored
Block-Editor: reorder Jetpack and CoBlocks categories (#37057)
1 parent a50e94d commit 2cda95b

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

apps/wpcom-block-editor/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ There are two environments the block editor integration supports:
2121
- `disable-nux-tour.js`: Disable the pop-up tooltip tour that is displayed on first use.
2222
- `rich-text.js`: Extensions for the Rich Text toolbar with the Calypso buttons missing on Core (i.e. underline, justify).
2323
- `switch-to-classic.js`: Append a button to the "More tools" menu for switching to the classic editor.
24+
- `tracking`: Adds analytics around specific user actions for Simple, Jetpack and Atomic sites.
25+
- `reorder-block-categories`: Moves Jetpack and CoBlocks Block Categories below Core Categories
26+
- `unregister-experimental-blocks`: Removes some experimental blocks from the Gutenberg Plugin.
2427

2528
### Calypso utilities
2629

apps/wpcom-block-editor/src/common/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* Internal dependencies
33
*/
44
import './disable-nux-tour';
5+
import './reorder-block-categories';
56
import './rich-text';
6-
import './switch-to-classic';
77
import './style.scss';
8-
import './unregister-experimental-blocks';
8+
import './switch-to-classic';
99
import './tracking';
10+
import './unregister-experimental-blocks';
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
/**
3+
* External dependencies
4+
*/
5+
import { getCategories, setCategories } from '@wordpress/blocks';
6+
import domReady from '@wordpress/dom-ready';
7+
8+
const categorySlugs = [ 'jetpack', 'coblocks', 'coblocks-galleries' ];
9+
10+
// Very fragile checks, we'll replace with proper common bundle splitting in https://github.com/Automattic/wp-calypso/issues/34476
11+
const isSimpleSite = !! window.wpcomGutenberg.pluginVersion;
12+
const isAtomicSite = window._currentSiteType === 'atomic';
13+
14+
if ( isAtomicSite || isSimpleSite ) {
15+
domReady( function() {
16+
//preserve order of other columns, and split matching
17+
const { core: coreCategories, custom: unsorted } = getCategories().reduce(
18+
( { core, custom }, category ) => {
19+
const isCustomCategory = categorySlugs.includes( category.slug );
20+
if ( isCustomCategory ) {
21+
return {
22+
core,
23+
custom: [ ...custom, category ],
24+
};
25+
}
26+
return {
27+
core: [ ...core, category ],
28+
custom,
29+
};
30+
},
31+
{ custom: [], core: [] }
32+
);
33+
//sort once following order of categorySlugs
34+
const customCategories = unsorted.sort( ( { slug }, { slug: slugB } ) => {
35+
const index = categorySlugs.indexOf( slug );
36+
const indexB = categorySlugs.indexOf( slugB );
37+
if ( index === indexB ) {
38+
return 0;
39+
}
40+
if ( index < indexB ) {
41+
return -1;
42+
}
43+
return 1;
44+
} );
45+
setCategories( [ ...coreCategories, ...customCategories ] );
46+
} );
47+
}

0 commit comments

Comments
 (0)