Skip to content

Commit 2509d8c

Browse files
authored
feat: Add Creatable Classifications
changed select to creatableselect for classification
2 parents 60c1c91 + 263662c commit 2509d8c

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

src/Annotator/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ export const Annotator = ({
132132
dispatchToReducer(action)
133133
})
134134

135+
const onRegionClassAdded = useEventCallback((cls) => {
136+
dispatchToReducer({
137+
type: "ON_CLS_ADDED",
138+
cls: cls,
139+
})
140+
})
141+
135142
useEffect(() => {
136143
if (!selectedImage) return
137144
dispatchToReducer({
@@ -148,6 +155,7 @@ export const Annotator = ({
148155
alwaysShowPrevButton={Boolean(onPrevImage)}
149156
state={state}
150157
dispatch={dispatch}
158+
onRegionClassAdded={onRegionClassAdded}
151159
/>
152160
</SettingsProvider>
153161
)

src/Annotator/reducers/general-reducer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import convertExpandingLineToPolygon from "./convert-expanding-line-to-polygon"
1313
const getRandomId = () => Math.random().toString().split(".")[1]
1414

1515
export default (state: MainLayoutState, action: Action) => {
16+
if (action.type === "ON_CLS_ADDED" && action.cls && action.cls !== "") {
17+
const oldRegionClsList = state.regionClsList
18+
const newState = {
19+
...state,
20+
regionClsList: oldRegionClsList.concat(action.cls),
21+
}
22+
return newState
23+
}
24+
1625
// Throttle certain actions
1726
if (action.type === "MOUSE_MOVE") {
1827
if (Date.now() - ((state: any).lastMouseMoveCall || 0) < 16) return state

src/ImageCanvas/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type Props = {
6565
duration?: number,
6666
}) => any,
6767
onChangeVideoTime: (number) => any,
68+
onRegionClassAdded: () => {},
6869
onChangeVideoPlaying?: Function,
6970
}
7071

@@ -106,6 +107,7 @@ export const ImageCanvas = ({
106107
onDeleteRegion,
107108
onChangeVideoTime,
108109
onChangeVideoPlaying,
110+
onRegionClassAdded,
109111
}: Props) => {
110112
const classes = useStyles()
111113

@@ -322,6 +324,7 @@ export const ImageCanvas = ({
322324
layoutParams={layoutParams}
323325
imageSrc={imageSrc}
324326
RegionEditLabel={RegionEditLabel}
327+
onRegionClassAdded={onRegionClassAdded}
325328
/>
326329
</PreventScrollToParents>
327330
)}

src/MainLayout/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Props = {
3434
dispatch: (Action) => any,
3535
alwaysShowNextButton?: boolean,
3636
alwaysShowPrevButton?: boolean,
37+
onRegionClassAdded: () => {},
3738
}
3839

3940
export const MainLayout = ({
@@ -42,6 +43,7 @@ export const MainLayout = ({
4243
alwaysShowNextButton = false,
4344
alwaysShowPrevButton = false,
4445
RegionEditLabel,
46+
onRegionClassAdded,
4547
}: Props) => {
4648
const classes = useStyles()
4749
const settings = useSettings()
@@ -223,6 +225,7 @@ export const MainLayout = ({
223225
"CHANGE_VIDEO_PLAYING",
224226
"isPlaying"
225227
)}
228+
onRegionClassAdded={onRegionClassAdded}
226229
/>
227230
</div>
228231
)}

src/RegionLabel/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import TrashIcon from "@material-ui/icons/Delete"
1212
import CheckIcon from "@material-ui/icons/Check"
1313
import UndoIcon from "@material-ui/icons/Undo"
1414
import Select from "react-select"
15+
import CreatableSelect from "react-select/creatable"
16+
1517
import { asMutable } from "seamless-immutable"
1618

1719
const useStyles = makeStyles(styles)
@@ -27,6 +29,7 @@ type Props = {
2729
onChange: (Region) => null,
2830
onClose: (Region) => null,
2931
onOpen: (Region) => null,
32+
onRegionClassAdded: () => {},
3033
}
3134

3235
export const RegionLabel = ({
@@ -38,6 +41,7 @@ export const RegionLabel = ({
3841
onChange,
3942
onClose,
4043
onOpen,
44+
onRegionClassAdded,
4145
}: Props) => {
4246
const classes = useStyles()
4347

@@ -100,14 +104,17 @@ export const RegionLabel = ({
100104
</div>
101105
{(allowedClasses || []).length > 0 && (
102106
<div style={{ marginTop: 6 }}>
103-
<Select
107+
<CreatableSelect
104108
placeholder="Classification"
105-
onChange={(o) =>
106-
onChange({
109+
onChange={(o, actionMeta) => {
110+
if (actionMeta.action == "create-option") {
111+
onRegionClassAdded(o.value)
112+
}
113+
return onChange({
107114
...(region: any),
108115
cls: o.value,
109116
})
110-
}
117+
}}
111118
value={
112119
region.cls ? { label: region.cls, value: region.cls } : null
113120
}

src/RegionTags/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const RegionTags = ({
2626
layoutParams,
2727
imageSrc,
2828
RegionEditLabel,
29+
onRegionClassAdded,
2930
}) => {
3031
const RegionLabel =
3132
RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel
@@ -116,6 +117,7 @@ export const RegionTags = ({
116117
region={region}
117118
regions={regions}
118119
imageSrc={imageSrc}
120+
onRegionClassAdded={onRegionClassAdded}
119121
/>
120122
</div>
121123
</div>

0 commit comments

Comments
 (0)