diff --git a/src/Annotator/index.js b/src/Annotator/index.js index a00bf98e..37c8393c 100644 --- a/src/Annotator/index.js +++ b/src/Annotator/index.js @@ -90,6 +90,7 @@ export const Annotator = ({ hideHeaderText, hideNext, hidePrev, + allowComments, }: Props) => { if (typeof selectedImage === "string") { selectedImage = (images || []).findIndex((img) => img.src === selectedImage) @@ -125,6 +126,7 @@ export const Annotator = ({ history: [], videoName, keypointDefinitions, + allowComments, ...(annotationType === "image" ? { selectedImage, diff --git a/src/Annotator/index.story.js b/src/Annotator/index.story.js index 5f31fbd1..f9e42d78 100644 --- a/src/Annotator/index.story.js +++ b/src/Annotator/index.story.js @@ -52,6 +52,37 @@ storiesOf("Annotator", module) ]} /> )) + .add("Basic - Allow Comments", () => ( + + )) .add("Fixed Size Container", () => (
{ if (!isEqual(oldRegion.tags, action.region.tags)) { state = saveToHistory(state, "Change Region Tags") } + if (!isEqual(oldRegion.comment, action.region.comment)) { + state = saveToHistory(state, "Change Region Comment") + } return setIn( state, [...pathToActiveImage, "regions", regionIndex], diff --git a/src/DemoSite/Editor.js b/src/DemoSite/Editor.js index 281b5308..e85bf0c7 100644 --- a/src/DemoSite/Editor.js +++ b/src/DemoSite/Editor.js @@ -59,6 +59,7 @@ export const examples = { name: "bianchi-oltre-xr4", }, ], + allowComments: true, }), "Simple Segmentation": () => ({ taskDescription: diff --git a/src/ImageCanvas/index.js b/src/ImageCanvas/index.js index f684ebce..42152214 100644 --- a/src/ImageCanvas/index.js +++ b/src/ImageCanvas/index.js @@ -66,7 +66,7 @@ type Props = { fullImageSegmentationMode?: boolean, autoSegmentationOptions?: Object, modifyingAllowedArea?: boolean, - + allowComments?: Boolean, onChangeRegion: (Region) => any, onBeginRegionEdit: (Region) => any, onCloseRegionEdit: (Region) => any, @@ -139,6 +139,7 @@ export const ImageCanvas = ({ zoomOnAllowedArea = true, modifyingAllowedArea = false, keypointDefinitions, + allowComments, }: Props) => { const classes = useStyles() @@ -388,6 +389,7 @@ export const ImageCanvas = ({ imageSrc={imageSrc} RegionEditLabel={RegionEditLabel} onRegionClassAdded={onRegionClassAdded} + allowComments={allowComments} /> )} @@ -402,6 +404,7 @@ export const ImageCanvas = ({ editing region={highlightedRegion} imageSrc={imageSrc} + allowComments={allowComments} />
)} diff --git a/src/MainLayout/index.js b/src/MainLayout/index.js index 8eaf1c39..a042f397 100644 --- a/src/MainLayout/index.js +++ b/src/MainLayout/index.js @@ -186,6 +186,7 @@ export const MainLayout = ({ onChangeVideoTime={action("CHANGE_VIDEO_TIME", "newTime")} onChangeVideoPlaying={action("CHANGE_VIDEO_PLAYING", "isPlaying")} onRegionClassAdded={onRegionClassAdded} + allowComments={state.allowComments} /> ) diff --git a/src/RegionLabel/index.js b/src/RegionLabel/index.js index 37256219..c273b02b 100644 --- a/src/RegionLabel/index.js +++ b/src/RegionLabel/index.js @@ -1,6 +1,6 @@ // @flow -import React, { useState, memo } from "react" +import React, { useRef, memo } from "react" import Paper from "@material-ui/core/Paper" import { makeStyles } from "@material-ui/core/styles" import styles from "./styles" @@ -10,7 +10,7 @@ import IconButton from "@material-ui/core/IconButton" import Button from "@material-ui/core/Button" import TrashIcon from "@material-ui/icons/Delete" import CheckIcon from "@material-ui/icons/Check" -import UndoIcon from "@material-ui/icons/Undo" +import TextField from "@material-ui/core/TextField" import Select from "react-select" import CreatableSelect from "react-select/creatable" @@ -30,6 +30,7 @@ type Props = { onClose: (Region) => null, onOpen: (Region) => null, onRegionClassAdded: () => {}, + allowComments?: boolean, } export const RegionLabel = ({ @@ -42,8 +43,16 @@ export const RegionLabel = ({ onClose, onOpen, onRegionClassAdded, + allowComments, }: Props) => { const classes = useStyles() + const commentInputRef = useRef(null) + const onCommentInputClick = (_) => { + // The TextField wraps the tag with two divs + const commentInput = commentInputRef.current.children[0].children[0] + + if (commentInput) return commentInput.focus() + } return ( )} + {allowComments && ( + + onChange({ ...(region: any), comment: event.target.value }) + } + /> + )} {onClose && (
diff --git a/src/RegionLabel/styles.js b/src/RegionLabel/styles.js index 5ca1e4ae..af38a042 100644 --- a/src/RegionLabel/styles.js +++ b/src/RegionLabel/styles.js @@ -44,4 +44,8 @@ export default { }, }, }, + commentBox: { + fontWeight: 400, + fontSize: 13, + }, } diff --git a/src/RegionTags/index.js b/src/RegionTags/index.js index 0bfc7510..09b756e3 100644 --- a/src/RegionTags/index.js +++ b/src/RegionTags/index.js @@ -27,6 +27,7 @@ export const RegionTags = ({ imageSrc, RegionEditLabel, onRegionClassAdded, + allowComments, }) => { const RegionLabel = RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel @@ -118,6 +119,7 @@ export const RegionTags = ({ regions={regions} imageSrc={imageSrc} onRegionClassAdded={onRegionClassAdded} + allowComments={allowComments} />