Skip to content

Commit fc13e2c

Browse files
updated code, to update options for regionclslist when new cls is added
1 parent 1863398 commit fc13e2c

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

src/Annotator/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ export const Annotator = ({
121121
dispatchToReducer(action)
122122
})
123123

124+
const onRegionLabelAdded = (cls) => {
125+
dispatchToReducer({
126+
type: "ON_CLS_ADDED",
127+
cls: cls,
128+
})
129+
}
130+
124131
useEffect(() => {
125132
if (!selectedImage) return
126133
dispatchToReducer({
@@ -137,6 +144,7 @@ export const Annotator = ({
137144
alwaysShowPrevButton={Boolean(onPrevImage)}
138145
state={state}
139146
dispatch={dispatch}
147+
onRegionLabelAdded={onRegionLabelAdded}
140148
/>
141149
</SettingsProvider>
142150
)

src/Annotator/reducers/history-handler.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ export default (reducer) => {
2626
const prevState = state
2727
const nextState = reducer(state, action)
2828

29+
if (action.type === "ON_CLS_ADDED" && action.cls && action.cls !== "") {
30+
const oldRegionClsList = state.regionClsList
31+
const newState = {
32+
...state,
33+
regionClsList: oldRegionClsList.concat(action.cls),
34+
}
35+
return newState
36+
}
37+
2938
if (action.type === "RESTORE_HISTORY") {
3039
if (state.history.length > 0) {
3140
return setIn(

src/ImageCanvas/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type Props = {
7979
duration?: number,
8080
}) => any,
8181
onChangeVideoTime: (number) => any,
82+
onRegionLabelAdded: () => {},
8283
}
8384

8485
const getDefaultMat = () => Matrix.from(1, 0, 0, 1, -10, -10)
@@ -118,6 +119,7 @@ export default ({
118119
onDeleteRegion,
119120
onChangeVideoTime,
120121
onChangeVideoPlaying,
122+
onRegionLabelAdded,
121123
}: Props) => {
122124
const classes = useStyles()
123125

@@ -441,6 +443,7 @@ export default ({
441443
layoutParams={layoutParams}
442444
imageSrc={imageSrc}
443445
RegionEditLabel={RegionEditLabel}
446+
onRegionLabelAdded={onRegionLabelAdded}
444447
/>
445448
</PreventScrollToParents>
446449
)}

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+
onRegionLabelAdded: () => {},
3738
}
3839

3940
export default ({
@@ -42,6 +43,7 @@ export default ({
4243
alwaysShowNextButton = false,
4344
alwaysShowPrevButton = false,
4445
RegionEditLabel,
46+
onRegionLabelAdded,
4547
}: Props) => {
4648
const classes = useStyles()
4749
const settings = useSettings()
@@ -220,6 +222,7 @@ export default ({
220222
"CHANGE_VIDEO_PLAYING",
221223
"isPlaying"
222224
)}
225+
onRegionLabelAdded={onRegionLabelAdded}
223226
/>
224227
</div>
225228
)}

src/RegionLabel/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Props = {
2929
onChange: (Region) => null,
3030
onClose: (Region) => null,
3131
onOpen: (Region) => null,
32+
onRegionLabelAdded: () => {},
3233
}
3334

3435
export const RegionLabel = ({
@@ -40,6 +41,7 @@ export const RegionLabel = ({
4041
onChange,
4142
onClose,
4243
onOpen,
44+
onRegionLabelAdded,
4345
}: Props) => {
4446
const classes = useStyles()
4547

@@ -104,12 +106,15 @@ export const RegionLabel = ({
104106
<div style={{ marginTop: 6 }}>
105107
<CreatableSelect
106108
placeholder="Classification"
107-
onChange={(o) =>
108-
onChange({
109+
onChange={(o, actionMeta) => {
110+
if (actionMeta.action == "create-option") {
111+
onRegionLabelAdded(o.value)
112+
}
113+
return onChange({
109114
...(region: any),
110115
cls: o.value,
111116
})
112-
}
117+
}}
113118
value={
114119
region.cls ? { label: region.cls, value: region.cls } : null
115120
}

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+
onRegionLabelAdded,
2930
}) => {
3031
const RegionLabel =
3132
RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel
@@ -115,6 +116,7 @@ export const RegionTags = ({
115116
region={region}
116117
regions={regions}
117118
imageSrc={imageSrc}
119+
onRegionLabelAdded={onRegionLabelAdded}
118120
/>
119121
</div>
120122
</div>

0 commit comments

Comments
 (0)