undo/redo cleanup (#1165)

* fix refactoring error which disabled annotation file clearing

* fix undo behavior on add category label

* fix various undo/redo bugs

* remove logging

* further refinement of annotation undo/redo and actions

* address PR comment
This commit is contained in:
Bruce Martin
2020-02-24 18:51:26 -07:00
committed by GitHub
parent 5c70cc5bcd
commit 7bc58bba2b
10 changed files with 75 additions and 60 deletions
@@ -70,7 +70,7 @@ class AnnoDialog extends React.Component {
onClick={handleSecondaryButtonSubmit}
disabled={!text || validationError}
intent="none"
type="submit"
type="button"
>
{secondaryButtonText}
</Button>
@@ -32,43 +32,43 @@ class Category extends React.Component {
});
};
handleAddNewLabelToCategory = () => {
handleAddNewLabelToCategory = e => {
const { dispatch, metadataField } = this.props;
const { newLabelText } = this.state;
this.disableAddNewLabelMode();
dispatch({
type: "annotation: add new label to category",
metadataField,
newLabelText,
assignSelectedCells: false
});
this.setState({ newLabelText: "" });
e.preventDefault();
};
addLabelAndAssignCells = () => {
const { dispatch, metadataField } = this.props;
const { newLabelText } = this.state;
this.disableAddNewLabelMode();
dispatch({
type: "annotation: add new label to category",
metadataField,
newLabelText,
assignSelectedCells: true
});
this.setState({ newLabelText: "" });
};
handleCreateArbitraryLabel = newLabelTextNotInOntology => {
const { dispatch, metadataField } = this.props;
this.disableAddNewLabelMode();
dispatch({
type: "annotation: add new label to category",
metadataField,
newLabelText: newLabelTextNotInOntology,
assignSelectedCells: false
});
this.setState({ newLabelText: "" });
};
labelNameError = name => {
@@ -102,7 +102,9 @@ class Category extends React.Component {
annotations.categoryAddingNewLabel === metadataField
}
inputProps={{ "data-testid": `${metadataField}:create-label-dialog` }}
primaryButtonProps={{ "data-testid": `${metadataField}:submit-label` }}
primaryButtonProps={{
"data-testid": `${metadataField}:submit-label`
}}
title="Add new label to category"
instruction="New, unique label name:"
cancelTooltipContent="Close this dialog without adding a label."
@@ -32,43 +32,43 @@ class Category extends React.Component {
});
};
handleAddNewLabelToCategory = () => {
handleAddNewLabelToCategory = e => {
const { dispatch, metadataField } = this.props;
const { newLabelText } = this.state;
this.disableAddNewLabelFromOntologyMode();
dispatch({
type: "annotation: add new label to category",
metadataField,
newLabelText,
assignSelectedCells: false
});
this.setState({ newLabelText: "" });
e.preventDefault();
};
addLabelAndAssignCells = () => {
const { dispatch, metadataField } = this.props;
const { newLabelText } = this.state;
this.disableAddNewLabelFromOntologyMode();
dispatch({
type: "annotation: add new label to category",
metadataField,
newLabelText,
assignSelectedCells: true
});
this.setState({ newLabelText: "" });
};
handleCreateArbitraryLabel = newLabelTextNotInOntology => {
const { dispatch, metadataField } = this.props;
this.disableAddNewLabelFromOntologyMode();
dispatch({
type: "annotation: add new label to category",
metadataField,
newLabelText: newLabelTextNotInOntology,
assignSelectedCells: false
});
this.setState({ newLabelText: "" });
};
labelNameError = name => {
@@ -30,13 +30,14 @@ class AnnoDialogEditCategoryName extends React.Component {
};
disableEditCategoryMode = () => {
const { dispatch } = this.props;
const { dispatch, metadataField } = this.props;
dispatch({
type: "annotation: disable category edit mode"
});
this.setState({ newCategoryText: metadataField });
};
handleEditCategory = () => {
handleEditCategory = e => {
const { dispatch, metadataField, categoricalSelection } = this.props;
const { newCategoryText } = this.state;
@@ -50,12 +51,14 @@ class AnnoDialogEditCategoryName extends React.Component {
return;
}
this.disableEditCategoryMode();
dispatch({
type: "annotation: category edited",
metadataField,
newCategoryText,
data: newCategoryText
});
e.preventDefault();
};
categoryNameErrorMessage = () => {
@@ -121,8 +124,12 @@ class AnnoDialogEditCategoryName extends React.Component {
annotations.isEditingCategoryName &&
annotations.categoryBeingEdited === metadataField
}
inputProps={{ "data-testid": `${metadataField}:edit-category-name-dialog` }}
primaryButtonProps={{ "data-testid": `${metadataField}:submit-category-edit` }}
inputProps={{
"data-testid": `${metadataField}:edit-category-name-dialog`
}}
primaryButtonProps={{
"data-testid": `${metadataField}:submit-category-edit`
}}
title="Edit category name"
instruction="New, unique category name:"
cancelTooltipContent="Close this dialog without editing this category."
@@ -134,7 +141,9 @@ class AnnoDialogEditCategoryName extends React.Component {
handleCancel={this.disableEditCategoryMode}
annoInput={
<AnnoInputs
inputProps={{ "data-testid": `${metadataField}:edit-category-name-text`}}
inputProps={{
"data-testid": `${metadataField}:edit-category-name-text`
}}
useSuggest={false}
text={newCategoryText}
handleTextChange={this.handleCategoryEditTextChange}
@@ -24,7 +24,7 @@ class Categories extends React.Component {
};
}
handleCreateUserAnno = () => {
handleCreateUserAnno = e => {
const { dispatch } = this.props;
const { newCategoryText, categoryToDuplicate } = this.state;
dispatch({
@@ -37,6 +37,7 @@ class Categories extends React.Component {
categoryToDuplicate: null,
newCategoryText: ""
});
e.preventDefault();
};
handleEnableAnnoMode = () => {
+15 -7
View File
@@ -83,10 +83,11 @@ class CategoryValue extends React.Component {
});
};
handleEditValue = () => {
handleEditValue = e => {
const { dispatch, metadataField, categoryIndex } = this.props;
const { editedLabelText } = this.state;
const label = this.getLabel();
this.cancelEditMode();
dispatch({
type: "annotation: label edited",
editedLabel: editedLabelText,
@@ -94,12 +95,13 @@ class CategoryValue extends React.Component {
categoryIndex,
label
});
e.preventDefault();
};
handleCreateArbitraryLabel = editedLabelTextNotInOntology => {
const { dispatch, metadataField, categoryIndex } = this.props;
const label = this.getLabel();
this.cancelEditMode();
dispatch({
type: "annotation: label edited",
metadataField,
@@ -150,7 +152,7 @@ class CategoryValue extends React.Component {
});
};
cancelEdit = () => {
cancelEditMode = () => {
const { dispatch, metadataField, categoryIndex } = this.props;
dispatch({
type: "annotation: cancel edit label mode",
@@ -433,8 +435,12 @@ class CategoryValue extends React.Component {
<div>
<AnnoDialog
isActive={editModeActive}
inputProps={{ "data-testid": `${metadataField}:edit-label-name-dialog` }}
primaryButtonProps={{ "data-testid": `${metadataField}:${displayString}:submit-label-edit` }}
inputProps={{
"data-testid": `${metadataField}:edit-label-name-dialog`
}}
primaryButtonProps={{
"data-testid": `${metadataField}:${displayString}:submit-label-edit`
}}
title="Edit label"
instruction={`New label text must be unique within category ${metadataField}:`}
cancelTooltipContent="Close this dialog without editing label text."
@@ -444,12 +450,14 @@ class CategoryValue extends React.Component {
validationError={this.labelNameError(editedLabelText)}
errorMessage={this.labelNameErrorMessage(editedLabelText)}
handleSubmit={this.handleEditValue}
handleCancel={this.cancelEdit}
handleCancel={this.cancelEditMode}
annoInput={
<AnnoInputs
useSuggest={ontologyEnabled}
text={editedLabelText}
inputProps={{ "data-testid": `${metadataField}:${displayString}:edit-label-name` }}
inputProps={{
"data-testid": `${metadataField}:${displayString}:edit-label-name`
}}
handleCreateArbitraryLabel={
this.handleCreateArbitraryLabel
}