Warnings on anno textfields (#1023)

*  Warning for creating new label with an existing name

* category dup

* italics
This commit is contained in:
Colin Megill
2019-11-07 18:57:15 -05:00
committed by GitHub
parent 4c3d783fc8
commit 84900bad0e
3 changed files with 85 additions and 24 deletions
@@ -7,7 +7,8 @@ import {
InputGroup, InputGroup,
Dialog, Dialog,
Classes, Classes,
MenuItem MenuItem,
Colors
} from "@blueprintjs/core"; } from "@blueprintjs/core";
import { Select } from "@blueprintjs/select"; import { Select } from "@blueprintjs/select";
import { connect } from "react-redux"; import { connect } from "react-redux";
@@ -57,7 +58,11 @@ class Categories extends React.Component {
}; };
render() { render() {
const { createAnnoModeActive, categoryToDuplicate } = this.state; const {
createAnnoModeActive,
categoryToDuplicate,
newCategoryText
} = this.state;
const { const {
categoricalSelection, categoricalSelection,
writableCategoriesEnabled, writableCategoriesEnabled,
@@ -76,7 +81,9 @@ class Categories extends React.Component {
> >
{/* READ ONLY CATEGORICAL FIELDS */} {/* READ ONLY CATEGORICAL FIELDS */}
{/* this is duplicative but flat, could be abstracted */} {/* this is duplicative but flat, could be abstracted */}
{_.map(allCategoryNames, catName => {_.map(
allCategoryNames,
catName =>
!schema.annotations.obsByName[catName].writable ? ( !schema.annotations.obsByName[catName].writable ? (
<Category <Category
key={catName} key={catName}
@@ -87,7 +94,9 @@ class Categories extends React.Component {
) : null ) : null
)} )}
{/* WRITEABLE FIELDS */} {/* WRITEABLE FIELDS */}
{_.map(allCategoryNames, catName => {_.map(
allCategoryNames,
catName =>
schema.annotations.obsByName[catName].writable ? ( schema.annotations.obsByName[catName].writable ? (
<Category <Category
key={catName} key={catName}
@@ -116,12 +125,33 @@ class Categories extends React.Component {
<p>New, unique category name:</p> <p>New, unique category name:</p>
<InputGroup <InputGroup
autoFocus autoFocus
intent={
allCategoryNames.indexOf(newCategoryText) !== -1
? "warning"
: "none"
}
onChange={e => onChange={e =>
this.setState({ newCategoryText: e.target.value }) this.setState({ newCategoryText: e.target.value })
} }
leftIcon="tag" leftIcon="tag"
/> />
<p
style={{
marginTop: 7,
visibility:
allCategoryNames.indexOf(newCategoryText) !== -1
? "visible"
: "hidden",
color: Colors.ORANGE3
}}
>
<span style={{ fontStyle: "italic" }}>
{newCategoryText}
</span>{" "}
already exists
</p>
</div> </div>
<p> <p>
Optionally duplicate all labels & cell assignments from Optionally duplicate all labels & cell assignments from
existing category into new category: existing category into new category:
@@ -157,6 +187,9 @@ class Categories extends React.Component {
</Tooltip> </Tooltip>
<Button <Button
onClick={this.handleCreateUserAnno} onClick={this.handleCreateUserAnno}
disabled={
allCategoryNames.indexOf(newCategoryText) !== -1
}
intent="primary" intent="primary"
type="submit" type="submit"
> >
+30 -2
View File
@@ -2,7 +2,7 @@ import React from "react";
import _ from "lodash"; import _ from "lodash";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { FaChevronRight, FaChevronDown } from "react-icons/fa"; import { FaChevronRight, FaChevronDown } from "react-icons/fa";
import { Flipper, Flipped, Spring } from "react-flip-toolkit"; import { Flipper, Flipped } from "react-flip-toolkit";
import { import {
Button, Button,
Tooltip, Tooltip,
@@ -14,7 +14,8 @@ import {
Classes, Classes,
Icon, Icon,
Position, Position,
PopoverInteractionKind PopoverInteractionKind,
Colors
} from "@blueprintjs/core"; } from "@blueprintjs/core";
import * as globals from "../../globals"; import * as globals from "../../globals";
@@ -345,11 +346,38 @@ class Category extends React.Component {
<p>New, unique label name:</p> <p>New, unique label name:</p>
<InputGroup <InputGroup
autoFocus autoFocus
intent={
universe.schema.annotations.obsByName[
metadataField
].categories.indexOf(newLabelText) !== -1
? "warning"
: "none"
}
onChange={e => onChange={e =>
this.setState({ newLabelText: e.target.value }) this.setState({ newLabelText: e.target.value })
} }
leftIcon="tag" leftIcon="tag"
/> />
<p
style={{
marginTop: 7,
visibility:
universe.schema.annotations.obsByName[
metadataField
].categories.indexOf(newLabelText) !== -1
? "visible"
: "hidden",
color: Colors.ORANGE3
}}
>
<span style={{ fontStyle: "italic" }}>
{newLabelText}
</span>{" "}
already exists within{" "}
<span style={{ fontStyle: "italic" }}>
{metadataField}
</span>
</p>
</div> </div>
</div> </div>
<div className={Classes.DIALOG_FOOTER}> <div className={Classes.DIALOG_FOOTER}>
+2 -2
View File
@@ -5,7 +5,7 @@ const Annotations = (
state = { state = {
isEditingCategoryName: false, isEditingCategoryName: false,
isEditingLabelName: false, isEditingLabelName: false,
categoryBeingEdited: false, categoryBeingEdited: null,
categoryAddingNewLabel: null, categoryAddingNewLabel: null,
labelEditable: { category: null, label: null } labelEditable: { category: null, label: null }
}, },
@@ -46,7 +46,7 @@ const Annotations = (
case "annotation: category edited": case "annotation: category edited":
return { return {
...state, ...state,
isEditingCategoryName: true, isEditingCategoryName: false,
categoryBeingEdited: null categoryBeingEdited: null
}; };