@@ -1191,6 +1191,58 @@ export const ApplicationResourceTree = (props: ApplicationResourceTreeProps) =>
1191
1191
} ) ;
1192
1192
const graphNodes = graph . nodes ( ) ;
1193
1193
const size = getGraphSize ( graphNodes . map ( id => graph . node ( id ) ) ) ;
1194
+
1195
+ const resourceTreeRef = React . useRef < HTMLDivElement > ( ) ;
1196
+
1197
+ const graphMoving = React . useRef ( {
1198
+ enable : false ,
1199
+ x : 0 ,
1200
+ y : 0
1201
+ } ) ;
1202
+
1203
+ const onGraphDragStart : React . PointerEventHandler < HTMLDivElement > = e => {
1204
+ if ( e . target !== resourceTreeRef . current ) {
1205
+ return ;
1206
+ }
1207
+
1208
+ if ( ! resourceTreeRef . current ?. parentElement ) {
1209
+ return ;
1210
+ }
1211
+
1212
+ graphMoving . current . enable = true ;
1213
+ graphMoving . current . x = e . clientX ;
1214
+ graphMoving . current . y = e . clientY ;
1215
+ } ;
1216
+
1217
+ const onGraphDragMoving : React . PointerEventHandler < HTMLDivElement > = e => {
1218
+ if ( ! graphMoving . current . enable ) {
1219
+ return ;
1220
+ }
1221
+
1222
+ if ( ! resourceTreeRef . current ?. parentElement ) {
1223
+ return ;
1224
+ }
1225
+
1226
+ const graphContainer = resourceTreeRef . current ?. parentElement ;
1227
+
1228
+ const currentPositionX = graphContainer . scrollLeft ;
1229
+ const currentPositionY = graphContainer . scrollTop ;
1230
+
1231
+ const scrollLeft = currentPositionX + graphMoving . current . x - e . clientX ;
1232
+ const scrollTop = currentPositionY + graphMoving . current . y - e . clientY ;
1233
+
1234
+ graphContainer . scrollTo ( scrollLeft , scrollTop ) ;
1235
+
1236
+ graphMoving . current . x = e . clientX ;
1237
+ graphMoving . current . y = e . clientY ;
1238
+ } ;
1239
+
1240
+ const onGraphDragEnd : React . PointerEventHandler < HTMLDivElement > = e => {
1241
+ if ( graphMoving . current . enable ) {
1242
+ graphMoving . current . enable = false ;
1243
+ e . preventDefault ( ) ;
1244
+ }
1245
+ } ;
1194
1246
return (
1195
1247
( graphNodes . length === 0 && (
1196
1248
< EmptyState icon = ' fa fa-network-wired' >
@@ -1199,6 +1251,11 @@ export const ApplicationResourceTree = (props: ApplicationResourceTreeProps) =>
1199
1251
</ EmptyState >
1200
1252
) ) || (
1201
1253
< div
1254
+ ref = { resourceTreeRef }
1255
+ onPointerDown = { onGraphDragStart }
1256
+ onPointerMove = { onGraphDragMoving }
1257
+ onPointerUp = { onGraphDragEnd }
1258
+ onPointerLeave = { onGraphDragEnd }
1202
1259
className = { classNames ( 'application-resource-tree' , { 'application-resource-tree--network' : props . useNetworkingHierarchy } ) }
1203
1260
style = { { width : size . width + 150 , height : size . height + 250 , transformOrigin : '0% 0%' , transform : `scale(${ props . zoom } )` } } >
1204
1261
{ graphNodes . map ( key => {
0 commit comments