fire categorical select deselect conditionally

This commit is contained in:
Colin Megill
2017-10-23 12:48:43 -07:00
parent 1c2acaddb8
commit bbe6107f49
+26 -9
View File
@@ -17,24 +17,26 @@ class Button extends React.Component {
render () { render () {
/* has this value for this category already been selected? */ /* has this value for this category already been selected? */
let selected = false;
let fontWeight; let fontWeight;
if (!this.props.selectedMetadata) { /* there is no selected metadata */ if (!this.props.selectedMetadata) { /* there is no selected metadata */
fontWeight = 400; selected = false;
} else if ( } else if (
this.props.selectedMetadata[this.props.metadataField] && /* the key {Location: []} is present */ this.props.selectedMetadata[this.props.metadataField] && /* the key {Location: []} is present */
this.props.selectedMetadata[this.props.metadataField].indexOf(this.props.value) > -1 /* "Tumor" exists in {Location: ["Tumor"]} */ this.props.selectedMetadata[this.props.metadataField].indexOf(this.props.value) > -1 /* "Tumor" exists in {Location: ["Tumor"]} */
) { ) {
fontWeight = 700 selected = true;
} }
return ( return (
<div <div
key={this.props.i} key={this.props.i}
onClick={this.props.handleClick(this.props.metadataField, this.props.value)} onClick={selected ? this.props.toggleOff(this.props.metadataField, this.props.value) : this.props.toggleOn(this.props.metadataField, this.props.value)}
style={{ style={{
cursor: "pointer", cursor: "pointer",
display: "flex", display: "flex",
fontWeight, fontWeight: selected ? 700 : 400,
}}> }}>
<div style={{ <div style={{
width: 200, width: 200,
@@ -50,7 +52,7 @@ class Button extends React.Component {
} }
} }
const Category = ({metadataField, values, handleClick}) => ( const Category = ({metadataField, values, toggleOn, toggleOff}) => (
<div style={{ <div style={{
display: "flex", display: "flex",
alignItems: "baseline", alignItems: "baseline",
@@ -70,7 +72,8 @@ const Category = ({metadataField, values, handleClick}) => (
return ( return (
<Button <Button
key={v} key={v}
handleClick={handleClick} toggleOn={toggleOn}
toggleOff={toggleOff}
metadataField={metadataField} metadataField={metadataField}
count={values[v]} count={values[v]}
value={v} value={v}
@@ -97,9 +100,22 @@ class Categories extends React.Component {
}; };
} }
handleClick(metadataField, value) { toggleOn(metadataField, value) {
return () => { return () => {
this.props.dispatch({type: "categorical metadata filter selected", metadataField, value}) this.props.dispatch({
type: "categorical metadata filter selected",
metadataField,
value
})
}
}
toggleOff(metadataField, value) {
return () => {
this.props.dispatch({
type: "categorical metadata filter deselected",
metadataField,
value
})
} }
} }
render () { render () {
@@ -115,7 +131,8 @@ class Categories extends React.Component {
) { ) {
return ( return (
<Category <Category
handleClick={this.handleClick.bind(this)} toggleOn={this.toggleOn.bind(this)}
toggleOff={this.toggleOff.bind(this)}
key={key} key={key}
metadataField={key} metadataField={key}
values={value.options}/> values={value.options}/>