Skip to content

Commit cb6f1f2

Browse files
authored
fix: Merge pull request #80 from UniversalDataTool/fix/video-annotation-region-error
fix video region undefined error
2 parents ad51abc + 2877555 commit cb6f1f2

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

src/Annotator/reducers/get-implied-video-regions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export default (
9090
}
9191
break
9292
}
93+
default:
94+
break
9395
}
9496
}
9597

src/Annotator/reducers/video-reducer.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default (state: MainLayoutVideoAnnotationState, action: Action) => {
1212
const copyImpliedRegions = () => {
1313
return setIn(
1414
saveToHistory(state, "Add Keyframe"),
15-
["keyframes", state.currentVideoTime],
15+
["keyframes", state.currentVideoTime || 0],
1616
{
1717
regions: getImpliedVideoRegions(
1818
state.keyframes,
@@ -46,6 +46,8 @@ export default (state: MainLayoutVideoAnnotationState, action: Action) => {
4646
case "DELETE_KEYFRAME": {
4747
return setIn(state, ["keyframes"], without(state.keyframes, action.time))
4848
}
49+
default:
50+
break
4951
}
5052

5153
// Before the user modifies regions, copy the interpolated regions over to a
@@ -55,8 +57,6 @@ export default (state: MainLayoutVideoAnnotationState, action: Action) => {
5557
case "BEGIN_BOX_TRANSFORM":
5658
case "BEGIN_MOVE_POINT":
5759
case "BEGIN_MOVE_POLYGON_POINT":
58-
case "BEGIN_BOX_TRANSFORM":
59-
case "BEGIN_MOVE_POLYGON_POINT":
6060
case "ADD_POLYGON_POINT":
6161
case "SELECT_REGION":
6262
case "CHANGE_REGION":
@@ -69,8 +69,13 @@ export default (state: MainLayoutVideoAnnotationState, action: Action) => {
6969
case "create-polygon":
7070
case "create-box":
7171
return copyImpliedRegions()
72+
default:
73+
break
7274
}
75+
break
7376
}
77+
default:
78+
break
7479
}
7580
}
7681

src/Annotator/video.story.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// @flow
2+
3+
import React from "react"
4+
5+
import { storiesOf } from "@storybook/react"
6+
import { action } from "@storybook/addon-actions"
7+
import Annotator from "./"
8+
9+
storiesOf("Annotator(video)", module).add("Video Annotator", () => {
10+
const props = {
11+
regionClsList: ["valid", "invalid"],
12+
enabledTools: ["select", "create-box", "create-polygon", "create-point"],
13+
keyframes: {
14+
"0": {
15+
regions: [
16+
{
17+
id: "910517662556203",
18+
cls: "valid",
19+
color: "#f44336",
20+
type: "box",
21+
x: 0.12195121951219515,
22+
y: 0.28726287262872624,
23+
w: 0.2606707317073171,
24+
h: 0.4769647696476965,
25+
},
26+
],
27+
},
28+
"2656": {
29+
regions: [
30+
{
31+
id: "910517662556203",
32+
cls: "valid",
33+
color: "#f44336",
34+
type: "box",
35+
x: 0.13109756097560976,
36+
y: 0.08672086720867206,
37+
w: 0.3445121951219512,
38+
h: 0.7913279132791328,
39+
},
40+
],
41+
},
42+
},
43+
onExit: action("onExit"),
44+
taskDescription: "",
45+
videoName: "",
46+
videoTime: 0,
47+
videoSrc:
48+
"https://s3.amazonaws.com/asset.workaround.online/SampleVideo_1280x720_1mb.mp4",
49+
}
50+
return <Annotator {...props} />
51+
})

src/HistorySidebarBox/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import UndoIcon from "@material-ui/icons/Undo"
1313
import moment from "moment"
1414
import { grey } from "@material-ui/core/colors"
1515
import isEqual from "lodash/isEqual"
16+
import Box from "@material-ui/core/Box"
1617

1718
const useStyles = makeStyles({
1819
emptyText: {
@@ -24,6 +25,8 @@ const useStyles = makeStyles({
2425
},
2526
})
2627

28+
const listItemTextStyle = { paddingLeft: 16 }
29+
2730
export const HistorySidebarBox = ({
2831
history,
2932
onRestoreHistory,
@@ -45,6 +48,7 @@ export const HistorySidebarBox = ({
4548
{history.map(({ name, time }, i) => (
4649
<ListItem button dense key={i}>
4750
<ListItemText
51+
style={listItemTextStyle}
4852
primary={name}
4953
secondary={moment(time).format("LT")}
5054
/>

src/KeyframesSelectorSidebarBox/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ const KeyframeRow = styled("div")({
4343
},
4444
})
4545

46-
const KeyframesSelector = ({
46+
const KeyframesSelectorSidebarBox = ({
4747
currentVideoTime,
4848
keyframes,
4949
onChangeVideoTime,
5050
onDeleteKeyframe,
5151
}) => {
5252
const keyframeTimes = Object.keys(keyframes).map((t) => parseInt(t))
53+
5354
return (
5455
<SidebarBoxContainer
5556
title="Keyframes"
@@ -67,7 +68,7 @@ const KeyframesSelector = ({
6768
<div className="time">
6869
{getTimeString(t, 2)}
6970
<span className="regionCount">
70-
({(keyframes[t].regions || []).length})
71+
({(keyframes[t]?.regions || []).length})
7172
</span>
7273
</div>
7374
<div className="trash">
@@ -85,4 +86,4 @@ const KeyframesSelector = ({
8586
)
8687
}
8788

88-
export default KeyframesSelector
89+
export default KeyframesSelectorSidebarBox

0 commit comments

Comments
 (0)