Prevent category collapsing on annotation edit, # of cells on add label button (#1204)

* collapse functionality

* expand collapse
This commit is contained in:
Colin Megill
2020-03-10 13:21:06 -04:00
committed by GitHub
parent d8231a9a3b
commit 1a93068810
3 changed files with 31 additions and 11 deletions
@@ -9,7 +9,8 @@ import { labelPrompt, isLabelErroneous } from "./labelUtil";
categoricalSelection: state.categoricalSelection, categoricalSelection: state.categoricalSelection,
annotations: state.annotations, annotations: state.annotations,
universe: state.universe, universe: state.universe,
ontology: state.ontology ontology: state.ontology,
crossfilter: state.crossfilter
})) }))
class Category extends React.PureComponent { class Category extends React.PureComponent {
constructor(props) { constructor(props) {
@@ -73,7 +74,7 @@ class Category extends React.PureComponent {
render() { render() {
const { newLabelText } = this.state; const { newLabelText } = this.state;
const { metadataField, annotations, ontology } = this.props; const { metadataField, annotations, ontology, crossfilter } = this.props;
const ontologyEnabled = ontology?.enabled ?? false; const ontologyEnabled = ontology?.enabled ?? false;
return ( return (
@@ -91,7 +92,7 @@ class Category extends React.PureComponent {
instruction={this.instruction(newLabelText)} instruction={this.instruction(newLabelText)}
cancelTooltipContent="Close this dialog without adding a label." cancelTooltipContent="Close this dialog without adding a label."
primaryButtonText="Add label" primaryButtonText="Add label"
secondaryButtonText="Add label and assign currently selected cells" secondaryButtonText={`Add label and assign ${crossfilter.countSelected()} currently selected cells`}
handleSecondaryButtonSubmit={this.addLabelAndAssignCells} handleSecondaryButtonSubmit={this.addLabelAndAssignCells}
text={newLabelText} text={newLabelText}
validationError={this.labelNameError(newLabelText)} validationError={this.labelNameError(newLabelText)}
@@ -22,7 +22,8 @@ class Categories extends React.Component {
this.state = { this.state = {
createAnnoModeActive: false, createAnnoModeActive: false,
newCategoryText: "", newCategoryText: "",
categoryToDuplicate: null categoryToDuplicate: null,
expandedCats: new Set()
}; };
} }
@@ -105,15 +106,28 @@ class Categories extends React.Component {
); );
}; };
onExpansionChange = catName => {
const {expandedCats} = this.state;
if (expandedCats.has(catName)) {
const _expandedCats = new Set(expandedCats);
_expandedCats.delete(catName)
this.setState({expandedCats: _expandedCats})
} else {
const _expandedCats = new Set(expandedCats);
_expandedCats.add(catName)
this.setState({expandedCats: _expandedCats})
}
}
render() { render() {
const { const {
createAnnoModeActive, createAnnoModeActive,
categoryToDuplicate, categoryToDuplicate,
newCategoryText newCategoryText,
expandedCats
} = this.state; } = this.state;
const { writableCategoriesEnabled, schema, config, ontology } = this.props; const { writableCategoriesEnabled, schema, config, ontology } = this.props;
const ontologyEnabled = ontology?.enabled ?? false; const ontologyEnabled = ontology?.enabled ?? false;
/* all names, sorted in display order. Will be rendered in this order */ /* all names, sorted in display order. Will be rendered in this order */
const allCategoryNames = ControlsHelpers.selectableCategoryNames( const allCategoryNames = ControlsHelpers.selectableCategoryNames(
schema, schema,
@@ -169,6 +183,8 @@ class Categories extends React.Component {
<Category <Category
key={catName} key={catName}
metadataField={catName} metadataField={catName}
onExpansionChange={this.onExpansionChange}
isExpanded={expandedCats.has(catName)}
createAnnoModeActive={createAnnoModeActive} createAnnoModeActive={createAnnoModeActive}
isUserAnno={false} isUserAnno={false}
/> />
@@ -180,6 +196,8 @@ class Categories extends React.Component {
<Category <Category
key={catName} key={catName}
metadataField={catName} metadataField={catName}
onExpansionChange={this.onExpansionChange}
isExpanded={expandedCats.has(catName)}
createAnnoModeActive={createAnnoModeActive} createAnnoModeActive={createAnnoModeActive}
isUserAnno isUserAnno
/> />
@@ -20,8 +20,7 @@ class Category extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
isChecked: true, isChecked: true
isExpanded: false
}; };
} }
@@ -142,13 +141,15 @@ class Category extends React.Component {
} }
render() { render() {
const { isExpanded, isChecked } = this.state; const { isChecked } = this.state;
const { const {
metadataField, metadataField,
categoricalSelection, categoricalSelection,
colorAccessor, colorAccessor,
isUserAnno, isUserAnno,
annotations annotations,
isExpanded,
onExpansionChange
} = this.props; } = this.props;
const isStillLoading = !(categoricalSelection?.[metadataField] ?? false); const isStillLoading = !(categoricalSelection?.[metadataField] ?? false);
@@ -196,7 +197,7 @@ class Category extends React.Component {
annotations.isEditingCategoryName && annotations.isEditingCategoryName &&
annotations.categoryBeingEdited === metadataField; annotations.categoryBeingEdited === metadataField;
if (!editingCategory) { if (!editingCategory) {
this.setState({ isExpanded: !isExpanded }); onExpansionChange(metadataField)
} }
}} }}
> >