Skip to content

Commit

Permalink
cluster fixes, would not update list on new cluster creation
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanWright committed Jun 20, 2016
1 parent a8197f0 commit 6aebfe5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/pages/Preferences/Cluster/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const ClusterPrefs = React.createClass({

clusterHasSimulation(id) {
for (let i = 0; i < this.props.taskflows.length; i++) {
if (this.props.taskflows[i].flow && this.props.taskflows[i].flow.meta.cluster._id === id) {
if (this.props.taskflows[i].flow && get(this.props.taskflows[i].flow, 'meta.cluster._id') === id) {
return this.props.taskflows[i].simulation;
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/redux/actions/taskflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,12 @@ client.onEvent((resp) => {
break;
}
case 'cluster': {
dispatch(clusterActions.updateClusterStatus(id, status));
if (status === 'created') {
// we need to fetch some new cluster props when this happens
dispatch(clusterActions.fetchCluster(id));
} else {
dispatch(clusterActions.updateClusterStatus(id, status));
}
break;
}
case 'profile': {
Expand Down
11 changes: 10 additions & 1 deletion src/redux/reducers/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,20 @@ export default function clustersReducer(state = initialState, action) {
}

case Actions.UPDATE_CLUSTER_STATUS: {
const list = [].concat(state.list);
const mapById = Object.assign({}, state.mapById);
const cluster = Object.assign({}, state.mapById[action.id]);
cluster.status = action.status;
mapById[action.id] = cluster;
return Object.assign({}, state, { mapById });
if (cluster.type === 'trad') {
for (let i = 0; i < list.length; i++) {
if (list[i]._id === action.id) {
list[i].status = action.status;
break;
}
}
}
return Object.assign({}, state, { list, mapById });
}

case Actions.CLUSTER_APPLY_PRESET: {
Expand Down
23 changes: 17 additions & 6 deletions test/redux/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ function setSpy(target, method, data) {
Object.freeze(initialState);

describe('cluster actions', () => {
const cluster = { _id: 'a1', name: 'myCluster',
const cluster = { _id: 'a1',
type: 'trad',
name: 'myCluster',
status: 'unknown',
log: [{ entry: 'created...' }, { entry: 'running...' }],
};
describe('simple actions', () => {
Expand Down Expand Up @@ -159,11 +162,19 @@ describe('cluster actions', () => {

// we only test the reducer here
it('should update a cluster\'s status', () => {
const thisState = Object.assign({}, initialState);
thisState.mapById = { a1: { status: 'created' } };
const action = { type: Actions.UPDATE_CLUSTER_STATUS, id: 'a1', status: 'terminated' };
expect(clustersReducer(thisState, action).mapById.a1.status)
.toEqual('terminated');
const newStatus = 'terminated';
const myCluster = deepClone(cluster);
const givenState = deepClone(initialState);
givenState.mapById[myCluster._id] = myCluster;
givenState.list.push(myCluster);

const expectedState = deepClone(givenState);
expectedState.mapById[myCluster._id].status = newStatus;
expectedState.list[0].status = newStatus;

const action = { type: Actions.UPDATE_CLUSTER_STATUS, id: cluster._id, status: newStatus };
expect(clustersReducer(givenState, action))
.toEqual(expectedState);
});
});

Expand Down

0 comments on commit 6aebfe5

Please sign in to comment.