mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-18 04:49:55 +00:00
wip
This commit is contained in:
@@ -312,7 +312,6 @@ export function setResourceView() {
|
||||
}
|
||||
|
||||
export function clickNode(nodeId, label, origin) {
|
||||
console.log(nodeId, label, origin);
|
||||
return (dispatch, getState) => {
|
||||
dispatch({
|
||||
type: ActionTypes.CLICK_NODE,
|
||||
|
||||
@@ -25,5 +25,5 @@ if (module.hot) {
|
||||
}
|
||||
|
||||
if (process.env.DEMO) {
|
||||
runDemo(store.getState, store.dispatch);
|
||||
runDemo(store.dispatch, store.getState);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,52 @@
|
||||
import _ from 'lodash';
|
||||
import { clickNode } from '../actions/app-actions';
|
||||
import { clickNode, clickTopology, clickCloseDetails } from '../actions/app-actions';
|
||||
|
||||
const INTERVAL = 3000;
|
||||
const INTERVAL = 5000;
|
||||
|
||||
function openNodeDetails(getState, dispatch) {
|
||||
const action = clickNode();
|
||||
if (typeof action === 'function') {
|
||||
return action(dispatch, getState);
|
||||
function getRandomNode(getState) {
|
||||
const { nodes } = getState().toJS();
|
||||
return _.sample(nodes);
|
||||
}
|
||||
|
||||
function runAction(action, args, dispatch, getState) {
|
||||
const payload = action.apply(this, args);
|
||||
if (typeof payload === 'function') {
|
||||
return payload(dispatch, getState);
|
||||
}
|
||||
|
||||
return dispatch(action);
|
||||
return dispatch(payload);
|
||||
}
|
||||
|
||||
const actions = [openNodeDetails];
|
||||
function openNodeDetails(dispatch, getState, run, next) {
|
||||
const { id, label } = getRandomNode(getState);
|
||||
run(clickNode, [id, label]);
|
||||
setTimeout(() => {
|
||||
run(clickCloseDetails, [id]);
|
||||
next();
|
||||
}, INTERVAL * 2);
|
||||
}
|
||||
|
||||
export default function runDemo(getState) {
|
||||
setInterval(() => {
|
||||
const state = getState().toJS();
|
||||
const fn = _.sample(actions);
|
||||
function changeTopology(dispatch, getState, run, next) {
|
||||
const blacklist = ['hosts', 'weave', 'containers-by-hostname'];
|
||||
const { topologies } = getState().toJS();
|
||||
const subTopologies = _.reduce(topologies, (result, t) => {
|
||||
if (t.sub_topologies) {
|
||||
return result.concat(t.sub_topologies);
|
||||
}
|
||||
return result;
|
||||
}, []);
|
||||
const all = _.filter(topologies.concat(subTopologies), i => !_.includes(blacklist, i.id));
|
||||
run(clickTopology, [_.sample(all).id]);
|
||||
next();
|
||||
}
|
||||
|
||||
const demos = [openNodeDetails, changeTopology];
|
||||
|
||||
export default function runDemo(dispatch, getState) {
|
||||
setTimeout(() => {
|
||||
const fn = _.sample(demos);
|
||||
const run = _.partialRight(runAction, dispatch, getState);
|
||||
const next = runDemo.bind(runDemo, dispatch, getState);
|
||||
fn(dispatch, getState, run, next);
|
||||
}, INTERVAL);
|
||||
}
|
||||
|
||||
@@ -304,6 +304,7 @@ export function getApiDetails(dispatch) {
|
||||
}
|
||||
|
||||
export function doControlRequest(nodeId, control, dispatch) {
|
||||
console.log(nodeId, control);
|
||||
clearTimeout(controlErrorTimer);
|
||||
const url = `${getApiPath()}/api/control/${encodeURIComponent(control.probeId)}/`
|
||||
+ `${encodeURIComponent(control.nodeId)}/${control.id}`;
|
||||
|
||||
Reference in New Issue
Block a user