Skip to content

Commit 5d821c9

Browse files
committed
Update tree.nodeAttrKeys during ADD_EXTRA_METADATA action
Ensures that new metadata fields added to the tree are included as new tip labels. Fixes #1844
1 parent 08be27a commit 5d821c9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/reducers/tree.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { countTraitsAcrossTree } from "../util/treeCountingHelpers";
22
import { addNodeAttrs } from "../util/treeMiscHelpers";
3+
import { processNodes } from "../util/treeJsonProcessing";
34
import * as types from "../actions/types";
45

56
/* A version increase (i.e. props.version !== nextProps.version) necessarily implies
@@ -68,13 +69,16 @@ const Tree = (state = getDefaultTreeState(), action) => {
6869
case types.ADD_EXTRA_METADATA:
6970
// add data into `nodes` in-place, so no redux update will be triggered if you only listen to `nodes`
7071
addNodeAttrs(state.nodes, action.newNodeAttrs);
72+
// add the new nodeAttrKeys to ensure tip labels get updated
73+
const { nodeAttrKeys } = processNodes(state.nodes)
7174
// add the new colorings to totalStateCounts so that they can function as filters
7275
return {
7376
...state,
7477
totalStateCounts: {
7578
...state.totalStateCounts,
7679
...countTraitsAcrossTree(state.nodes, Object.keys(action.newColorings), false, true)
77-
}
80+
},
81+
nodeAttrKeys
7882
};
7983
default:
8084
return state;

src/util/treeJsonProcessing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const pseudoRandomName = () => (Math.random()*1e32).toString(36).slice(0, 6);
1616
*
1717
* side-effects: node.hasChildren (bool) and node.arrayIdx (INT) for each node in nodes
1818
*/
19-
const processNodes = (nodes) => {
19+
export const processNodes = (nodes) => {
2020
const nodeNamesSeen = new Set();
2121
const nodeAttrKeys = new Set();
2222
calcFullTipCounts(nodes[0]); /* recursive. Uses d.children */

0 commit comments

Comments
 (0)