-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
Ideally, I'd like to avoid |
The action could take a callback. |
Okay, I guess we'll stick with the |
|
||
return ( dispatch, getState ) => { | ||
dispatch( { | ||
type: THEME_TRY_AND_CUSTOMIZE_ON_JETPACK_REQUEST, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
Suggested roadmap (see my inline comments for context):
|
36a8963
to
dbd96e5
Compare
Rebased. |
header: i18n.translate( 'Try & Customize on:', { | ||
comment: 'label in the dialog for opening the Customizer with the theme in preview' | ||
} ), | ||
action: tryAndCustomizeWpcomThemeOnJetpack, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
ac310a4
to
972a3f0
Compare
Rebased. |
* @param {String} siteId Jetpack Site ID | ||
* @return {Function} Action thunk | ||
*/ | ||
export function installWpcomThemeAndTryAndCustomize( themeId, siteId ) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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' ), |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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' ) ), |
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
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"
35d6054
to
ed0cad6
Compare
Rebased. |
Design wise: 👍 |
}; | ||
} | ||
|
||
export function tryAndCustomize( themeId, siteId ) { |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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 diff
erence.)
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. |
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.