Skip to content

Commit 03e0734

Browse files
authored
fix: Merge pull request #134 from erobaina/master
Added comment box option when creating a new area/point/polygon
2 parents 0e1b96e + 767311a commit 03e0734

File tree

9 files changed

+75
-3
lines changed

9 files changed

+75
-3
lines changed

src/Annotator/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export const Annotator = ({
9090
hideHeaderText,
9191
hideNext,
9292
hidePrev,
93+
allowComments,
9394
}: Props) => {
9495
if (typeof selectedImage === "string") {
9596
selectedImage = (images || []).findIndex((img) => img.src === selectedImage)
@@ -125,6 +126,7 @@ export const Annotator = ({
125126
history: [],
126127
videoName,
127128
keypointDefinitions,
129+
allowComments,
128130
...(annotationType === "image"
129131
? {
130132
selectedImage,

src/Annotator/index.story.js

+31
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,37 @@ storiesOf("Annotator", module)
5252
]}
5353
/>
5454
))
55+
.add("Basic - Allow Comments", () => (
56+
<Annotator
57+
onExit={actionAddon("onExit")}
58+
middlewares={middlewares}
59+
labelImages
60+
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
61+
regionTagList={["tag1", "tag2", "tag3"]}
62+
imageClsList={["Alpha", "Beta", "Charlie", "Delta"]}
63+
imageTagList={["tag1", "tag2", "tag3"]}
64+
images={[
65+
{
66+
src: exampleImage,
67+
name: "Seve's Desk",
68+
regions: testRegions,
69+
},
70+
{
71+
src: "https://loremflickr.com/100/100/cars?lock=1",
72+
name: "Frame 0036",
73+
},
74+
{
75+
src: "https://loremflickr.com/100/100/cars?lock=2",
76+
name: "Frame 0037",
77+
},
78+
{
79+
src: "https://loremflickr.com/100/100/cars?lock=3",
80+
name: "Frame 0038",
81+
},
82+
]}
83+
allowComments
84+
/>
85+
))
5586
.add("Fixed Size Container", () => (
5687
<div style={{ width: 500, height: 500 }}>
5788
<Annotator

src/Annotator/reducers/general-reducer.js

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ export default (state: MainLayoutState, action: Action) => {
142142
if (!isEqual(oldRegion.tags, action.region.tags)) {
143143
state = saveToHistory(state, "Change Region Tags")
144144
}
145+
if (!isEqual(oldRegion.comment, action.region.comment)) {
146+
state = saveToHistory(state, "Change Region Comment")
147+
}
145148
return setIn(
146149
state,
147150
[...pathToActiveImage, "regions", regionIndex],

src/DemoSite/Editor.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const examples = {
5959
name: "bianchi-oltre-xr4",
6060
},
6161
],
62+
allowComments: true,
6263
}),
6364
"Simple Segmentation": () => ({
6465
taskDescription:

src/ImageCanvas/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Props = {
6666
fullImageSegmentationMode?: boolean,
6767
autoSegmentationOptions?: Object,
6868
modifyingAllowedArea?: boolean,
69-
69+
allowComments?: Boolean,
7070
onChangeRegion: (Region) => any,
7171
onBeginRegionEdit: (Region) => any,
7272
onCloseRegionEdit: (Region) => any,
@@ -139,6 +139,7 @@ export const ImageCanvas = ({
139139
zoomOnAllowedArea = true,
140140
modifyingAllowedArea = false,
141141
keypointDefinitions,
142+
allowComments,
142143
}: Props) => {
143144
const classes = useStyles()
144145

@@ -388,6 +389,7 @@ export const ImageCanvas = ({
388389
imageSrc={imageSrc}
389390
RegionEditLabel={RegionEditLabel}
390391
onRegionClassAdded={onRegionClassAdded}
392+
allowComments={allowComments}
391393
/>
392394
</PreventScrollToParents>
393395
)}
@@ -402,6 +404,7 @@ export const ImageCanvas = ({
402404
editing
403405
region={highlightedRegion}
404406
imageSrc={imageSrc}
407+
allowComments={allowComments}
405408
/>
406409
</div>
407410
)}

src/MainLayout/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export const MainLayout = ({
187187
onChangeVideoTime={action("CHANGE_VIDEO_TIME", "newTime")}
188188
onChangeVideoPlaying={action("CHANGE_VIDEO_PLAYING", "isPlaying")}
189189
onRegionClassAdded={onRegionClassAdded}
190+
allowComments={state.allowComments}
190191
/>
191192
)
192193

src/RegionLabel/index.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import React, { useState, memo } from "react"
3+
import React, { useRef, memo } from "react"
44
import Paper from "@material-ui/core/Paper"
55
import { makeStyles } from "@material-ui/core/styles"
66
import styles from "./styles"
@@ -10,7 +10,7 @@ import IconButton from "@material-ui/core/IconButton"
1010
import Button from "@material-ui/core/Button"
1111
import TrashIcon from "@material-ui/icons/Delete"
1212
import CheckIcon from "@material-ui/icons/Check"
13-
import UndoIcon from "@material-ui/icons/Undo"
13+
import TextField from "@material-ui/core/TextField"
1414
import Select from "react-select"
1515
import CreatableSelect from "react-select/creatable"
1616

@@ -30,6 +30,7 @@ type Props = {
3030
onClose: (Region) => null,
3131
onOpen: (Region) => null,
3232
onRegionClassAdded: () => {},
33+
allowComments?: boolean,
3334
}
3435

3536
export const RegionLabel = ({
@@ -42,8 +43,16 @@ export const RegionLabel = ({
4243
onClose,
4344
onOpen,
4445
onRegionClassAdded,
46+
allowComments,
4547
}: Props) => {
4648
const classes = useStyles()
49+
const commentInputRef = useRef(null)
50+
const onCommentInputClick = (_) => {
51+
// The TextField wraps the <input> tag with two divs
52+
const commentInput = commentInputRef.current.children[0].children[0]
53+
54+
if (commentInput) return commentInput.focus()
55+
}
4756

4857
return (
4958
<Paper
@@ -142,6 +151,22 @@ export const RegionLabel = ({
142151
/>
143152
</div>
144153
)}
154+
{allowComments && (
155+
<TextField
156+
InputProps={{
157+
className: classes.commentBox,
158+
}}
159+
fullWidth
160+
multiline
161+
rows={3}
162+
ref={commentInputRef}
163+
onClick={onCommentInputClick}
164+
value={region.comment || ""}
165+
onChange={(event) =>
166+
onChange({ ...(region: any), comment: event.target.value })
167+
}
168+
/>
169+
)}
145170
{onClose && (
146171
<div style={{ marginTop: 4, display: "flex" }}>
147172
<div style={{ flexGrow: 1 }} />

src/RegionLabel/styles.js

+4
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ export default {
4444
},
4545
},
4646
},
47+
commentBox: {
48+
fontWeight: 400,
49+
fontSize: 13,
50+
},
4751
}

src/RegionTags/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const RegionTags = ({
2727
imageSrc,
2828
RegionEditLabel,
2929
onRegionClassAdded,
30+
allowComments,
3031
}) => {
3132
const RegionLabel =
3233
RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel
@@ -118,6 +119,7 @@ export const RegionTags = ({
118119
regions={regions}
119120
imageSrc={imageSrc}
120121
onRegionClassAdded={onRegionClassAdded}
122+
allowComments={allowComments}
121123
/>
122124
</div>
123125
</div>

0 commit comments

Comments
 (0)