Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block-Editor: reorder Jetpack and CoBlocks categories #37057

Merged
merged 4 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions apps/wpcom-block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ There are two environments the block editor integration supports:
- `disable-nux-tour.js`: Disable the pop-up tooltip tour that is displayed on first use.
- `rich-text.js`: Extensions for the Rich Text toolbar with the Calypso buttons missing on Core (i.e. underline, justify).
- `switch-to-classic.js`: Append a button to the "More tools" menu for switching to the classic editor.
- `tracking`: Adds analytics around specific user actions for Simple, Jetpack and Atomic sites.
- `reorder-block-categories`: Moves Jetpack and CoBlocks Block Categories below Core Categories
- `unregister-experimental-blocks`: Removes some experimental blocks from the Gutenberg Plugin.

### Calypso utilities

Expand Down
5 changes: 3 additions & 2 deletions apps/wpcom-block-editor/src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* Internal dependencies
*/
import './disable-nux-tour';
import './reorder-block-categories';
import './rich-text';
import './switch-to-classic';
import './style.scss';
import './unregister-experimental-blocks';
import './switch-to-classic';
import './tracking';
import './unregister-experimental-blocks';
47 changes: 47 additions & 0 deletions apps/wpcom-block-editor/src/common/reorder-block-categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable import/no-extraneous-dependencies */
/**
* External dependencies
*/
import { getCategories, setCategories } from '@wordpress/blocks';
import domReady from '@wordpress/dom-ready';

const categorySlugs = [ 'jetpack', 'coblocks', 'coblocks-galleries' ];

// Very fragile checks, we'll replace with proper common bundle splitting in https://github.com/Automattic/wp-calypso/issues/34476
const isSimpleSite = !! window.wpcomGutenberg.pluginVersion;
const isAtomicSite = window._currentSiteType === 'atomic';

if ( isAtomicSite || isSimpleSite ) {
domReady( function() {
//preserve order of other columns, and split matching
const { core: coreCategories, custom: unsorted } = getCategories().reduce(
( { core, custom }, category ) => {
const isCustomCategory = categorySlugs.includes( category.slug );
if ( isCustomCategory ) {
return {
core,
custom: [ ...custom, category ],
};
}
return {
core: [ ...core, category ],
custom,
};
},
{ custom: [], core: [] }
);
//sort once following order of categorySlugs
const customCategories = unsorted.sort( ( { slug }, { slug: slugB } ) => {
const index = categorySlugs.indexOf( slug );
const indexB = categorySlugs.indexOf( slugB );
if ( index === indexB ) {
return 0;
}
if ( index < indexB ) {
return -1;
}
return 1;
} );
setCategories( [ ...coreCategories, ...customCategories ] );
} );
}