Skip to content

Commit

Permalink
Update tree.nodeAttrKeys during ADD_EXTRA_METADATA action
Browse files Browse the repository at this point in the history
Ensures that new metadata fields added to the tree are included as
new tip labels.

Fixes #1844
  • Loading branch information
joverlee521 committed Sep 3, 2024
1 parent 08be27a commit 5d821c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/reducers/tree.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { countTraitsAcrossTree } from "../util/treeCountingHelpers";
import { addNodeAttrs } from "../util/treeMiscHelpers";
import { processNodes } from "../util/treeJsonProcessing";
import * as types from "../actions/types";

/* A version increase (i.e. props.version !== nextProps.version) necessarily implies
Expand Down Expand Up @@ -68,13 +69,16 @@ const Tree = (state = getDefaultTreeState(), action) => {
case types.ADD_EXTRA_METADATA:
// add data into `nodes` in-place, so no redux update will be triggered if you only listen to `nodes`
addNodeAttrs(state.nodes, action.newNodeAttrs);
// add the new nodeAttrKeys to ensure tip labels get updated
const { nodeAttrKeys } = processNodes(state.nodes)

Check failure on line 73 in src/reducers/tree.js

View workflow job for this annotation

GitHub Actions / lint (16)

Unexpected lexical declaration in case block

Check failure on line 73 in src/reducers/tree.js

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected lexical declaration in case block

Check failure on line 73 in src/reducers/tree.js

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected lexical declaration in case block

Check failure on line 73 in src/reducers/tree.js

View workflow job for this annotation

GitHub Actions / lint (22)

Unexpected lexical declaration in case block
// add the new colorings to totalStateCounts so that they can function as filters
return {
...state,
totalStateCounts: {
...state.totalStateCounts,
...countTraitsAcrossTree(state.nodes, Object.keys(action.newColorings), false, true)
}
},
nodeAttrKeys
};
default:
return state;
Expand Down
2 changes: 1 addition & 1 deletion src/util/treeJsonProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const pseudoRandomName = () => (Math.random()*1e32).toString(36).slice(0, 6);
*
* side-effects: node.hasChildren (bool) and node.arrayIdx (INT) for each node in nodes
*/
const processNodes = (nodes) => {
export const processNodes = (nodes) => {
const nodeNamesSeen = new Set();
const nodeAttrKeys = new Set();
calcFullTipCounts(nodes[0]); /* recursive. Uses d.children */
Expand Down

0 comments on commit 5d821c9

Please sign in to comment.