mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-08 11:08:12 +08:00
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:
@@ -237,45 +237,6 @@ class Category extends React.Component {
|
|||||||
<span className="bp3-control-indicator" />
|
<span className="bp3-control-indicator" />
|
||||||
{""}
|
{""}
|
||||||
</label>
|
</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
|
<span
|
||||||
data-testid={`category-expand-${metadataField}`}
|
data-testid={`category-expand-${metadataField}`}
|
||||||
style={{
|
style={{
|
||||||
@@ -283,13 +244,58 @@ class Category extends React.Component {
|
|||||||
display: "inline-block"
|
display: "inline-block"
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.setState({ isExpanded: !isExpanded });
|
const editingCategory =
|
||||||
|
annotations.isEditingCategoryName &&
|
||||||
|
annotations.categoryBeingEdited === metadataField;
|
||||||
|
if (!editingCategory) {
|
||||||
|
this.setState({ isExpanded: !isExpanded });
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isUserAnno ? (
|
{isUserAnno ? (
|
||||||
<Icon style={{ marginRight: 5 }} icon="tag" iconSize={16} />
|
<Icon style={{ marginRight: 5 }} icon="tag" iconSize={16} />
|
||||||
) : null}
|
) : 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 ? (
|
{isExpanded ? (
|
||||||
<FaChevronDown
|
<FaChevronDown
|
||||||
data-testclass="category-expand-is-expanded"
|
data-testclass="category-expand-is-expanded"
|
||||||
|
|||||||
@@ -317,6 +317,7 @@ class CategoryValue extends React.Component {
|
|||||||
this.editableInput = input;
|
this.editableInput = input;
|
||||||
}}
|
}}
|
||||||
small
|
small
|
||||||
|
autoFocus
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
this.setState({ editedLabelText: e.target.value });
|
this.setState({ editedLabelText: e.target.value });
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const Annotations = (
|
|||||||
state = {
|
state = {
|
||||||
isEditingCategoryName: false,
|
isEditingCategoryName: false,
|
||||||
isEditingLabelName: false,
|
isEditingLabelName: false,
|
||||||
categoryEditable: false,
|
categoryBeingEdited: false,
|
||||||
labelEditable: { category: null, label: null }
|
labelEditable: { category: null, label: null }
|
||||||
},
|
},
|
||||||
action
|
action
|
||||||
@@ -34,19 +34,19 @@ const Annotations = (
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isEditingCategoryName: true,
|
isEditingCategoryName: true,
|
||||||
categoryEditable: action.data
|
categoryBeingEdited: action.data
|
||||||
};
|
};
|
||||||
case "annotation: disable category edit mode":
|
case "annotation: disable category edit mode":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isEditingCategoryName: false,
|
isEditingCategoryName: false,
|
||||||
categoryEditable: null
|
categoryBeingEdited: null
|
||||||
};
|
};
|
||||||
case "annotation: category edited":
|
case "annotation: category edited":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isEditingCategoryName: true,
|
isEditingCategoryName: true,
|
||||||
categoryEditable: null
|
categoryBeingEdited: null
|
||||||
};
|
};
|
||||||
|
|
||||||
/* LABEL */
|
/* LABEL */
|
||||||
|
|||||||
Reference in New Issue
Block a user