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

Try and Customize WP.com theme on Jetpack. #10126

Merged
merged 25 commits into from
Jan 6, 2017

Conversation

budzanowski
Copy link
Contributor

@budzanowski budzanowski commented Dec 16, 2016

Info

Implements Try&Customize feature for Wpcom themes on Jetpack site.

Test

Open Jetpack site /design on calypso, click ellipsis menu and chose Try and Customize this should move user to try&customize page.

On internal falure this will show error banner to the user. @folletto - request for designer approval.
retry

@budzanowski budzanowski added the [Feature Group] Appearance & Themes Features related to the appearance of sites. label Dec 16, 2016
@budzanowski budzanowski added this to the Themes: JetPress Rally milestone Dec 16, 2016
@budzanowski budzanowski self-assigned this Dec 16, 2016
@matticbot
Copy link
Contributor

@ockham
Copy link
Contributor

ockham commented Dec 16, 2016

Ideally, I'd like to avoid page and getState inside the action. The '...' menu actually supports action and getUrl in an option at the same time, see here. The main problem here is the async nature of the action...

@seear
Copy link
Contributor

seear commented Dec 16, 2016

Ideally, I'd like to avoid page and getState inside the action.

The action could take a callback.

@ockham
Copy link
Contributor

ockham commented Dec 16, 2016

