-
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
Remove Olark #21488
Remove Olark #21488
Conversation
Test live: https://calypso.live/?branch=remove/olark |
Yes, I think the |
The entanglements are on the backend, is that what you mean? I haven't found any on Calypso side. The best course of action seems to be to move the mine endpoint querying to |
Right, the entanglements I'm thinking of are on the back end (if indeed they're still intact). |
@jsnajdr Thats how I see it. I don't think |
The PR is ready for review! 🎉 I added a All the other commits are just deleting stuff. I recommend to review commit-by-commit. I divided the task into small easy-to-review bites and there is a detailed description in each commit message. Here are some stats on how the size of Javascript we ship to our users decreased: |
It's been replaced with `HelpContactClosed` and is no longer used. Removing it removes one of remaining usages of `lib/olark`.
This patch removes the only usage of `OlarkChatbox` component from `HelpContact`. The `canShowChatbox` method always returns `false`, because: 1. `isChatEnded` initial value is `false` and no Olark event is ever dispatched to set it to `true` -- `onCommandFromOperator` is never called. 2. `olark.details.isConversing` is always undefined, because `olark.details` is initialized to empty object and the `OLARK_DETAILS` action is never dispatched. After removing the only remaining usage, we also remove the component itself.
As no Olark events are ever emitted, we can remove listeners and all code used only by them from the `HelpContact` component.
…lp-contact Many Olark actions are defined as noop function, we can remove the calls. The conditions `olark.isOperatorAvailable` and `olark.details.isConversing` are always false: their initial value in the Olark store is `false` and the actions to update them are never dispatched.
This variation is no longer ever used, so we can remove all code that depends on it.
The `QueryOlark` components dispatches a `requestOlark` action, which in turn dispatches `olarkTimeout` -- setting Olark status to `timeout` immediately without attempting any real request. The Olark info is no longer needed in `hasDataToDetermineVariation` and it would be always `true` anyway, because `olarkTimedOut` is set to `true` by `QueryOlark`. All the code mentioned above can be removed.
…e it in Redux Use the Olark REST endpoint to fetch `isUserEligible` property and store it in Redux in `state.happychat.user.isEligible`. Replace places where the eligibility is retrieved using the `lib/olark` library with the new Redux actions and selectors. The eligibility is requested on Calypso startup and updated after removing a purchase. It's used to determine the value of `isHappychatAvailable` and the `HelpContact` components waits until it's fetched (i.e., becomes not `null`) before deciding which support variation to use. This patch removes the last usage of `lib/olark` in Calypso.
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.
Went through the code and so far, it's looking good. I'm going to smoke test a bit.
Btw, I found one more occurrence of "olark" in codebase in client/boot/README
. You can remove that as well. :)
Btw 2, nice commits. :)
}; | ||
export const clearPurchases = () => dispatch => { | ||
dispatch( { type: PURCHASES_REMOVE } ); | ||
dispatch( requestHappychatEligibility() ); |
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.
Is the TODO message about side effects not relevant anymore?
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.
Yes, I believe it's not relevant any more.
Before this patch, the Olark function was called in the action creator -- you didn't even need to dispatch the action to execute it (!). Very hacky. Now it's a classic thunk that dispatches two Redux actions. Nothing unusual any more. Converting the request to data layer would be even better, but I didn't have any energy left to do that :)
During boot, the |
Yes, but it's not "loading various helpers (olark..)" which sounds like something bigger is being loaded. Anyways, a very minor detail. |
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.
Tested by opening a chat window. Working fine.
@@ -219,6 +219,7 @@ export const HAPPINESS_ENGINEERS_FETCH_SUCCESS = 'HAPPINESS_ENGINEERS_FETCH_SUCC | |||
export const HAPPINESS_ENGINEERS_RECEIVE = 'HAPPINESS_ENGINEERS_RECEIVE'; | |||
export const HAPPYCHAT_BLUR = 'HAPPYCHAT_BLUR'; | |||
export const HAPPYCHAT_FOCUS = 'HAPPYCHAT_FOCUS'; | |||
export const HAPPYCHAT_ELIGIBILITY_SET = 'HAPPYCHAT_ELIGIBILITY_SET'; |
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 context: there is the happychat-client project which is going to be the source of truth for Happychat customer facing code. In a few weeks, Calypso will be modified to use this library and the only code remaining will be Calypso-specific.
In that context, I've been namespacing the action names. At the moment, Calypso code doesn't have any Happychat user actions, but it will, and I've been using HAPPYCHAT_USER_*
for them. With that in mind, can this be renamed to HAPPYCHAT_USER_ELIGIBILITY
?
isEligible, | ||
} ); | ||
|
||
export const requestHappychatEligibility = () => dispatch => { |
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 context: there is the happychat-client project which is going to be the source of truth for Happychat customer facing code. In a few weeks, Calypso will be modified to use this library and the only code remaining will be Calypso-specific.
In that context, I've been decoupling Calypso-specific code into middleware-calypso, all the rest should be Calypso-agnostic. Can this be refactored for the Olark request to be fired on middleware-calypso?
The HAPPYCHAT_USER_ELIGIBILITY
actions are still valuable because this is something we'll need in every host, so I'll take care of merging these actions in the consolidated state.user
for happychat-client.
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.
Follow-up: the requestChatEligibility
could be either a Happychat or a host (Calypso, WordPress, etc) action. I'll probably lean towards that being a host action, but I haven't thought about it deeply yet, so use whatever works for you at the moment - I can refactor that later if needed.
@@ -29,4 +29,12 @@ export const geoLocation = createReducer( | |||
geoLocationSchema | |||
); | |||
|
|||
export default combineReducers( { geoLocation } ); | |||
export const isEligible = createReducer( |
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.
As mentioned above: this code is going to be pulled from Calypso in a few weeks to happychat-client. We aren't using the custom Calypso state utils, but the canonical Redux ones. At the moment, we don't have a schema or a mechanism to store the state in the browser localStorage either. Can this be refactored to use the canonical Redux utils instead and remove the schema utils as well?
@@ -8,12 +8,17 @@ import { get } from 'lodash'; | |||
* Internal dependencies | |||
*/ | |||
import isHappychatClientConnected from 'state/happychat/selectors/is-happychat-client-connected'; | |||
import isHappychatUserEligible from 'state/happychat/selectors/is-happychat-user-eligible'; | |||
|
|||
/** | |||
* Returns true if Happychat client is connected and server is available to take new chats | |||
* @param {Object} state - global redux state | |||
* @return {Boolean} Whether new chats can be taken | |||
*/ | |||
export default function( state ) { |
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.
There are use cases where we'll need happychat availability and user eligibility separately, so we'll need a new selector is-user-eligible-for-happychat
(and don't modify is-happychat-available
).
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.
Just saw the is-happychat-user-eligible
selector. We'll need to revert the changes to is-happychat-available
, though.
olark.isUserEligible && | ||
this.props.isSelectedHelpSiteOnPaidPlan | ||
); | ||
return this.props.isHappychatAvailable && this.props.isSelectedHelpSiteOnPaidPlan; |
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 will need the isHappychatUserEligible
selector when the changes in isHappychatAvailable
are reverted.
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.
Thanks for this!
-
Most my comments address the fact that in a couple of weeks customer facing Happychat code will be removed from Calypso in favor of the happychat-client library. For that reason, in the past months, I've been trying to isolate Calypso-specific code into middleware-calypso. If you don't have the time to address them, no worries, I will in future PRs.
-
The one thing we need to do before landing this PR is separating user eligibility from the
is-happychat-available
selector. There may be places where we want to check one but the other - for example: in a pre-sales context, a user may not have any plan yet but we may want to upsell them things in a chat session. That's from a Calypso point-of-view; thinking about the host-agnostic API for Happychat, it makes sense to have both separated as well. -
I also saw a couple of comments about Olark that don't hold true anymore in
client/boot/README
andclient/me/help/help-contact/index.jsx
. It'd be nice if we could remove them as well.
@nosolosw I removed the remaining Olark mentions from comments and readmes, and made the There are a few places where a I didn't remove the Calypso-specific Thanks for your review and please have another look whenever you can. |
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.
Code looks good. Started a Happychat session, sent a Zendesk ticket, and loaded the Directly widget. Everything works properly. 🚢
In this PR, I'm removing Olark from Calypso in small, easy-to-review steps.
I start with the following observations:
olark-events
module doesn't ever emit any events. All listeners are noops.olark-store/actions
are noops.olark-store/actions
are never dispatched and mostolark-store
properties keep their initial value forever.Based on this, I can gradually remove large parts of code that are provably never called and I'm close to being able to remove the whole
lib/olark
,lib/olark-store
,lib/olark-events
andstate/ui/olark
libraries.There's only one bit of code that still does something: the
/help/olark/mine
REST endpoint returns aisUserEligible
flag that is used to decide if HappyChat should be displayed to the user.The user is eligible if the following conditions hold:
live-support
stickerlivechat_options
admin page, but that might change.The endpoint is queried on Calypso startup, and then when a purchase is removed. It's not queried when a purchase is added, which looks like a bug -- if I add a paid plan purchase to a user account that didn't have any, HappyChat won't be available until page reload.
Then Calypso has some further conditions before HappyChat is offered to the user -- the connection to the server must be active, there must be a HE available and the site that help is requested for must be on a paid plan.
@dllh is the author of the wpcom code for
/help/olark/mine
. I assume that endpoint still needs to be consulted for HappyChat eligibility?Fixes #21153
If the
isUserEligible
issue is resolved, removing the rest of Olark from Calypso is going to be trivial.