correctly toggle group selection in categorical metadata (#640)

This commit is contained in:
Bruce Martin
2019-03-12 10:49:29 -07:00
committed by GitHub
parent 80969012c9
commit aa5ce4a2f1
@@ -21,8 +21,9 @@ class Category extends React.Component {
}; };
} }
componentDidUpdate() { componentDidUpdate(prevProps) {
const { categoricalSelectionState, metadataField } = this.props; const { categoricalSelectionState, metadataField } = this.props;
if (categoricalSelectionState !== prevProps.categoricalSelectionState) {
const cat = categoricalSelectionState[metadataField]; const cat = categoricalSelectionState[metadataField];
const categoryCount = { const categoryCount = {
// total number of categories in this dimension // total number of categories in this dimension
@@ -37,22 +38,25 @@ class Category extends React.Component {
if (categoryCount.selectedCatCount === categoryCount.totalCatCount) { if (categoryCount.selectedCatCount === categoryCount.totalCatCount) {
/* everything is on, so not indeterminate */ /* everything is on, so not indeterminate */
this.checkbox.indeterminate = false; this.checkbox.indeterminate = false;
this.setState({ isChecked: true }); // eslint-disable-line react/no-did-update-set-state
} else if (categoryCount.selectedCatCount === 0) { } else if (categoryCount.selectedCatCount === 0) {
/* nothing is on, so no */ /* nothing is on, so no */
this.checkbox.indeterminate = false; this.checkbox.indeterminate = false;
this.setState({ isChecked: false }); // eslint-disable-line react/no-did-update-set-state
} else if (categoryCount.selectedCatCount < categoryCount.totalCatCount) { } else if (categoryCount.selectedCatCount < categoryCount.totalCatCount) {
/* to be explicit... */ /* to be explicit... */
this.checkbox.indeterminate = true; this.checkbox.indeterminate = true;
} }
} }
}
handleColorChange() { handleColorChange = () => {
const { dispatch, metadataField } = this.props; const { dispatch, metadataField } = this.props;
dispatch({ dispatch({
type: "color by categorical metadata", type: "color by categorical metadata",
colorAccessor: metadataField colorAccessor: metadataField
}); });
} };
toggleAll() { toggleAll() {
const { dispatch, metadataField } = this.props; const { dispatch, metadataField } = this.props;
@@ -161,10 +165,10 @@ class Category extends React.Component {
</div> </div>
<Tooltip content="Use as color scale" position="bottom"> <Tooltip content="Use as color scale" position="bottom">
<Button <Button
onClick={this.handleColorChange.bind(this)} onClick={this.handleColorChange}
active={colorAccessor === metadataField} active={colorAccessor === metadataField}
intent={colorAccessor === metadataField ? "primary" : "none"} intent={colorAccessor === metadataField ? "primary" : "none"}
icon={"tint"} icon="tint"
/> />
</Tooltip> </Tooltip>
</div> </div>