Okay, I guess we'll stick with the page call and the getState for now since I can't think of anything that makes this any better (callback would alter option shape for all other options inside theme-options, unless I'm reading you wrong, @seear).


return ( dispatch, getState ) => {
dispatch( {
type: THEME_TRY_AND_CUSTOMIZE_ON_JETPACK_REQUEST,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is where I really wish we had a separate install action that we'd just use here to .then( page ( /*...*/ ), since the entire tryAndCustomizeWpcomThemeOnJetpack action is really just that. I'll provide some more rationale -- with the new middleware-based error handling (#10018), I currently have to listen to THEME_ACTIVATE_REQUEST_FAILURE, even though what I really am listening for is errors resulting from a failed install. This is because activateWpcomThemeOnJetpack dispatches those THEME_ACTIVATE_ actions even while it's installing.

Much rather than adding a listener for THEME_TRY_AND_CUSTOMIZE_ON_JETPACK_REQUEST on top of the one that listens to THEME_ACTIVATE_REQUEST_FAILURE while both are still really just listening to failed installation, I think we should finally introduce the installWpcomThemeOnJetpack action along with properly named action name constants, and compose both activateWpcomThemeOnJetpack and tryAndCustomizeWpcomThemeOnJetpack from it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should finally introduce the installWpcomThemeOnJetpack action along with properly named action name constants, and compose both activateWpcomThemeOnJetpack and tryAndCustomizeWpcomThemeOnJetpack from it.

Yeah, I would suggest that now we have the two lists and install working, we can take the time to do this properly.

//Add -wpcom suffix. This suffix tells the endpoint that we want to
//install WordPress.com theme. Without the suffix endpoint would look
//for theme in .org
const suffixedThemeId = themeId + '-wpcom';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can actually keep this function generic -- maybe at some point we really want to install a theme from WP.org; we'll be able to re-use this function then. It's easy enough for the consumer to add the prefix themselves.

@ockham
Copy link
Contributor

ockham commented Dec 16, 2016

Suggested roadmap (see my inline comments for context):

  • Let's get Themes, Actions: Install WP.com theme on Jetpack action. #9924 in. That's the installTheme action along with tests and everything we could ever dream of. It seems like we're also going to need install state for UI purposes (for Try & Customize), too.
  • Let's rebase this one on it and implement tryAndCustomizeWpcomThemeOnJetpack as installTheme.then( page ( ) ), essentially. activateWpcomThemeOnJetpack will be installTheme and activateTheme.
  • Framework: bump localforage to 1.4.3 #10018 can then listen to THEME_INSTALL_REQUEST_FAILURE (instead of THEME_ACTIVATE_REQUEST_FAILURE which is misleading) to cover both cases.
  • Also, let's just call them installTheme (could be conceivably a WP.org theme too in the future), installAndActivate, and installAndTryAndCustomize.

@budzanowski
Copy link
Contributor Author

Rebased.

header: i18n.translate( 'Try & Customize on:', {
comment: 'label in the dialog for opening the Customizer with the theme in preview'
} ),
action: tryAndCustomizeWpcomThemeOnJetpack,
Copy link
Contributor

Choose a reason for hiding this comment

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

What about dropping the installWpcomThemeAndTryAndCustomize wrapper and doing

action: ( themeId, siteId ) => {
	installAndTryAndCustomize( themeId + '-wpcom', siteId )
}

here?

function installAndTryAndCustomize( themeId, siteId ) {
return ( dispatch, getState ) => {
dispatch( {
type: THEME_TRY_AND_CUSTOMIZE_ON_JETPACK_REQUEST,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd go as far as considering dropping state handling (i.e. dispatching THEME_TRY_AND_CUSTOMIZE_ON_JETPACK_REQUEST* in this function) and really just compose it from installTheme and that page call. I don't think we lose any information that way.

@hoverduck hoverduck added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 21, 2016
@ockham ockham added [Status] In Progress and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 3, 2017
@budzanowski budzanowski force-pushed the add/try-and-customize-on-jetpack branch from ac310a4 to 972a3f0 Compare January 4, 2017 13:34
@budzanowski
Copy link
Contributor Author

Rebased.

* @param {String} siteId Jetpack Site ID
* @return {Function} Action thunk
*/
export function installWpcomThemeAndTryAndCustomize( themeId, siteId ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency's sake, let's nix the wrapper and add the suffix in theme-options (like so)

@@ -404,6 +405,44 @@ export function clearActivated( siteId ) {
}

/**
* Triggers a network request to install WordPress.com theme on Jetpack site.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be .com/.org agnostic: let's s/WordPress.com/a/

comment: 'label in the dialog for opening the Customizer with the theme in preview'
} ),
action: installWpcomThemeAndTryAndCustomize,
hideForSite: ( state, siteId ) => ! canCurrentUser( state, siteId, 'edit_theme_options' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also hide if ! isJetpackSite( state, siteId ), just to be sure.

return;
}
const url = getThemeCustomizeUrl( getState(), theme, siteId );
page( url );
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to modularize things, you could put the contents of the .then() statement into a separate action. That might simplify testing a bit.

.then( () => {
const theme = getTheme( getState(), siteId, themeId );
if ( ! theme ) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to dispatch a _FAILURE here (to show an error message, e.g. thru the notices middleware)?

(If we do dispatch a FAILURE, this should really be a separate action, see my other comment.)

@@ -175,6 +176,7 @@ export const handlers = {
[ PUBLICIZE_CONNECTION_UPDATE_FAILURE ]: onPublicizeConnectionUpdateFailure,
[ GUIDED_TRANSFER_HOST_DETAILS_SAVE_SUCCESS ]: dispatchSuccess( translate( 'Thanks for confirming those details!' ) ),
[ SITE_FRONT_PAGE_SET_FAILURE ]: dispatchError( translate( 'An error occurred while setting the homepage' ) ),
[ THEME_TRY_AND_CUSTOMIZE_FAILURE ]: dispatchError( translate( 'An error occured while trying to customize theme' ) ),
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be shortened to 'Error customizing theme'.

Copy link
Contributor

Choose a reason for hiding this comment

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

We had a quick chat. Following the rule of thumb of always give an indication to the user on "what can I do now" instead of blunt error messages, let's go with:

"Error customizing theme, check with support"

@budzanowski budzanowski force-pushed the add/try-and-customize-on-jetpack branch from 35d6054 to ed0cad6 Compare January 5, 2017 12:21
@budzanowski
Copy link
Contributor Author

Rebased.

@budzanowski budzanowski added [Status] Needs Design Review Add this when you'd like to get a review / feedback from the Design team on your PR [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Jan 5, 2017
@folletto
Copy link
Contributor

folletto commented Jan 5, 2017

Design wise: 👍

@folletto folletto removed the [Status] Needs Design Review Add this when you'd like to get a review / feedback from the Design team on your PR label Jan 5, 2017
};
}

export function tryAndCustomize( themeId, siteId ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

JSDoc pls? 😄 Sry for nagging, but it's the only function without one in this file, I think...

@@ -871,4 +874,144 @@ describe( 'actions', () => {
} );
} );
} );

describe( '#installAndTryAndCustomize', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We've discussed this before, but would you consider changing this test to only check if installTheme and tryAndCustomizeTheme are dispatched (much like the installAndActivate test does)? I think that's the actual unit we're testing here. In addition, you could add a test just for tryAndCustomize that does the spying on page and covers the failure case.

(This way, we might get away without mockery and redux-mock-store.)

@@ -181,6 +181,7 @@
"react-addons-test-utils": "15.4.0",
"react-hot-loader": "1.3.0",
"react-test-env": "0.2.0",
"redux-mock-store": "1.2.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

If we decide to keep this, do we need to make shrinkwrap? (I'm not sure if it's required for devDependencies, but you could try and see if it makes a difference.)

@ockham
Copy link
Contributor

ockham commented Jan 5, 2017

Code looks good. Left a note on testing since I think the new unit test is a bit big and checks a bit more than it needs to.

@budzanowski budzanowski merged commit cf66c9a into master Jan 6, 2017
@budzanowski budzanowski deleted the add/try-and-customize-on-jetpack branch January 7, 2017 12:04
@lancewillett lancewillett removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jan 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature Group] Appearance & Themes Features related to the appearance of sites.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants