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

Contact Info jetpack native blocks behind DEV flag #1934

Merged
merged 17 commits into from
Apr 17, 2020
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ symlinked-packages
symlinked-packages-in-parent
react-native-aztec
bundle
jetpack
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "gutenberg"]
path = gutenberg
url = ../../WordPress/gutenberg.git
[submodule "jetpack"]
path = jetpack
url = ../../Automattic/jetpack.git
1 change: 1 addition & 0 deletions jetpack
Submodule jetpack added at f6f313
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"classnames": "^2.2.5",
"dom-react": "^2.2.1",
"domutils": "^1.7.0",
"email-validator": "2.0.4",
"emotion": "^10.0.27",
"emotion-theming": "^10.0.27",
"fast-average-color": "^4.3.0",
Expand Down
4 changes: 3 additions & 1 deletion src/api-fetch-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const fetchHandler = ( { path }, retries = 20, retryCount = 1 ) => {
};

export const isPathSupported = ( path ) =>
[ /wp\/v2\/(media|categories)\/?\d*?.*/i ].some( ( pattern ) => pattern.test( path ) );
[ /wp\/v2\/(media|categories)\/?\d*?.*/i, /wpcom\/v2\/gutenberg\/.*/i ].some( ( pattern ) =>
pattern.test( path )
);

export default () => {
apiFetch.setFetchHandler( ( options ) => fetchHandler( options ) );
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import './globals';
import { getTranslation } from '../i18n-cache';
import initialHtml from './initial-html';
import setupApiFetch from './api-fetch-setup';
import setupJetpackEditor from './jetpack-editor-setup';

const gutenbergSetup = () => {
const wpData = require( '@wordpress/data' );
Expand Down Expand Up @@ -55,6 +56,7 @@ export class RootComponent extends React.Component {
super( props );
setupLocale( props.locale, props.translations );
setupApiFetch();
setupJetpackEditor( props.jetpackState || { blogId: 1, isJetpackActive: true } );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have to make this async when we actually fetch the data from the site, but for now let's keep it that way 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Just going to note here that if we make an async call to check if we're enabling jetpack blocks, then we need to block the action of parsing raw html to blocks until after that function returns, otherwise jetpack blocks will show up as not enabled, even if api response says they should be enabled.

require( '@wordpress/edit-post' ).initializeEditor();

const isHermes = () => global.HermesInternal !== null;
Expand Down
49 changes: 49 additions & 0 deletions src/jetpack-editor-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/** @format */

/**
* External dependencies
*/
/**
* Internal dependencies
*/
import { JETPACK_DATA_PATH } from '../jetpack/extensions/shared/get-jetpack-data';

const supportedJetpackBlocks = {
'contact-info': {
available: true,
},
};

const setJetpackData = ( {
isJetpackActive = false,
userData = null,
siteFragment = null,
blogId,
} ) => {
const availableBlocks = supportedJetpackBlocks;
const jetpackEditorInitialState = {
available_blocks: availableBlocks,
jetpack: {
is_active: isJetpackActive,
},
siteFragment,
tracksUserData: userData,
wpcomBlogId: blogId,
};
global.window[ JETPACK_DATA_PATH ] = jetpackEditorInitialState;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to ask you @Tug about this line since it's hard to understand with the API calls temporarily disabled. Are we utilizing global.window here so jetpack code can access jetpackEditorInitialState when initializing, similar to how they're doing it on the web side in jetpack/extensions/editor.js?

return jetpackEditorInitialState;
};

export default ( jetpackState ) => {
if ( ! jetpackState.isJetpackActive ) {
return;
}

const jetpackData = setJetpackData( jetpackState );

if ( __DEV__ ) {
require( '../jetpack/extensions/editor' );
}

return jetpackData;
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6430,6 +6430,11 @@ elliptic@^6.0.0:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.0"

[email protected]:
version "2.0.4"
resolved "https://registry.yarnpkg.com/email-validator/-/email-validator-2.0.4.tgz#b8dfaa5d0dae28f1b03c95881d904d4e40bfe7ed"
integrity sha512-gYCwo7kh5S3IDyZPLZf6hSS0MnZT8QmJFqYvbqlDZSbwdZlY6QZWxJ4i/6UhITOJ4XzyI647Bm2MXKCLqnJ4nQ==

emitter-listener@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/emitter-listener/-/emitter-listener-1.1.2.tgz#56b140e8f6992375b3d7cb2cab1cc7432d9632e8"
Expand Down