all or none becomes a checkbox

This commit is contained in:
Colin Megill
2018-01-08 14:04:02 -08:00
parent 5140020c08
commit 7cea939926
4 changed files with 47 additions and 42 deletions
+21 -13
View File
@@ -10,6 +10,13 @@ import { alphabeticallySortedValues } from "./util";
@connect() @connect()
class Category extends React.Component { class Category extends React.Component {
constructor(props) {
super(props);
this.state = {
isChecked: true
};
}
handleColorChange() { handleColorChange() {
this.props.dispatch({ this.props.dispatch({
type: "color by categorical metadata", type: "color by categorical metadata",
@@ -21,6 +28,15 @@ class Category extends React.Component {
type: "categorical metadata filter all of these", type: "categorical metadata filter all of these",
metadataField: this.props.metadataField metadataField: this.props.metadataField
}) })
this.setState({isChecked: true})
}
toggleNone() {
this.props.dispatch({
type: "categorical metadata filter none of these",
metadataField: this.props.metadataField,
value: this.props.value
})
this.setState({isChecked: false})
} }
render() { render() {
return ( return (
@@ -43,11 +59,15 @@ class Category extends React.Component {
marginRight: 10, marginRight: 10,
}}> }}>
{this.props.metadataField} {this.props.metadataField}
<input
onChange={this.state.isChecked ? this.toggleNone.bind(this) : this.toggleAll.bind(this)}
checked={this.state.isChecked}
type="checkbox"/>
<span <span
onClick={this.handleColorChange.bind(this)} onClick={this.handleColorChange.bind(this)}
style={{ style={{
fontSize: 16, fontSize: 16,
marginLeft: 10, marginLeft: 4,
position: "relative", position: "relative",
top: 2, top: 2,
cursor: "pointer", cursor: "pointer",
@@ -55,18 +75,6 @@ class Category extends React.Component {
🖌️ 🖌️
</span> </span>
</p> </p>
<span
onClick={this.toggleAll.bind(this)}
style={{
fontFamily: globals.accentFont,
fontSize: 10,
fontWeight: 100,
fontStyle: "italic",
cursor: "pointer",
}}>
{"all"}
</span>
</div> </div>
<div> <div>
{ {
+19 -19
View File
@@ -26,14 +26,6 @@ class CategoryValue extends React.Component {
}); });
} }
toggleOnlyThis() {
this.props.dispatch({
type: "categorical metadata filter only this",
metadataField: this.props.metadataField,
value: this.props.value
})
}
render () { render () {
if (!this.props.categoricalAsBooleansMap) return null if (!this.props.categoricalAsBooleansMap) return null
@@ -66,17 +58,6 @@ class CategoryValue extends React.Component {
}}> }}>
{this.props.count} {this.props.count}
</p> </p>
<span
onClick={this.toggleOnlyThis.bind(this)}
style={{
fontFamily: globals.accentFont,
fontSize: 10,
fontWeight: 100,
fontStyle: "italic",
cursor: "pointer",
}}>
{"only"}
</span>
</div> </div>
) )
} }
@@ -84,6 +65,25 @@ class CategoryValue extends React.Component {
export default CategoryValue; export default CategoryValue;
// toggleOnlyThis() {
// this.props.dispatch({
// type: "categorical metadata filter none of these",
// metadataField: this.props.metadataField,
// value: this.props.value
// })
// }
// <span
// onClick={this.toggleOnlyThis.bind(this)}
// style={{
// fontFamily: globals.accentFont,
// fontSize: 10,
// fontWeight: 100,
// fontStyle: "italic",
// cursor: "pointer",
// }}>
// {"only"}
// </span>
// onClick={selected ? this.toggleOff.bind(this) : this.toggleOn.bind(this)} // onClick={selected ? this.toggleOff.bind(this) : this.toggleOn.bind(this)}
// toggleOn() { // toggleOn() {
// this.props.dispatch( // this.props.dispatch(
@@ -30,7 +30,7 @@ const updateCellSelectionMiddleware = (store) => {
action.type === "graph brush deselect" || action.type === "graph brush deselect" ||
action.type === "categorical metadata filter deselect" || action.type === "categorical metadata filter deselect" ||
action.type === "categorical metadata filter select" || action.type === "categorical metadata filter select" ||
action.type === "categorical metadata filter only this" || action.type === "categorical metadata filter none of these" ||
action.type === "categorical metadata filter all of these" action.type === "categorical metadata filter all of these"
; ;
@@ -143,27 +143,24 @@ const updateCellSelectionMiddleware = (store) => {
[action.value]: false [action.value]: false
} }
} }
} else if (action.type === "categorical metadata filter only this") { } else if (action.type === "categorical metadata filter none of these") {
const metadataFieldWithOnlyThisValueSelected = {}; const metadataFieldWithAllOfTheseValueSelected = {};
/* set EVERYTHING to false in this intermediate object */ /* set EVERYTHING to false in this intermediate object */
_.each(s.controls.categoricalAsBooleansMap[action.metadataField], (isActive, option) => { _.each(s.controls.categoricalAsBooleansMap[action.metadataField], (isActive, option) => {
metadataFieldWithOnlyThisValueSelected[option] = false; metadataFieldWithAllOfTheseValueSelected[option] = false;
}) })
/* then set the one we want to true, to avoid the conditional nesting */
metadataFieldWithOnlyThisValueSelected[action.value] = true;
newCategoricalAsBooleansMap = { newCategoricalAsBooleansMap = {
...s.controls.categoricalAsBooleansMap, ...s.controls.categoricalAsBooleansMap,
[action.metadataField]: metadataFieldWithOnlyThisValueSelected [action.metadataField]: metadataFieldWithAllOfTheseValueSelected
} }
} else if (action.type === "categorical metadata filter all of these") { } else if (action.type === "categorical metadata filter all of these") {
const metadataFieldWithAllOfTheseValueSelected = {}; const metadataFieldWithAllOfTheseValueSelected = {};
/* set EVERYTHING to false in this intermediate object */ /* set EVERYTHING to true in this intermediate object */
_.each(s.controls.categoricalAsBooleansMap[action.metadataField], (isActive, option) => { _.each(s.controls.categoricalAsBooleansMap[action.metadataField], (isActive, option) => {
metadataFieldWithAllOfTheseValueSelected[option] = true; metadataFieldWithAllOfTheseValueSelected[option] = true;
}) })
+1 -1
View File
@@ -89,7 +89,7 @@ const Controls = (state = {
categoricalAsBooleansMap: action.newCategoricalAsBooleansMap, /* this comes from middleware */ categoricalAsBooleansMap: action.newCategoricalAsBooleansMap, /* this comes from middleware */
currentCellSelection: action.newSelection /* this comes from middleware */ currentCellSelection: action.newSelection /* this comes from middleware */
}) })
case "categorical metadata filter only this": case "categorical metadata filter none of these":
return Object.assign({}, state, { return Object.assign({}, state, {
categoricalAsBooleansMap: action.newCategoricalAsBooleansMap, /* this comes from middleware */ categoricalAsBooleansMap: action.newCategoricalAsBooleansMap, /* this comes from middleware */
currentCellSelection: action.newSelection /* this comes from middleware */ currentCellSelection: action.newSelection /* this comes from middleware */