mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-08 14:28:12 +08:00
checkbox intermediate state
This commit is contained in:
@@ -15,7 +15,8 @@ import FaPaintBrush from "react-icons/lib/fa/paint-brush";
|
|||||||
|
|
||||||
@connect(state => {
|
@connect(state => {
|
||||||
return {
|
return {
|
||||||
colorAccessor: state.controls.colorAccessor
|
colorAccessor: state.controls.colorAccessor,
|
||||||
|
categoricalAsBooleansMap: state.controls.categoricalAsBooleansMap
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
class Category extends React.Component {
|
class Category extends React.Component {
|
||||||
@@ -26,7 +27,24 @@ class Category extends React.Component {
|
|||||||
isExpanded: false
|
isExpanded: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
componentDidUpdate() {
|
||||||
|
const valuesAsBool = _.values(
|
||||||
|
this.props.categoricalAsBooleansMap[this.props.metadataField]
|
||||||
|
)
|
||||||
|
/* count categories toggled on by counting true values */
|
||||||
|
const categoriesToggledOn = _.values(valuesAsBool).filter(v => v).length;
|
||||||
|
|
||||||
|
if (categoriesToggledOn === valuesAsBool.length) {
|
||||||
|
/* everything is on, so not indeterminate */
|
||||||
|
this.checkbox.indeterminate = false;
|
||||||
|
} else if (categoriesToggledOn === 0) {
|
||||||
|
/* nothing is on, so no */
|
||||||
|
this.checkbox.indeterminate = false;
|
||||||
|
} else if (categoriesToggledOn < valuesAsBool.length) {
|
||||||
|
/* to be explicit... */
|
||||||
|
this.checkbox.indeterminate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
handleColorChange() {
|
handleColorChange() {
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: "color by categorical metadata",
|
type: "color by categorical metadata",
|
||||||
@@ -61,6 +79,16 @@ class Category extends React.Component {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
handleToggleAllClick() {
|
||||||
|
// || this.checkbox.indeterminate === false
|
||||||
|
if (this.state.isChecked) {
|
||||||
|
console.log('checked, firing toggle none')
|
||||||
|
this.toggleNone();
|
||||||
|
} else if (!this.state.isChecked) {
|
||||||
|
console.log('!checked, firing toggle all')
|
||||||
|
this.toggleAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -102,11 +130,8 @@ class Category extends React.Component {
|
|||||||
</span>
|
</span>
|
||||||
{this.props.metadataField}
|
{this.props.metadataField}
|
||||||
<input
|
<input
|
||||||
onChange={
|
onChange={this.handleToggleAllClick.bind(this)}
|
||||||
this.state.isChecked
|
ref={el => this.checkbox = el}
|
||||||
? this.toggleNone.bind(this)
|
|
||||||
: this.toggleAll.bind(this)
|
|
||||||
}
|
|
||||||
checked={this.state.isChecked}
|
checked={this.state.isChecked}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user