Skip to content

Commit

Permalink
Update actions to use PK when working with nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
bryfox committed Jul 31, 2018
1 parent 214d0e1 commit fc316d8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/ducks/modules/__tests__/network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('network reducer', () => {
},
{
type: actionTypes.REMOVE_NODE,
uid: 2,
[PK]: 2,
},
),
).toEqual({
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('network reducer', () => {
},
{
type: actionTypes.TOGGLE_NODE_ATTRIBUTES,
uid: 1,
[PK]: 1,
attributes: { stage: 1 },
},
);
Expand All @@ -136,7 +136,7 @@ describe('network reducer', () => {
},
{
type: actionTypes.TOGGLE_NODE_ATTRIBUTES,
uid: 2,
[PK]: 2,
attributes: { stage: 1 },
},
);
Expand Down
5 changes: 3 additions & 2 deletions src/ducks/modules/__tests__/sessions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import reducer, { actionCreators, actionTypes } from '../sessions';
import { NodePK } from '../network';
import uuidv4 from '../../../utils/uuid';

const middlewares = [thunk];
Expand Down Expand Up @@ -161,7 +162,7 @@ describe('sessions actions', () => {
const expectedAction = {
type: actionTypes.TOGGLE_NODE_ATTRIBUTES,
sessionId: 'a',
uid: 2,
[NodePK]: 2,
attributes: {},
};

Expand All @@ -175,7 +176,7 @@ describe('sessions actions', () => {
const expectedAction = {
type: actionTypes.REMOVE_NODE,
sessionId: 'a',
uid: 2,
[NodePK]: 2,
};

store.dispatch(actionCreators.removeNode(2));
Expand Down
6 changes: 3 additions & 3 deletions src/ducks/modules/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export default function reducer(state = initialState, action = {}) {
};
}
case TOGGLE_NODE_ATTRIBUTES: {
const attributes = omit(action.attributes, ['uid']);
const attributes = omit(action.attributes, [NodePK]);

const updatedNodes = state.nodes.map((node) => {
if (node[NodePK] !== action.uid) { return node; }
if (node[NodePK] !== action[NodePK]) { return node; }

if (isMatch(node, attributes)) {
return omit(node, Object.getOwnPropertyNames(attributes));
Expand All @@ -95,7 +95,7 @@ export default function reducer(state = initialState, action = {}) {
case REMOVE_NODE:
return {
...state,
nodes: reject(state.nodes, node => node[NodePK] === action.uid),
nodes: reject(state.nodes, node => node[NodePK] === action[NodePK]),
};
case ADD_EDGE:
if (edgeExists(state.edges, action.edge)) { return state; }
Expand Down
7 changes: 4 additions & 3 deletions src/ducks/modules/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Observable } from 'rxjs';
import { combineEpics } from 'redux-observable';

import uuidv4 from '../../utils/uuid';
import network, { ADD_NODES, REMOVE_NODE, UPDATE_NODE, TOGGLE_NODE_ATTRIBUTES, ADD_EDGE, TOGGLE_EDGE, REMOVE_EDGE, SET_EGO, UNSET_EGO } from './network';
import network, { NodePK, ADD_NODES, REMOVE_NODE, UPDATE_NODE, TOGGLE_NODE_ATTRIBUTES, ADD_EDGE, TOGGLE_EDGE, REMOVE_EDGE, SET_EGO, UNSET_EGO } from './network';
import ApiClient from '../../utils/ApiClient';
import { protocolIdFromSessionPath } from '../../utils/matchSessionPath';
import { getPairedServerFactory } from '../../selectors/servers';


const ADD_SESSION = 'ADD_SESSION';
const UPDATE_SESSION = 'UPDATE_SESSION';
const UPDATE_PROMPT = 'UPDATE_PROMPT';
Expand Down Expand Up @@ -124,7 +125,7 @@ const toggleNodeAttributes = (uid, attributes) => (dispatch, getState) => {
dispatch({
type: TOGGLE_NODE_ATTRIBUTES,
sessionId: session,
uid,
[NodePK]: uid,
attributes,
});
};
Expand All @@ -135,7 +136,7 @@ const removeNode = uid => (dispatch, getState) => {
dispatch({
type: REMOVE_NODE,
sessionId: session,
uid,
[NodePK]: uid,
});
};

Expand Down

0 comments on commit fc316d8

Please sign in to comment.