From 8b1ca73179defc034048ea74ea752800af19e2b8 Mon Sep 17 00:00:00 2001 From: jpellizzari Date: Thu, 9 Feb 2017 13:44:30 -0800 Subject: [PATCH] Added changeInstance action; exported actions to public API --- client/app/scripts/actions/app-actions.js | 12 ++++++++++++ client/app/scripts/index.js | 2 +- client/app/scripts/utils/web-api-utils.js | 7 ++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/client/app/scripts/actions/app-actions.js b/client/app/scripts/actions/app-actions.js index 9f9f5f35e..300c4bbfe 100644 --- a/client/app/scripts/actions/app-actions.js +++ b/client/app/scripts/actions/app-actions.js @@ -681,3 +681,15 @@ export function toggleTroubleshootingMenu(ev) { type: ActionTypes.TOGGLE_TROUBLESHOOTING_MENU }; } + +export function changeInstance() { + return (dispatch, getState) => { + const state = getState(); + getNodesDelta( + getCurrentTopologyUrl(state), + getActiveTopologyOptions(state), + dispatch, + true // forces websocket teardown and reconnect to new instance + ); + }; +} diff --git a/client/app/scripts/index.js b/client/app/scripts/index.js index 9e4525628..7f5362bfe 100644 --- a/client/app/scripts/index.js +++ b/client/app/scripts/index.js @@ -1,3 +1,3 @@ exports.reducer = require('./reducers/root').default; exports.Scope = require('./components/app').default; -exports.ActionTypes = require('./constants/action-types').default; +exports.actions = require('./actions/app-actions'); diff --git a/client/app/scripts/utils/web-api-utils.js b/client/app/scripts/utils/web-api-utils.js index 8f40d4e50..1b7cbe95c 100644 --- a/client/app/scripts/utils/web-api-utils.js +++ b/client/app/scripts/utils/web-api-utils.js @@ -166,11 +166,12 @@ export function getTopologies(options, dispatch) { }); } -export function getNodesDelta(topologyUrl, options, dispatch) { +export function getNodesDelta(topologyUrl, options, dispatch, forceReload) { const optionsQuery = buildOptionsQuery(options); + // only recreate websocket if url changed or if forced (weave cloud instance reload); + const isNewUrl = topologyUrl && (topologyUrl !== currentUrl || currentOptions !== optionsQuery); - // only recreate websocket if url changed - if (topologyUrl && (topologyUrl !== currentUrl || currentOptions !== optionsQuery)) { + if (forceReload || isNewUrl) { createWebsocket(topologyUrl, optionsQuery, dispatch); currentUrl = topologyUrl; currentOptions = optionsQuery;