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 6, 2024
1 parent 08be27a commit c212525
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/reducers/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,22 @@ const Tree = (state = getDefaultTreeState(), action) => {
});
case types.TREE_TOO_DATA:
return action.tree;
case types.ADD_EXTRA_METADATA:
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 = new Set(state.nodeAttrKeys);
Object.keys(action.newColorings).forEach((attr) => nodeAttrKeys.add(attr));
// 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

0 comments on commit c212525

Please sign in to comment.