Make the Manage Integrations Button defer scalar auth to the manager

This moves the responsibility of creating a URL to open from the button (and other components) to the integrations manager dialog itself.

By doing this, we also cut down on scalar API calls because we don't pick up on account information until the user opens the dialog.
This commit is contained in:
Travis Ralston 2019-06-17 15:29:19 -06:00
parent 6cc443cd01
commit a5f296457f
5 changed files with 125 additions and 80 deletions

View file

@ -29,6 +29,14 @@ class ScalarAuthClient {
this.scalarToken = null;
}
/**
* Determines if setting up a ScalarAuthClient is even possible
* @returns {boolean} true if possible, false otherwise.
*/
static isPossible() {
return SdkConfig.get()['integrations_rest_url'] && SdkConfig.get()['integrations_ui_url'];
}
connect() {
return this.getScalarToken().then((tok) => {
this.scalarToken = tok;
@ -41,7 +49,8 @@ class ScalarAuthClient {
// Returns a scalar_token string
getScalarToken() {
const token = window.localStorage.getItem("mx_scalar_token");
let token = this.scalarToken;
if (!token) token = window.localStorage.getItem("mx_scalar_token");
if (!token) {
return this.registerForToken();