Skip to content

Commit 203a4e3

Browse files
authored
fix: Merge pull request #118 from UniversalDataTool/various-fixes
Update Layout, Add Hotkey Help Text, Remember Show Tags
2 parents ce5266f + fa16121 commit 203a4e3

File tree

9 files changed

+60
-33
lines changed

9 files changed

+60
-33
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"react-hotkeys": "^2.0.0",
2020
"react-json-view": "^1.19.1",
2121
"react-markdown": "^4.0.6",
22-
"react-material-workspace-layout": "^0.1.17",
22+
"react-material-workspace-layout": "^1.0.4",
2323
"react-monaco-editor": "^0.25.1",
2424
"react-remove-scroll": "^2.0.4",
2525
"react-select": "^3.0.8",

src/Annotator/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import historyHandler from "./reducers/history-handler.js"
2121

2222
import useEventCallback from "use-event-callback"
2323
import makeImmutable, { without } from "seamless-immutable"
24+
import getFromLocalStorage from "../utils/get-from-local-storage"
2425

2526
type Props = {
2627
taskDescription?: string,
@@ -55,7 +56,7 @@ export const Annotator = ({
5556
selectedImage = images && images.length > 0 ? 0 : undefined,
5657
showPointDistances,
5758
pointDistancePrecision,
58-
showTags = true,
59+
showTags = getFromLocalStorage("showTags", true),
5960
enabledTools = [
6061
"select",
6162
"create-point",

src/Annotator/reducers/general-reducer.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import fixTwisted from "./fix-twisted"
1111
import convertExpandingLineToPolygon from "./convert-expanding-line-to-polygon"
1212
import clamp from "clamp"
1313
import getLandmarksWithTransform from "../../utils/get-landmarks-with-transform"
14+
import setInLocalStorage from "../../utils/set-in-local-storage"
1415

1516
const getRandomId = () => Math.random().toString().split(".")[1]
1617

@@ -809,6 +810,7 @@ export default (state: MainLayoutState, action: Action) => {
809810
}
810811
case "SELECT_TOOL": {
811812
if (action.selectedTool === "show-tags") {
813+
setInLocalStorage("showTags", !state.showTags)
812814
return setIn(state, ["showTags"], !state.showTags)
813815
} else if (action.selectedTool === "show-mask") {
814816
return setIn(state, ["showMask"], !state.showMask)

src/MainLayout/index.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import RegionSelector from "../RegionSelectorSidebarBox"
2727
import ImageSelector from "../ImageSelectorSidebarBox"
2828
import HistorySidebarBox from "../HistorySidebarBox"
2929
import useEventCallback from "use-event-callback"
30+
import getHotkeyHelpText from "../utils/get-hotkey-help-text"
3031

3132
const emptyArr = []
3233
const useStyles = makeStyles(styles)
@@ -260,17 +261,20 @@ export const MainLayout = ({
260261
iconSidebarItems={[
261262
{
262263
name: "select",
263-
helperText: "Select",
264+
helperText: "Select" + getHotkeyHelpText("select_tool"),
264265
alwaysShowing: true,
265266
},
266267
{
267268
name: "pan",
268-
helperText: "Drag/Pan",
269+
helperText:
270+
"Drag/Pan (right or middle click)" +
271+
getHotkeyHelpText("pan_tool"),
269272
alwaysShowing: true,
270273
},
271274
{
272275
name: "zoom",
273-
helperText: "Zoom In/Out",
276+
helperText:
277+
"Zoom In/Out (scroll)" + getHotkeyHelpText("zoom_tool"),
274278
alwaysShowing: true,
275279
},
276280
{
@@ -280,15 +284,16 @@ export const MainLayout = ({
280284
},
281285
{
282286
name: "create-point",
283-
helperText: "Add Point",
287+
helperText: "Add Point" + getHotkeyHelpText("create_point"),
284288
},
285289
{
286290
name: "create-box",
287-
helperText: "Add Bounding Box",
291+
helperText:
292+
"Add Bounding Box" + getHotkeyHelpText("create_bounding_box"),
288293
},
289294
{
290295
name: "create-polygon",
291-
helperText: "Add Polygon",
296+
helperText: "Add Polygon" + getHotkeyHelpText("create_polygon"),
292297
},
293298
{
294299
name: "create-expanding-line",

src/SidebarBoxContainer/index.js

-21
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,6 @@ export const SidebarBoxContainer = ({
8181
{children}
8282
</SidebarBox>
8383
)
84-
85-
return (
86-
<Paper className={classes.container}>
87-
<div className={classes.header}>
88-
{icon}
89-
<div className={classes.title}>
90-
{title} <span>{subTitle}</span>
91-
</div>
92-
<IconButton onClick={toggleExpanded} className={classes.expandButton}>
93-
<ExpandIcon className={classnames("icon", expanded && "expanded")} />
94-
</IconButton>
95-
</div>
96-
{noScroll ? (
97-
expanded ? (
98-
content
99-
) : null
100-
) : (
101-
<Collapse in={expanded}>{content}</Collapse>
102-
)}
103-
</Paper>
104-
)
10584
}
10685

10786
export default memo(

src/utils/get-from-local-storage.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default (key, defaultValue) => {
2+
try {
3+
return JSON.parse(window.localStorage[`__REACT_IMAGE_ANNOTATE_${key}`])
4+
} catch (e) {
5+
return defaultValue
6+
}
7+
}

src/utils/get-hotkey-help-text.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { getApplicationKeyMap } from "react-hotkeys"
2+
3+
export const getHotkeyHelpText = (commandName) => {
4+
const firstSequence = getApplicationKeyMap()[commandName]?.sequences?.[0]
5+
?.sequence
6+
7+
if (!firstSequence) return ""
8+
return ` (${firstSequence})`
9+
}
10+
11+
export default getHotkeyHelpText

src/utils/set-in-local-storage.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default (key, val) => {
2+
window.localStorage.setItem(
3+
`__REACT_IMAGE_ANNOTATE_${key}`,
4+
JSON.stringify(val)
5+
)
6+
}

yarn.lock

+20-4
Original file line numberDiff line numberDiff line change
@@ -5597,6 +5597,11 @@ caseless@~0.12.0:
55975597
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
55985598
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
55995599

5600+
cash-dom@^4.1.5:
5601+
version "4.1.5"
5602+
resolved "https://registry.yarnpkg.com/cash-dom/-/cash-dom-4.1.5.tgz#0ef0cf205bc7603aa4e2dfada5808442a7a0e6ca"
5603+
integrity sha512-E6MO0A6ms5iZPtexznQXWRkFEvqdPqCmdx/SiJr2PnhOQNhZNfALkLG5t83Hk3J5JELzED7PJuzhMoS2tT64XA==
5604+
56005605
ccount@^1.0.3:
56015606
version "1.0.5"
56025607
resolved "https://registry.yarnpkg.com/ccount/-/ccount-1.0.5.tgz#ac82a944905a65ce204eb03023157edf29425c17"
@@ -14551,15 +14556,16 @@ react-markdown@^4.0.6:
1455114556
unist-util-visit "^1.3.0"
1455214557
xtend "^4.0.1"
1455314558

14554-
react-material-workspace-layout@^0.1.17:
14555-
version "0.1.17"
14556-
resolved "https://registry.yarnpkg.com/react-material-workspace-layout/-/react-material-workspace-layout-0.1.17.tgz#98a997e7d8671444fafe53caa4298b6643d1b9cb"
14557-
integrity sha512-GY+jFZ14IYKyzIW/KI8/R0Mttb5dTRdYDKdj++YAU/Z3HSQ7kZJ678mv5Nl7X0o081IpMFg5CRiBvvdozUmBtQ==
14559+
react-material-workspace-layout@^1.0.4:
14560+
version "1.0.4"
14561+
resolved "https://registry.yarnpkg.com/react-material-workspace-layout/-/react-material-workspace-layout-1.0.4.tgz#ff1ade3b322bdc99d62eb2f1da3080555f07b4e6"
14562+
integrity sha512-EJjmun16OxRcbNnYX+49LZBTcYhLAlHRa38wC1S5BZi0TKQkh+d4FN/Xs60pnLLQeoJ7nEyEjQgNCLQu9ESVbw==
1455814563
dependencies:
1455914564
"@material-ui/core" "^4.10.0"
1456014565
"@material-ui/icons" "^4.9.1"
1456114566
classnames "^2.2.6"
1456214567
react "^16.13.1"
14568+
react-resize-panel "^0.3.5"
1456314569
react-use-dimensions "^1.2.1"
1456414570
use-event-callback "^0.1.0"
1456514571

@@ -14610,6 +14616,16 @@ react-remove-scroll@^2.0.4:
1461014616
tslib "^1.0.0"
1461114617
use-sidecar "^1.0.1"
1461214618

14619+
react-resize-panel@^0.3.5:
14620+
version "0.3.5"
14621+
resolved "https://registry.yarnpkg.com/react-resize-panel/-/react-resize-panel-0.3.5.tgz#43aa3450bf5b5a2566b40c4201445ced96c2a905"
14622+
integrity sha512-iyHOFTrSt+WV4Ilzi81x6KH3FU7VsGP736rmxepwGrgAEATmCvXzZdluTm3NpsptP7aC3hLODmXwnxusyA393A==
14623+
dependencies:
14624+
cash-dom "^4.1.5"
14625+
classnames "^2.2.6"
14626+
lodash.debounce "^4.0.8"
14627+
react-draggable "^4.0.3"
14628+
1461314629
react-scripts@^3.4.1:
1461414630
version "3.4.1"
1461514631
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-3.4.1.tgz#f551298b5c71985cc491b9acf3c8e8c0ae3ada0a"

0 commit comments

Comments
 (0)