remove modal for inline edit category name, and autofocus (#962)

* remove modal for inline edit category name, and autofocus

* remove comment, rename to categorybeingedited
This commit is contained in:
Colin Megill
2019-10-04 13:41:05 -04:00
committed by GitHub
parent 3f2811d9da
commit 296352b620
3 changed files with 52 additions and 45 deletions
+47 -41
View File
@@ -237,45 +237,6 @@ class Category extends React.Component {
<span className="bp3-control-indicator" />
{""}
</label>
{/* Dialog uses portal, can be anywhere/factored out */}
<Dialog
icon="tag"
title="Edit category name"
isOpen={
annotations.isEditingCategoryName &&
annotations.categoryEditable === metadataField
}
onClose={this.disableEditCategoryMode}
>
<div className={Classes.DIALOG_BODY}>
<div style={{ marginBottom: 20 }}>
<p>New, unique category name:</p>
<InputGroup
autoFocus
onChange={e =>
this.setState({ newCategoryText: e.target.value })
}
leftIcon="tag"
/>
</div>
</div>
<div className={Classes.DIALOG_FOOTER}>
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
<Tooltip content="Close this dialog without editing the category.">
<Button onClick={this.disableEditCategoryMode}>
Cancel
</Button>
</Tooltip>
<Button
disabled={newCategoryText.length === 0}
onClick={this.handleEditCategory}
intent="primary"
>
Edit category name
</Button>
</div>
</div>
</Dialog>
<span
data-testid={`category-expand-${metadataField}`}
style={{
@@ -283,13 +244,58 @@ class Category extends React.Component {
display: "inline-block"
}}
onClick={() => {
this.setState({ isExpanded: !isExpanded });
const editingCategory =
annotations.isEditingCategoryName &&
annotations.categoryBeingEdited === metadataField;
if (!editingCategory) {
this.setState({ isExpanded: !isExpanded });
}
}}
>
{isUserAnno ? (
<Icon style={{ marginRight: 5 }} icon="tag" iconSize={16} />
) : null}
{metadataField}
{annotations.isEditingCategoryName &&
annotations.categoryBeingEdited === metadataField ? (
<form
style={{ display: "inline-block" }}
onSubmit={e => {
e.preventDefault();
this.handleEditCategory();
}}
>
<InputGroup
style={{ position: "relative", top: -1 }}
ref={input => {
this.editableCategoryInput = input;
}}
small
autoFocus
onChange={e => {
this.setState({
newCategoryText: e.target.value
});
}}
defaultValue={metadataField}
rightElement={
<Button
minimal
disabled={newCategoryText.length === 0}
style={{ position: "relative", top: -1 }}
type="button"
icon="small-tick"
data-testclass="submitCategoryNameEdit"
data-testid="submitCategoryNameEdit"
onClick={this.handleEditCategory}
/>
}
/>
</form>
) : (
metadataField
)}
{isExpanded ? (
<FaChevronDown
data-testclass="category-expand-is-expanded"
@@ -317,6 +317,7 @@ class CategoryValue extends React.Component {
this.editableInput = input;
}}
small
autoFocus
onChange={e => {
this.setState({ editedLabelText: e.target.value });
}}
+4 -4
View File
@@ -5,7 +5,7 @@ const Annotations = (
state = {
isEditingCategoryName: false,
isEditingLabelName: false,
categoryEditable: false,
categoryBeingEdited: false,
labelEditable: { category: null, label: null }
},
action
@@ -34,19 +34,19 @@ const Annotations = (
return {
...state,
isEditingCategoryName: true,
categoryEditable: action.data
categoryBeingEdited: action.data
};
case "annotation: disable category edit mode":
return {
...state,
isEditingCategoryName: false,
categoryEditable: null
categoryBeingEdited: null
};
case "annotation: category edited":
return {
...state,
isEditingCategoryName: true,
categoryEditable: null
categoryBeingEdited: null
};
/* LABEL */