-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jh lab editor gui #66
Draft
jhurst502
wants to merge
187
commits into
main
Choose a base branch
from
jh-lab-editor-gui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,684
−342
Draft
Changes from 39 commits
Commits
Show all changes
187 commits
Select commit
Hold shift + click to select a range
dea409c
Initial setup of component structure.
jhurst502 16bd1b8
Imported GUI prototype
jhurst502 1e3be9e
Added context menu
jhurst502 c36131d
Added removable VMs
jhurst502 bacceaa
Added toggle feature to wan node. Ports are now visable
jhurst502 1ea77b5
Added warning banner/alert
AClifton22 3fa54f7
Nodes can be added independently of other nodes. Fixed some issues wi…
jhurst502 88d25f9
remove node on backspace and delete
jhurst502 dbec0c9
created skeleton of 503 service unavailable page and added it to routes
WarriorAchilles 9bc83e8
added text and styling to 503 page
WarriorAchilles f1d6d85
Added feature to remove node on keyboard event
jhurst502 e6f6268
Cleaned up unnecessary functions. Fixed issue with nodes occasionally…
jhurst502 5e1360b
Nodes can be duplicated.
jhurst502 9a4da0d
Changes to alert
AClifton22 52094c7
Added Alerts to routes and removed from Layout.
AClifton22 6b7aafc
Prevent image drag in firefox, fixed duplicate node error on switch, …
jhurst502 7e4cdcb
Centered text on banner alert and removed Warning.
AClifton22 bd936db
cleaned up the styling by putting it in its own file
WarriorAchilles 135b752
Prevented multiple connections on one port. Gave VM 4 port default.
jhurst502 3ccbdce
added an image to the page
WarriorAchilles a472e9a
Added number of ports selection when creating new switches
jhurst502 89d89d9
Changes to layout of ports on switch node
jhurst502 de3ac56
Add scaffolding for selectable user roles in the admin panel
johnpcooke94 6827b12
Added switch selection images.
jhurst502 8db8517
Changes to switch selection menu.
jhurst502 902f048
Added event listener for ctrl+z / ctrl+shift+z
jhurst502 47ae760
finished basic static 503 page
WarriorAchilles b87e487
Fixed issue with multiple context menus being able to appear at once.
jhurst502 7cf396c
Added rename feature in new context menu. Rename on double click does…
jhurst502 b722e68
Styling for close button in select switch menu
jhurst502 a5c9007
Fixes to context menu
jhurst502 c994d95
Added banner files
AClifton22 d90705d
Merge branch 'master' into Alert
AClifton22 75e6dd8
started work on adaptive 503
WarriorAchilles 4c78999
removed Banner files, added modules style path to Alert which removed…
AClifton22 3674a48
Up-to-date-branch
AClifton22 af42bb6
Changed nodes on 5 port switch
jhurst502 df708d9
Fixed issue of Name disappearing when using double click to rename. D…
jhurst502 f1c0475
Add basic request functionality for committing role changes in admin …
johnpcooke94 558ee51
Fix bug in commit role change functionality
johnpcooke94 180adff
Update style on commit button in user panel
johnpcooke94 54be3a4
added basic adaptability functionality
WarriorAchilles 307039f
Merge branch 'master' into ZE-adaptive-503-page
WarriorAchilles b96e805
Added properties to alert, type of alerts and css for each type.
AClifton22 113c847
Fixed issue with crash after deleting certain nodes. Changed naming o…
jhurst502 b27b126
Prevent connecting two ports belonging to the same node
jhurst502 58c6d7a
Updated favicon.
jbello0909 e3b67bb
Merge pull request #61 from ius-csg/update/fav-icon
jasekiw cdb2653
Update Axios
jasekiw 721835b
Merge pull request #62 from ius-csg/update/axios
jasekiw dd60ad8
added conditional rendering based on props
WarriorAchilles 6e6a86a
Changes Jason requested
AClifton22 bff41d1
Added different colored links for increased visibility.
jhurst502 fa9d828
Update admin panel user role update functionality with a cleaner impl…
johnpcooke94 6d0745e
Clean up user role implementation in UserListItem.tsx
johnpcooke94 3467923
Added scss module for SelectSwitch component. Slide in animation on t…
jhurst502 a44a9d6
refactored code so most of it was it its own component that is then r…
WarriorAchilles bbb5135
edited conditional rendering
WarriorAchilles 70c58e4
Prevent two nodes from connecting more than once
jhurst502 c9f95ab
Added bootstrap buttons to Diagram component.
jhurst502 13087bb
Implement storing node count as state to fix error with deleting node…
jhurst502 9d39324
Change language on user admin panel for saving changes to user roles
johnpcooke94 5abc0d5
Changed Alert.tsx file to AlertNotification.tsx and module
AClifton22 4eab8dc
Move save button on admin users pane to sit above the table and updat…
johnpcooke94 36556c4
Merge pull request #60 from ius-csg/jc-update-user-role
jasekiw 55174e1
Merge pull request #58 from ius-csg/Alert
jasekiw 6102b1c
Make style changes to avoid user the status notification on user role…
johnpcooke94 c384fa3
More link colors!
jhurst502 04ee04f
Option to add VM ports in the context menu.
jhurst502 e34bc74
Removed rule preventing multiple connections between nodes. Crash on …
jhurst502 7648118
Fixed issue with links being the same color when nodeCount is not inc…
jhurst502 b46a3f9
fixed restoration time rendering
WarriorAchilles c908179
fixed merge conflicts
WarriorAchilles e0db734
Applied patch to beautiful-react-diagrams to fix crash on deleting no…
jhurst502 70961c9
Removed setDeleting state. Used a better way to prevent changing colo…
jhurst502 2051c8f
Add a warning to the admin panel when the user attempts to change the…
johnpcooke94 96a1b8e
Changed warning on to use React Bootstrap modal instead of vanilla al…
johnpcooke94 d863a49
Fix an issue with updating user roles when the user changes the dropd…
johnpcooke94 89060a0
Take out console logs
jhurst502 d3c5080
Removed commented out code. Fixed issue with duplicated nodes having …
jhurst502 bbd7ebd
Cleaned up some SonarLint codesmells.
jhurst502 8a01ec5
Connect user pane to webstate to update webstate if user changes thei…
johnpcooke94 290b62a
Update webstate and reload UI if admin user changes their own role to…
johnpcooke94 0814024
Merge branch 'dev' into jc-update-user-role
johnpcooke94 b1e2ae6
Separate commit status text into its own component for better readabi…
johnpcooke94 eb8c616
Update redirect logic to use react-router redirect component when use…
johnpcooke94 78aface
Merge pull request #67 from ius-csg/jc-update-user-role
jasekiw 1f5a7f5
merged MaintenanceInfoLayout.tsx code into ServiceUnavailable.tsx, mo…
WarriorAchilles 5020655
Merge pull request #63 from ius-csg/ZE-adaptive-503-page
jasekiw dc5a0fe
Implement search users function in admin panel
johnpcooke94 70da7f2
Merge branch 'dev' into jc-update-user-role
johnpcooke94 874c582
Renamed instances of 'PNG' to 'png'
jhurst502 6d60b5d
Refactored styling to css classes
jhurst502 cb8cc6e
Update src/components/LabEditorGUI/ContextMenu.tsx
jhurst502 15adb92
Changed Typscript types of 'any' on types that did not involve beauti…
jhurst502 933e1e9
Fixed merge conflict
jhurst502 2b511a6
Created component for switch button to remove duplicate logic
jhurst502 b8ebdb8
Make save button inline with search bar on user panel
johnpcooke94 826fbec
tag editor for module creation/editing
jhenry09 f976341
fix merge
jhenry09 4976bd3
Update user search function to use Array.filter()
johnpcooke94 eb32ff0
Add api call
zkhussain 1e12541
Enable user to extend the lab
zkhussain 2ae8bb1
Update display of modules
zkhussain 0a639ae
Remove module changes
zkhussain 8ee689c
Update user search function for more consistent behavior, accounting …
johnpcooke94 8fcc86d
Update some CSS for current CSS3 compatibility
johnpcooke94 2b55bf7
Fix the remainder of CSS for CSS3 compatibility
johnpcooke94 c7aabbc
Fix CSS code smells, mostly duplicate declarations
johnpcooke94 0e1af25
Fix some SonarCloud code smells
johnpcooke94 bf548d5
Fix more code smells
johnpcooke94 38d1e24
Rename AdminPanel.tsx to AdminPage.tsx
johnpcooke94 ca123db
Rename Contact.tsx to Contact.tsx
johnpcooke94 a0bc793
Fix more code smells
johnpcooke94 4509968
Fix more code smells
johnpcooke94 bb178dd
Fix yet more code smells!
johnpcooke94 775415f
Create sonar.yml
johnpcooke94 7a4af2d
Fix one more code smell
johnpcooke94 1be855f
Merge pull request #75 from ius-csg/jc/pay-tech-debt
Cliftonz e779859
Add sonar-project.properties file for sonarcloud
johnpcooke94 1462c6b
Merge branch 'dev' into jc/add-sonar-action
johnpcooke94 914bf8c
Merge pull request #76 from ius-csg/jc/add-sonar-action
Cliftonz 372caa0
Fix delay in lab time extension
zkhussain 7cb573b
Show a popup if the lab times up
zkhussain a0e2e73
Fix code smells
zkhussain 3aa6cf8
Add build.yml action to build project with Yarn
johnpcooke94 6224ebc
Fix issue in build.yml
johnpcooke94 e9abc7b
Install dependencies before attempting to build
johnpcooke94 941bd17
Dump GitHub CI variable before building
johnpcooke94 9f7fa1b
Hide button instead of disabling it
zkhussain 7037cae
Fix TSLint issues and run TSLint before building
johnpcooke94 3f8cbf3
Change name of SonarCloud workflow for better clarity
johnpcooke94 e591279
Merge pull request #78 from ius-csg/jc/add-build-actions
Cliftonz 680a578
Merge branch 'dev' into jc-update-user-role
johnpcooke94 b3001fd
Fix issue in build.yml causing unexpected job cancellation
johnpcooke94 04b0c9e
Merge pull request #70 from ius-csg/jc-update-user-role
jasekiw db69e36
Raise job timeout time in build.yml to address early job cancellation
johnpcooke94 a9822e9
Merge pull request #79 from ius-csg/jc/fix-actions
Cliftonz cfada4d
Merge remote-tracking branch 'origin/dev' into zh/extend-temp-lab-end…
zkhussain 0103647
Create popup component
zkhussain 1c3f7b0
Make requested changes
zkhussain d21b107
updated page and components to reflect backend changes
WarriorAchilles 52519fb
Merge pull request #73 from ius-csg/zh/extend-temp-lab-end-time
jasekiw ec10e0a
updated Maintenance type to reflect what's coming in from backend, as…
WarriorAchilles 1274914
Merge branch 'dev' into ze/503-page-updates
WarriorAchilles b9cde22
changed so either the maintenance message or the down message will be…
WarriorAchilles dd43c65
modified ServiceMessage component to display date and time in a clean…
WarriorAchilles b9bc9ea
removed 'CSG' from more information line
WarriorAchilles d3eff3d
Change display of modules
zkhussain a14943c
Merge pull request #80 from ius-csg/ze/503-page-updates
jasekiw 53235f6
Merge pull request #83 from ius-csg/zh/fix-display-of-modules
jasekiw 3a6e256
branch fixes and dependecy fixes
jhenry09 994a888
Merge branch 'dev' into jh/tag-bar
jhenry09 ea825f2
System messages (#71)
AClifton22 79d3467
fixing branch issues
jhenry09 58e7fcf
branch fixes
jhenry09 255decb
branch fixes
jhenry09 e684aa4
Merge branch 'dev' into jh/tag-bar
jhenry09 12afb7b
removed unneeded dependecies
jhenry09 460cc1f
Merge branch 'jh/tag-bar' of https://github.com/ius-csg/cslabs-webapp…
jhenry09 5cb93e5
fix merge conflicts
jhenry09 bd82b97
Do not display temp lab time/extension for other lab types
zkhussain e5f68c0
fixed route for getting tag
jhenry09 482f45d
Fixed issue with VM node movement when a new port is added
jhurst502 e46c2dd
Better undo and redo. Links now work for undo and redo.
jhurst502 26e50fc
fix tag endpoint
jasekiw c99ce7c
Merge pull request #72 from ius-csg/jh/tag-bar
jasekiw 51604ca
Update CI actions for master branch renaming
johnpcooke94 2c76d0a
Merge pull request #93 from ius-csg/jc/branch-rename
jasekiw 858976e
Merge pull request #86 from ius-csg/zh/extend-temp-lab-end-time
jasekiw 2ef30fe
Stated changing 'any' types to actual types found in diagrams library
jhurst502 c6fe261
Added library to caputure GUI as image
jhurst502 d9bac6b
Begin refactor to allow LabEditorGui to be toggle-able within existin…
jhurst502 b96de38
GUI is default in LabEditor, removed buttons in picture of diagram
jhurst502 181e876
Fixed more types
jhurst502 64ec7ec
Added logic to save gui topology as file
jhurst502 001bdda
Reverted accidental change for testing purposes
jhurst502 ca593e8
Rename bridges to cables in editor
jhurst502 fca19da
Remove port menu option
jhurst502 b837e35
Disable gui when not editing. Begin reformat of gui schema into exist…
jhurst502 628560a
Added uuids to nodes
jhurst502 213518d
More changes to make nodes work with uuids, add node type
jhurst502 f25f2f7
Reformatting schema links to match existing
jhurst502 c9c3bd6
Handled isCoreBridge for LabEditor GUI
jhurst502 9715c64
Slice port numbers off connected node
jhurst502 31b3af9
Merged dev
jhurst502 194b5d4
Revert bridge to Switch naming change
jhurst502 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
diff --git a/node_modules/beautiful-react-diagrams/Diagram/Link/Link.js b/node_modules/beautiful-react-diagrams/Diagram/Link/Link.js | ||
index e4a958b..5a34e47 100644 | ||
--- a/node_modules/beautiful-react-diagrams/Diagram/Link/Link.js | ||
+++ b/node_modules/beautiful-react-diagrams/Diagram/Link/Link.js | ||
@@ -62,9 +62,9 @@ var Link = function Link(props) { | ||
return getEntityCoordinates['default'](output, portRefs, nodeRefs, canvas); | ||
}, [output, portRefs, nodeRefs, canvas]); | ||
var pathOptions = { | ||
- type: input.type === 'port' || output.type === 'port' ? 'bezier' : 'curve', | ||
- inputAlignment: input.entity.alignment || null, | ||
- outputAlignment: output.entity.alignment || null | ||
+ type: (input?.type === 'port' || output?.type === 'port') ? 'bezier' : 'curve', | ||
+ inputAlignment: input?.entity?.alignment || null, | ||
+ outputAlignment: output?.entity?.alignment || null | ||
}; | ||
var path = React.useMemo(function () { | ||
return makeSvgPath['default'](inputPoint, outputPoint, pathOptions); | ||
diff --git a/node_modules/beautiful-react-diagrams/Diagram/Link/getEntityCoordinates.js b/node_modules/beautiful-react-diagrams/Diagram/Link/getEntityCoordinates.js | ||
index 87da7a7..1e69411 100644 | ||
--- a/node_modules/beautiful-react-diagrams/Diagram/Link/getEntityCoordinates.js | ||
+++ b/node_modules/beautiful-react-diagrams/Diagram/Link/getEntityCoordinates.js | ||
@@ -6,13 +6,13 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
var getRelativePoint = require('../../shared/functions/getRelativePoint.js'); | ||
|
||
var getEntityCoordinates = function getEntityCoordinates(entity, portRefs, nodeRefs, canvas) { | ||
- if (entity && entity.type === 'node' && nodeRefs[entity.entity.id]) { | ||
+ if (entity && entity?.type === 'node' && entity?.entity?.id && nodeRefs[entity.entity.id]) { | ||
var nodeEl = nodeRefs[entity.entity.id]; | ||
var bbox = nodeEl.getBoundingClientRect(); | ||
return [entity.entity.coordinates[0] + bbox.width / 2, entity.entity.coordinates[1] + bbox.height / 2]; | ||
} | ||
|
||
- if (portRefs && portRefs[entity.entity.id]) { | ||
+ if (portRefs && entity?.entity?.id && portRefs[entity.entity.id]) { | ||
var portEl = portRefs[entity.entity.id]; | ||
|
||
var _bbox = portEl.getBoundingClientRect(); | ||
diff --git a/node_modules/beautiful-react-diagrams/esm/Diagram/Link/Link.js b/node_modules/beautiful-react-diagrams/esm/Diagram/Link/Link.js | ||
index 306fffc..8d87c56 100644 | ||
--- a/node_modules/beautiful-react-diagrams/esm/Diagram/Link/Link.js | ||
+++ b/node_modules/beautiful-react-diagrams/esm/Diagram/Link/Link.js | ||
@@ -52,9 +52,9 @@ var Link = function Link(props) { | ||
return getEntityCoordinates(output, portRefs, nodeRefs, canvas); | ||
}, [output, portRefs, nodeRefs, canvas]); | ||
var pathOptions = { | ||
- type: input.type === 'port' || output.type === 'port' ? 'bezier' : 'curve', | ||
- inputAlignment: input.entity.alignment || null, | ||
- outputAlignment: output.entity.alignment || null | ||
+ type: (input?.type === 'port' || output?.type === 'port') ? 'bezier' : 'curve', | ||
+ inputAlignment: input?.entity?.alignment || null, | ||
+ outputAlignment: output?.entity?.alignment || null | ||
}; | ||
var path = useMemo(function () { | ||
return makeSvgPath(inputPoint, outputPoint, pathOptions); | ||
diff --git a/node_modules/beautiful-react-diagrams/esm/Diagram/Link/getEntityCoordinates.js b/node_modules/beautiful-react-diagrams/esm/Diagram/Link/getEntityCoordinates.js | ||
index be36a34..7a1e4f3 100644 | ||
--- a/node_modules/beautiful-react-diagrams/esm/Diagram/Link/getEntityCoordinates.js | ||
+++ b/node_modules/beautiful-react-diagrams/esm/Diagram/Link/getEntityCoordinates.js | ||
@@ -2,13 +2,13 @@ | ||
import getRelativePoint from '../../shared/functions/getRelativePoint.js'; | ||
|
||
var getEntityCoordinates = function getEntityCoordinates(entity, portRefs, nodeRefs, canvas) { | ||
- if (entity && entity.type === 'node' && nodeRefs[entity.entity.id]) { | ||
+ if (entity && entity?.type === 'node' && entity?.entity?.id && nodeRefs[entity.entity.id]) { | ||
var nodeEl = nodeRefs[entity.entity.id]; | ||
var bbox = nodeEl.getBoundingClientRect(); | ||
return [entity.entity.coordinates[0] + bbox.width / 2, entity.entity.coordinates[1] + bbox.height / 2]; | ||
} | ||
|
||
- if (portRefs && portRefs[entity.entity.id]) { | ||
+ if (portRefs && entity?.entity?.id && portRefs[entity.entity.id]) { | ||
var portEl = portRefs[entity.entity.id]; | ||
|
||
var _bbox = portEl.getBoundingClientRect(); | ||
diff --git a/node_modules/beautiful-react-diagrams/esm/hooks/useSchema/schemaReducer.js b/node_modules/beautiful-react-diagrams/esm/hooks/useSchema/schemaReducer.js | ||
index 829d14a..2198760 100644 | ||
--- a/node_modules/beautiful-react-diagrams/esm/hooks/useSchema/schemaReducer.js | ||
+++ b/node_modules/beautiful-react-diagrams/esm/hooks/useSchema/schemaReducer.js | ||
@@ -27,12 +27,14 @@ var schemaReducer = function schemaReducer(state, action) { | ||
|
||
if (state.nodes) { | ||
var index = findIndex(state.nodes, ['id', action.payload.nodeId]); | ||
- var inputPorts = getNodePortsId(state.nodes[index], 'inputs'); | ||
- var outputPorts = getNodePortsId(state.nodes[index], 'outputs'); | ||
- nextLinks = nextLinks.filter(function (link) { | ||
- return !inputPorts.includes(link.input) && !outputPorts.includes(link.output); | ||
- }); | ||
- state.nodes.splice(index, 1); | ||
+ if (index >= 0) { | ||
+ var inputPorts = getNodePortsId(state.nodes[index], 'inputs'); | ||
+ var outputPorts = getNodePortsId(state.nodes[index], 'outputs'); | ||
+ nextLinks = nextLinks.filter( | ||
+ (link) => !inputPorts.includes(link.input) && !outputPorts.includes(link.output), | ||
+ ); | ||
+ state.nodes.splice(index, 1); | ||
+ } | ||
} | ||
|
||
return { | ||
diff --git a/node_modules/beautiful-react-diagrams/hooks/useSchema/schemaReducer.js b/node_modules/beautiful-react-diagrams/hooks/useSchema/schemaReducer.js | ||
index fd9b41c..82c69b8 100644 | ||
--- a/node_modules/beautiful-react-diagrams/hooks/useSchema/schemaReducer.js | ||
+++ b/node_modules/beautiful-react-diagrams/hooks/useSchema/schemaReducer.js | ||
@@ -35,12 +35,14 @@ var schemaReducer = function schemaReducer(state, action) { | ||
|
||
if (state.nodes) { | ||
var index = findIndex__default['default'](state.nodes, ['id', action.payload.nodeId]); | ||
- var inputPorts = getNodePortsId['default'](state.nodes[index], 'inputs'); | ||
- var outputPorts = getNodePortsId['default'](state.nodes[index], 'outputs'); | ||
- nextLinks = nextLinks.filter(function (link) { | ||
- return !inputPorts.includes(link.input) && !outputPorts.includes(link.output); | ||
- }); | ||
- state.nodes.splice(index, 1); | ||
+ if (index >= 0) { | ||
+ var inputPorts = getNodePortsId(state.nodes[index], 'inputs'); | ||
+ var outputPorts = getNodePortsId(state.nodes[index], 'outputs'); | ||
+ nextLinks = nextLinks.filter( | ||
+ (link) => !inputPorts.includes(link.input) && !outputPorts.includes(link.output), | ||
+ ); | ||
+ state.nodes.splice(index, 1); | ||
+ } | ||
} | ||
|
||
return { |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { useRef } from 'react'; | ||
import ContextMenu from './ContextMenu'; | ||
|
||
|
||
const ContextContainer = ({ children, menuItems, schema}: any) => { | ||
const containerRef = useRef(null); | ||
|
||
return ( | ||
<div ref={containerRef}> | ||
{children} | ||
<ContextMenu | ||
schema={schema} | ||
parentRef={containerRef} | ||
items={menuItems} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ContextContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.context-menu { | ||
position: fixed; | ||
background-color: #d6d8db; | ||
padding: 10px 0; | ||
cursor: default; | ||
border-radius: 5px; | ||
z-index: 2000; | ||
} | ||
|
||
.context-menu__item { | ||
padding: 0 30px; | ||
} | ||
|
||
.context-menu .context-menu__item:hover { | ||
background-color: #c7c7c9; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import './ContextMenu.css'; | ||
|
||
const ContextMenu = ({parentRef, items}:any) => { | ||
const [isVisible, setVisibility ] = useState(false); | ||
const [x, setX] = useState(0); | ||
const [y, setY] = useState(0); | ||
|
||
useEffect(() => { | ||
const parent = parentRef.current; | ||
if (!parent) { | ||
return; | ||
} | ||
|
||
const showMenu = (event: any) => { | ||
event.preventDefault(); | ||
setX(event.clientX); | ||
setY(event.clientY); | ||
setVisibility(true); | ||
}; | ||
|
||
const closeMenu = () => { | ||
setVisibility(false); | ||
}; | ||
|
||
parent.addEventListener('contextmenu', showMenu); | ||
window.addEventListener('click', closeMenu); | ||
|
||
return () => { | ||
parent.removeEventListener('contextmenu', showMenu); | ||
window.removeEventListener('click', closeMenu); | ||
}; | ||
}); | ||
|
||
const style = { | ||
top: y, | ||
left: x | ||
}; | ||
|
||
|
||
return isVisible ? ( | ||
<div className='context-menu' style={style}> | ||
{items.map((item: any, index: any) => { | ||
return ( | ||
<div | ||
key={index} | ||
onClick={item.onClick} | ||
className='context-menu__item' | ||
> | ||
{item.text} | ||
</div> | ||
); | ||
})} | ||
jhurst502 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</div> | ||
) : null; | ||
}; | ||
|
||
export default ContextMenu; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid use any, go through and find usages of any and find what type they should be.