Skip to content

Commit

Permalink
Merge pull request #2713 from weaveworks/2708-reset-nodes-when-scope-…
Browse files Browse the repository at this point in the history
…app-restarted

Reset nodes in frontend when scope-app restarted
  • Loading branch information
rndstr authored Jul 14, 2017
2 parents a3cd457 + 5329efa commit a6d3542
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/app/scripts/actions/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export function receiveNodesDelta(delta) {
dispatch({ type: ActionTypes.FINISH_TIME_TRAVEL_TRANSITION });
}

const hasChanges = delta.add || delta.update || delta.remove;
const hasChanges = delta.add || delta.update || delta.remove || delta.reset;
if (hasChanges) {
dispatch({
type: ActionTypes.RECEIVE_NODES_DELTA,
Expand Down
7 changes: 6 additions & 1 deletion client/app/scripts/reducers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,12 @@ export function rootReducer(state = initialState, action) {
log('RECEIVE_NODES_DELTA',
'remove', size(action.delta.remove),
'update', size(action.delta.update),
'add', size(action.delta.add));
'add', size(action.delta.add),
'reset', action.delta.reset);

if (action.delta.reset) {
state = state.set('nodes', makeMap());
}

// remove nodes that no longer exist
each(action.delta.remove, (nodeId) => {
Expand Down
3 changes: 2 additions & 1 deletion render/detailed/topology_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ type Diff struct {
Add []NodeSummary `json:"add"`
Update []NodeSummary `json:"update"`
Remove []string `json:"remove"`
Reset bool `json:"reset,omitempty"`
}

// TopoDiff gives you the diff to get from A to B.
func TopoDiff(a, b NodeSummaries) Diff {
diff := Diff{}
diff := Diff{Reset: a == nil}

notSeen := map[string]struct{}{}
for k := range a {
Expand Down
16 changes: 16 additions & 0 deletions render/detailed/topology_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ func TestTopoDiff(t *testing.T) {
Update: []detailed.NodeSummary{nodeap},
},
},
{
label: "no previous nodes",
have: detailed.TopoDiff(nil, nodes(nodea)),
want: detailed.Diff{
Add: []detailed.NodeSummary{nodea},
Reset: true,
},
},
{
label: "empty previous nodes",
have: detailed.TopoDiff(nodes(), nodes(nodea)),
want: detailed.Diff{
Add: []detailed.NodeSummary{nodea},
Reset: false,
},
},
} {
sort.Strings(c.have.Remove)
sort.Sort(ByID(c.have.Add))
Expand Down

0 comments on commit a6d3542

Please sign in to comment.