summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-05-16 13:45:48 +0200
committerGitHub <noreply@github.com>2022-05-16 13:45:48 +0200
commit00b5ee4bd423d8d9682a9ed9cd2af7c19a715459 (patch)
tree8d157d2553438dd9ac59983bc0fdd6ca63bbdb4b /opendc-web/opendc-web-ui/src
parente35d7c49856d8fb5965a315976ac6fdd6c9fb718 (diff)
parent63c88a4ce70b065a568992cde28135818e0031b9 (diff)
merge: Update build and runtime dependencies (#86)
This pull request updates the build and runtime dependencies used by OpenDC to their latest version compatible with the project. ## Implementation Notes :hammer_and_pick: * Update simulator dependency versions * Fix hotkeys support for React 18 * Update dependencies of web UI * Remove unused dependencies ## Breaking API Changes :warning: * N/A
Diffstat (limited to 'opendc-web/opendc-web-ui/src')
-rw-r--r--opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss3
-rw-r--r--opendc-web/opendc-web-ui/src/components/topologies/TopologyMap.js27
-rw-r--r--opendc-web/opendc-web-ui/src/components/topologies/map/MapStage.js26
-rw-r--r--opendc-web/opendc-web-ui/src/hotkeys.js6
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/building.js2
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js2
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/room.js2
7 files changed, 30 insertions, 38 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss b/opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss
index 0aa63ee6..07b7b1d0 100644
--- a/opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss
+++ b/opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss
@@ -20,7 +20,8 @@
* SOFTWARE.
*/
-.contextSelector {
+.contextSelector.contextSelector {
+ // Ensure this selector has precedence over the default one
margin-right: 20px;
--pf-c-context-selector__toggle--PaddingTop: var(--pf-global--spacer--sm);
diff --git a/opendc-web/opendc-web-ui/src/components/topologies/TopologyMap.js b/opendc-web/opendc-web-ui/src/components/topologies/TopologyMap.js
index 2f27749f..47235c7e 100644
--- a/opendc-web/opendc-web-ui/src/components/topologies/TopologyMap.js
+++ b/opendc-web/opendc-web-ui/src/components/topologies/TopologyMap.js
@@ -20,7 +20,7 @@
* SOFTWARE.
*/
-import React, { useState } from 'react'
+import React, { useState, useRef } from 'react'
import {
Bullseye,
Drawer,
@@ -31,8 +31,6 @@ import {
Spinner,
Title,
} from '@patternfly/react-core'
-import { configure, HotKeys } from 'react-hotkeys'
-import { KeymapConfiguration } from '../../hotkeys'
import MapStage from './map/MapStage'
import Collapse from './map/controls/Collapse'
import { useSelector } from 'react-redux'
@@ -45,10 +43,7 @@ function TopologyMap() {
const [isExpanded, setExpanded] = useState(true)
const panelContent = <TopologySidebar interactionLevel={interactionLevel} onClose={() => setExpanded(false)} />
- // Make sure that holding down a key will generate repeated events
- configure({
- ignoreRepeatedEventsWhenKeyHeldDown: false,
- })
+ const hotkeysRef = useRef()
return topologyIsLoading ? (
<Bullseye>
@@ -60,16 +55,14 @@ function TopologyMap() {
</EmptyState>
</Bullseye>
) : (
- <HotKeys keyMap={KeymapConfiguration} allowChanges={true} className="full-height">
- <Drawer isExpanded={isExpanded}>
- <DrawerContent panelContent={panelContent}>
- <DrawerContentBody>
- <MapStage />
- <Collapse onClick={() => setExpanded(true)} />
- </DrawerContentBody>
- </DrawerContent>
- </Drawer>
- </HotKeys>
+ <Drawer isExpanded={isExpanded} className="full-height">
+ <DrawerContent panelContent={panelContent}>
+ <DrawerContentBody>
+ <MapStage hotkeysRef={hotkeysRef} />
+ <Collapse onClick={() => setExpanded(true)} />
+ </DrawerContentBody>
+ </DrawerContent>
+ </Drawer>
)
}
diff --git a/opendc-web/opendc-web-ui/src/components/topologies/map/MapStage.js b/opendc-web/opendc-web-ui/src/components/topologies/map/MapStage.js
index d8735cf1..7b96f548 100644
--- a/opendc-web/opendc-web-ui/src/components/topologies/map/MapStage.js
+++ b/opendc-web/opendc-web-ui/src/components/topologies/map/MapStage.js
@@ -1,5 +1,6 @@
import React, { useRef, useState, useContext } from 'react'
-import { HotKeys } from 'react-hotkeys'
+import PropTypes from 'prop-types'
+import { useHotkeys } from 'react-hotkeys-hook'
import { Stage } from 'react-konva'
import { MAP_MAX_SCALE, MAP_MIN_SCALE, MAP_MOVE_PIXELS_PER_EVENT, MAP_SCALE_PER_EVENT } from './MapConstants'
import { ReactReduxContext } from 'react-redux'
@@ -11,10 +12,10 @@ import ObjectHoverLayer from './layers/ObjectHoverLayer'
import ScaleIndicator from './controls/ScaleIndicator'
import Toolbar from './controls/Toolbar'
-function MapStage() {
+function MapStage({ hotkeysRef }) {
const reduxContext = useContext(ReactReduxContext)
- const { ref, width = 100, height = 100 } = useResizeObserver()
const stageRef = useRef(null)
+ const { width = 100, height = 100 } = useResizeObserver({ ref: stageRef.current?.attrs?.container })
const [[x, y], setPos] = useState([0, 0])
const [scale, setScale] = useState(1)
@@ -48,16 +49,15 @@ function MapStage() {
download.click()
}
- const handlers = {
- MOVE_LEFT: () => moveWithDelta(MAP_MOVE_PIXELS_PER_EVENT, 0),
- MOVE_RIGHT: () => moveWithDelta(-MAP_MOVE_PIXELS_PER_EVENT, 0),
- MOVE_UP: () => moveWithDelta(0, MAP_MOVE_PIXELS_PER_EVENT),
- MOVE_DOWN: () => moveWithDelta(0, -MAP_MOVE_PIXELS_PER_EVENT),
- }
+ useHotkeys('left, a', () => moveWithDelta(MAP_MOVE_PIXELS_PER_EVENT, 0), { element: hotkeysRef.current })
+ useHotkeys('right, d', () => moveWithDelta(-MAP_MOVE_PIXELS_PER_EVENT, 0), { element: hotkeysRef.current })
+ useHotkeys('up, w', () => moveWithDelta(0, MAP_MOVE_PIXELS_PER_EVENT), { element: hotkeysRef.current })
+ useHotkeys('down, s', () => moveWithDelta(0, -MAP_MOVE_PIXELS_PER_EVENT), { element: hotkeysRef.current })
return (
- <HotKeys handlers={handlers} allowChanges={true} innerRef={ref} className={mapContainer}>
+ <>
<Stage
+ className={mapContainer}
ref={stageRef}
onWheel={onZoom}
onDragEnd={onDragEnd}
@@ -76,8 +76,12 @@ function MapStage() {
</Stage>
<ScaleIndicator scale={scale} />
<Toolbar onZoom={onZoomButton} onExport={onExport} />
- </HotKeys>
+ </>
)
}
+MapStage.propTypes = {
+ hotkeysRef: PropTypes.object.isRequired,
+}
+
export default MapStage
diff --git a/opendc-web/opendc-web-ui/src/hotkeys.js b/opendc-web/opendc-web-ui/src/hotkeys.js
deleted file mode 100644
index 1c4d2621..00000000
--- a/opendc-web/opendc-web-ui/src/hotkeys.js
+++ /dev/null
@@ -1,6 +0,0 @@
-export const KeymapConfiguration = {
- MOVE_LEFT: ['a', 'left'],
- MOVE_RIGHT: ['d', 'right'],
- MOVE_UP: ['w', 'up'],
- MOVE_DOWN: ['s', 'down'],
-}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topology/building.js b/opendc-web/opendc-web-ui/src/redux/actions/topology/building.js
index e430da2e..c12417b9 100644
--- a/opendc-web/opendc-web-ui/src/redux/actions/topology/building.js
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/building.js
@@ -1,4 +1,4 @@
-import { uuid } from 'uuidv4'
+import { v4 as uuid } from 'uuid'
import { addRoom, deleteRoom } from './room'
export const START_NEW_ROOM_CONSTRUCTION = 'START_NEW_ROOM_CONSTRUCTION'
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js b/opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js
index 308acaa6..1f65952a 100644
--- a/opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js
@@ -1,4 +1,4 @@
-import { uuid } from 'uuidv4'
+import { v4 as uuid } from 'uuid'
export const EDIT_RACK_NAME = 'EDIT_RACK_NAME'
export const DELETE_RACK = 'DELETE_RACK'
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topology/room.js b/opendc-web/opendc-web-ui/src/redux/actions/topology/room.js
index fd2d8cdc..350c1d92 100644
--- a/opendc-web/opendc-web-ui/src/redux/actions/topology/room.js
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/room.js
@@ -1,4 +1,4 @@
-import { uuid } from 'uuidv4'
+import { v4 as uuid } from 'uuid'
import {
DEFAULT_RACK_SLOT_CAPACITY,
DEFAULT_RACK_POWER_CAPACITY,