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

Support User: Add Redux integration #2512

Closed
wants to merge 6 commits into from
Closed

Conversation

jordwest
Copy link
Contributor

Previous PR: #2368

This change adds the Redux actions and reducer for the Support User UI in an upcoming PR. There are no changes to functionality in this PR.

Ref: p195om-2GO-p2

cc @gwwar

@jordwest jordwest added [Status] In Progress [Feature Group] Support All things related to WordPress.com customer support. labels Jan 18, 2016
@jordwest jordwest self-assigned this Jan 18, 2016
@jordwest jordwest added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Status] In Progress and removed [Status] In Progress [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 21, 2016
@jordwest jordwest force-pushed the add/support-user-redux branch from 1de7339 to 4df8b5c Compare January 21, 2016 02:12
@jordwest jordwest added [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 21, 2016
@gwwar
Copy link
Contributor

gwwar commented Jan 21, 2016

Also cc @aduth @dmsnell

@dllh
Copy link
Member

dllh commented Jan 21, 2016

I tested the functionality a bit and it's working as I'd expect. The code looks good to me, but I'd rather have more experienced eyes on it to thumbs up a merge.

login: ( username, password ) => user.changeUser( username, password, callback ),
logout: () => user.restoreUser()
login: ( ...args ) => reduxStore.dispatch( supportUserFetchToken( ...args ) ),
logout: ( ...args ) => reduxStore.dispatch( supportUserRestore( ...args ) )
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why you're hiding the function signature here?

Copy link
Member

Choose a reason for hiding this comment

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

Or go crazy and skip the arguments…

const storeDispatch = reduxStore.dispatch.bind( reduxStore );

window.supportUser = {
    login: compose( storeDispatch, supportUserFetchToken ),
    logout: compose( storeDispatch, supportUserRestore )
}

😄

@gwwar
Copy link
Contributor

gwwar commented Jan 21, 2016

👍 This looks pretty good to me and works. To be safe, I'd get another +1 from @aduth or @dmsnell.

Also, should we update the selector for current user to also know about the support user?

}
callback( error );
Copy link
Member

Choose a reason for hiding this comment

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

how about instead of merging this into a nested structure we just abort early

if ( error ) {
    return callback( error );
}

this.once( 'change', callback ); // no need to create a closure for calling callback
this.clear();
this.fetch();

@dmsnell
Copy link
Member

dmsnell commented Jan 21, 2016

Looks pretty good @jordwest - sure would be nice to see some tests here to verify this!

@dmsnell dmsnell added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 21, 2016
@jordwest jordwest force-pushed the add/support-user-redux branch 2 times, most recently from 88204bb to 0ea14b7 Compare January 22, 2016 08:20
export function supportUserRestore() {
let user = new User();
user.clear();
user.restoreUser();
Copy link
Contributor

Choose a reason for hiding this comment

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

There's quite a few side-effects occurring in the functions of this file. The action creators should really only be returning simple objects (or in the case of thunks, dispatching objects as asynchronously). It seems that these are needed for interoperability between the old-style user store, though I'd argue that we should start to manage the behavior of the current user exclusively from client/state/current-user.

Copy link
Member

Choose a reason for hiding this comment

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

I second what @aduth is saying here, though withheld my comments previously because it seemed to be mostly stage one in moving the legacy code to Redux. But consider this a plus one, a bump, or a thumbs-up to what he said 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thirded. I was also hesitant writing these calls in the action creators, but at this stage I can't think of another way around it until User and UserSettings libraries are fully connected to the Redux store. That looks like a fairly sizeable task in itself and at the moment HEs are pretty keen to start using this feature; would you both be happy with this as is for a temporary solution and we can revisit later?

Copy link
Member

Choose a reason for hiding this comment

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

That's fine with me, which is why I didn't originally bring it up. I'd rather have it here than in the store.

Copy link
Member

Choose a reason for hiding this comment

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

There's another issue with these intermediary steps that affect the purity of the state — for part of our offline strategy we are dumping state into storage and hydrating on boot, we are also exploring queues of actions to be replayed later on. Anything that affects what's expected of a pure redux flow would add obstacles in the way. I'm of the mind that as long as we have coexisting data structures we need to duplicate code and handle it in both places, or fully rework the old code to the new state tree.

@aduth
Copy link
Contributor

aduth commented Jan 22, 2016

Result of eslint client/state/support:

/Users/andrew/Documents/Code/wp-calypso/client/state/support/actions.js
  16:3   warning  Trailing spaces not allowed             no-trailing-spaces
  34:33  warning  "userData" is defined but never used    no-unused-vars
  34:46  warning  Trailing spaces not allowed             no-trailing-spaces
  37:42  warning  Trailing spaces not allowed             no-trailing-spaces
  58:1   warning  Missing JSDoc for parameter 'userData'  valid-jsdoc
  72:1   warning  Missing JSDoc for parameter 'error'     valid-jsdoc

/Users/andrew/Documents/Code/wp-calypso/client/state/support/reducer.js
  22:40  warning  "userData" is already declared in the upper scope  no-shadow
  29:1   warning  Trailing spaces not allowed                        no-trailing-spaces
  49:1   warning  Missing JSDoc parameter description for 'state'    valid-jsdoc
  49:1   warning  Missing JSDoc parameter description for 'action'   valid-jsdoc
  49:1   warning  Missing JSDoc return description                   valid-jsdoc

✖ 11 problems (0 errors, 11 warnings)

This change adds the Redux actions and reducer for the Support User
UI in an upcoming PR.
@jordwest jordwest force-pushed the add/support-user-redux branch from 7d8c4f7 to b81de33 Compare January 25, 2016 07:00
@jordwest
Copy link
Contributor Author

Thanks for the feedback @dllh, @gwwar, @mtias, @dmsnell, @aduth. Based on the discussion above, I went back to the drawing board and came up with a way to decouple the Redux store from the low-level parts, and re-implemented this PR in #2819. It removes any side-effects in the action creators, while a support-user-interop module observes the Redux store and passes any changes down to the wpcom module. Would appreciate any review :)

I'll close this PR for now as #2819 replaces it.

@jordwest jordwest closed this Jan 28, 2016
@lancewillett lancewillett deleted the add/support-user-redux branch February 15, 2016 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature Group] Support All things related to WordPress.com customer support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants