Skip to content

Commit

Permalink
cluster list and mapById sync
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanWright committed Jun 22, 2016
1 parent efcdcae commit 96b23f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/redux/reducers/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ export default function clustersReducer(state = initialState, action) {
const list = [].concat(state.list);
const mapById = Object.assign({}, state.mapById);
mapById[newCluster._id] = newCluster;

if (newCluster.type === 'trad' && list.some((el) => el._id === newCluster._id)) {
for (let i = 0; i < list.length; i++) {
if (list[i]._id === newCluster._id) {
list[i].status = newCluster.status;
list[i] = newCluster;
updateIcon(list);
break;
}
}
Expand Down Expand Up @@ -178,7 +180,8 @@ export default function clustersReducer(state = initialState, action) {
if (cluster.type === 'trad') {
for (let i = 0; i < list.length; i++) {
if (list[i]._id === action.id) {
list[i].status = action.status;
list[i] = cluster;
updateIcon(list);
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/redux/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Actions from '../../src/redux/actions/clusters';
import clustersReducer, { clusterTemplate, initialState } from '../../src/redux/reducers/clusters';
import client from '../../src/network';
import * as ClusterHelpers from '../../src/network/helpers/clusters';
import style from 'HPCCloudStyle/PageWithMenu.mcss';

import expect from 'expect';
import thunk from 'redux-thunk';
Expand All @@ -26,6 +27,7 @@ describe('cluster actions', () => {
type: 'trad',
name: 'myCluster',
status: 'unknown',
classPrefix: '',
log: [{ entry: 'created...' }, { entry: 'running...' }],
};
describe('simple actions', () => {
Expand Down Expand Up @@ -171,7 +173,9 @@ describe('cluster actions', () => {

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

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

0 comments on commit 96b23f9

Please sign in to comment.