@@ -167,6 +167,7 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
167
167
const responsiveGridLayoutRef = useRef < any > ( null ) ;
168
168
const currentBreakpointRef = useRef < string > ( 'lg' ) ;
169
169
const lastModifiedBreakpointRef = useRef < string > ( 'lg' ) ; // Track the last modified breakpoint
170
+ const [ disableStoreButton , setDisableStoreButton ] = useState < boolean > ( true ) ;
170
171
171
172
const { snackInfo } = useSnackMessage ( ) ;
172
173
@@ -198,6 +199,7 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
198
199
const addLayoutItem = useCallback ( ( diagram : Diagram ) => {
199
200
lastModifiedBreakpointRef . current = currentBreakpointRef . current ;
200
201
setLayouts ( ( currentLayouts ) => createLayoutItem ( diagram . diagramUuid , currentLayouts ) ) ;
202
+ setDisableStoreButton ( false ) ;
201
203
} , [ ] ) ;
202
204
203
205
const removeLayoutItem = useCallback ( ( cardUuid : UUID | string ) => {
@@ -212,6 +214,7 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
212
214
213
215
return newLayouts ;
214
216
} ) ;
217
+ setDisableStoreButton ( false ) ;
215
218
} , [ ] ) ;
216
219
217
220
const onAddMapCard = useCallback ( ( ) => {
@@ -237,6 +240,22 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
237
240
onDiagramAlreadyExists,
238
241
} ) ;
239
242
243
+ const handleUpdateDiagram = useCallback (
244
+ ( diagram : Diagram ) => {
245
+ setDisableStoreButton ( false ) ;
246
+ updateDiagram ( diagram ) ;
247
+ } ,
248
+ [ updateDiagram ]
249
+ ) ;
250
+
251
+ const handleUpdateDiagramPositions = useCallback (
252
+ ( diagramParams : DiagramParams ) => {
253
+ setDisableStoreButton ( false ) ;
254
+ updateDiagramPositions ( diagramParams ) ;
255
+ } ,
256
+ [ updateDiagramPositions ]
257
+ ) ;
258
+
240
259
const onRemoveCard = useCallback (
241
260
( diagramUuid : UUID ) => {
242
261
removeLayoutItem ( diagramUuid ) ;
@@ -369,6 +388,7 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
369
388
370
389
return newLayouts ;
371
390
} ) ;
391
+ setDisableStoreButton ( false ) ;
372
392
} , [ ] ) ;
373
393
374
394
/**
@@ -400,6 +420,7 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
400
420
lastModifiedBreakpointRef . current = currentBreakpointRef . current ;
401
421
// Ensure final order is propagated to all breakpoints
402
422
propagateOrder ( layout , currentBreakpointRef . current ) ;
423
+ setDisableStoreButton ( false ) ;
403
424
} ,
404
425
[ propagateOrder ]
405
426
) ;
@@ -411,6 +432,7 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
411
432
} else {
412
433
setLayouts ( initialLayouts ) ;
413
434
}
435
+ setDisableStoreButton ( true ) ;
414
436
} , [ ] ) ;
415
437
useDiagramsGridLayoutInitialization ( { onLoadDiagramLayout } ) ;
416
438
@@ -429,10 +451,15 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
429
451
[ diagrams , snackInfo ]
430
452
) ;
431
453
432
- const handleGridLayoutSave = useSaveDiagramLayout ( { layouts, diagrams } ) ;
454
+ const gridLayoutSave = useSaveDiagramLayout ( { layouts, diagrams } ) ;
433
455
434
456
// Debounce the layout save function to avoid excessive calls
435
- const debouncedGridLayoutSave = useDebounce ( handleGridLayoutSave , 300 ) ;
457
+ const debouncedGridLayoutSave = useDebounce ( gridLayoutSave , 300 ) ;
458
+
459
+ const handleGridLayoutSave = useCallback ( ( ) => {
460
+ setDisableStoreButton ( true ) ;
461
+ debouncedGridLayoutSave ( ) ;
462
+ } , [ debouncedGridLayoutSave ] ) ;
436
463
437
464
return (
438
465
< Box sx = { styles . container } >
@@ -441,7 +468,8 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
441
468
onSearch = { showVoltageLevelDiagram }
442
469
onOpenNetworkAreaDiagram = { showGrid }
443
470
onMap = { ! isMapCardAdded ( ) ? onAddMapCard : undefined }
444
- onLayoutSave = { debouncedGridLayoutSave }
471
+ onLayoutSave = { handleGridLayoutSave }
472
+ disableStore = { disableStoreButton }
445
473
/>
446
474
< ResponsiveGridLayout
447
475
ref = { responsiveGridLayoutRef } // the provided innerRef prop is bugged (see https://github.com/react-grid-layout/react-grid-layout/issues/1444)
@@ -490,8 +518,8 @@ function GridLayoutPanel({ studyUuid, showInSpreadsheet, showGrid, visible }: Re
490
518
onClose = { ( ) => onRemoveCard ( diagram . diagramUuid ) }
491
519
showInSpreadsheet = { showInSpreadsheet }
492
520
createDiagram = { createDiagram }
493
- updateDiagram = { updateDiagram }
494
- updateDiagramPositions = { updateDiagramPositions }
521
+ updateDiagram = { handleUpdateDiagram }
522
+ updateDiagramPositions = { handleUpdateDiagramPositions }
495
523
/>
496
524
) ;
497
525
} ) }
0 commit comments