Added changeInstance action; exported actions to public API

This commit is contained in:
jpellizzari
2017-02-09 13:44:30 -08:00
parent d91fc5c310
commit 8b1ca73179
3 changed files with 17 additions and 4 deletions

View File

@@ -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
);
};
}

View File

@@ -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');

View File

@@ -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;