{
_.map(alphabeticallySortedValues(values), (v, i) => {
@@ -60,7 +71,7 @@ const Category = ({category, values, handleClick}) => (
@@ -73,17 +84,10 @@ const Category = ({category, values, handleClick}) => (
@connect((state) => {
- let ranges = null;
-
- if (
- state.cells.cells &&
- state.cells.cells.data.ranges
- ) {
- ranges = state.cells.cells.data.ranges;
- }
+ const ranges = state.cells.cells && state.cells.cells.data.ranges ? state.cells.cells.data.ranges : null;
return {
- ranges: ranges
+ ranges
}
})
class Categories extends React.Component {
@@ -93,9 +97,9 @@ class Categories extends React.Component {
};
}
- handleClick(category, value) {
+ handleClick(metadataField, value) {
return () => {
- this.props.dispatch({type: "category changed", data: {category, value}})
+ this.props.dispatch({type: "categorical metadata filter selected", metadataField, value})
}
}
render () {
@@ -113,7 +117,7 @@ class Categories extends React.Component {
)
} else {
diff --git a/src/reducers/selectedMetadata.js b/src/reducers/selectedMetadata.js
new file mode 100644
index 00000000..ce135837
--- /dev/null
+++ b/src/reducers/selectedMetadata.js
@@ -0,0 +1,53 @@
+import uri from "urijs";
+import _ from "lodash";
+
+/************************************************************************
+*************************************************************************
+1. This is all of the state that will be stored in the URL query params.
+1a. It is reasonably important it be kept in the same place,
+because if initial load or back button etc, we'll hear about that
+and manually reconstruct the state from the url, overriding whatever
+we had. We could of course listen for the "url changed" type in another
+reducer, if this gets messy.
+1b. The data structures used here are constrained as well, as urijs
+needs to be able to parse them, if arrays: https://hackernoon.com/redux-patterns-add-edit-remove-objects-in-an-array-6ee70cab2456
+*************************************************************************
+************************************************************************/
+
+const selectedMetadata = (
+ state = {},
+ action
+) => {
+ switch (action.type) {
+ case "url changed": {
+ const {url} = action;
+ const parsed = uri.parseQuery(window.location.search);
+ // console.log("onURLchange sees: ", state, parsed)
+ return state;
+ }
+ case "categorical metadata filter selected": {
+ if (!state[action.metadataField]) { /* we don't have the field, which means this is a simple insertion */
+ /* {} becomes {Location: ["Tumor"]} */
+ return Object.assign({}, state, {[action.metadataField]: [action.value]});
+ } else { /* we do have the field, so we need to push to a copy of the array */
+ const updatedField = state[action.metadataField].slice()
+ updatedField.push(action.value)
+ return Object.assign({}, state, {
+ /* {Location: ["Tumor"]} becomes {Location: ["Tumor", "Periphery"]} */
+ [action.metadataField]: updatedField
+ })
+ }
+ }
+ case "categorical metadata filter deselected": {
+ return Object.assign({}, state, {
+
+ })
+ }
+ default:
+ return state;
+ }
+
+ return state;
+}
+
+export default selectedMetadata;
diff --git a/src/reducers/url.js b/src/reducers/url.js
deleted file mode 100644
index a8264b22..00000000
--- a/src/reducers/url.js
+++ /dev/null
@@ -1,43 +0,0 @@
-import uri from "urijs";
-
-/************************************************************************
-*************************************************************************
-1. This is all of the state that will be stored in the URL query params.
-1a. It is reasonably important it be kept in the same place,
-because if initial load or back button etc, we'll hear about that
-and manually reconstruct the state from the url, overriding whatever
-we had. We could of course listen for the "url changed" type in another
-reducer, if this gets messy.
-1b. The data structures used here are constrained as well, as urijs
-needs to be able to parse them
-*************************************************************************
-************************************************************************/
-
-const url = (
- state = {
- selectedMetadata: {}
- },
- action
-) => {
- switch (action.type) {
- case "url changed": {
- const {url} = action;
-
- // const parsed = uri.parseQuery(window.location.search);
-
- // console.log("onURLchange sees: ", state, parsed)
-
- return state;
- }
- case "category changed": {
-
- return state;
- }
- default:
- return state;
- }
-
- return state;
-}
-
-export default url;