@@ -10,7 +10,7 @@ import { Layout, Layouts, Responsive, WidthProvider } from 'react-grid-layout';
10
10
import { useDiagramModel } from './hooks/use-diagram-model' ;
11
11
import { Diagram , DiagramParams , DiagramType } from './diagram.type' ;
12
12
import { Box , useTheme } from '@mui/material' ;
13
- import { ElementType , EquipmentInfos , EquipmentType , useDebounce } from '@gridsuite/commons-ui' ;
13
+ import { ElementType , EquipmentInfos , EquipmentType , useDebounce , useSnackMessage } from '@gridsuite/commons-ui' ;
14
14
import { UUID } from 'crypto' ;
15
15
import { useDiagramsGridLayoutInitialization } from './hooks/use-diagrams-grid-layout-initialization' ;
16
16
import { v4 } from 'uuid' ;
@@ -21,6 +21,7 @@ import MapCard from './map-card';
21
21
import { BLINK_LENGTH_MS } from './card-header' ;
22
22
import CustomResizeHandle from './custom-resize-handle' ;
23
23
import { useSaveDiagramLayout } from './hooks/use-save-diagram-layout' ;
24
+ import { countOpenedNadDiagrams , MAX_NUMBER_OF_NAD_DIAGRAMS } from './diagram-grid-layout-utils' ;
24
25
25
26
const styles = {
26
27
container : {
@@ -147,16 +148,19 @@ const initialLayouts: Layouts = generateInitialLayouts();
147
148
interface DiagramGridLayoutProps {
148
149
studyUuid : UUID ;
149
150
showInSpreadsheet : ( equipment : { equipmentId : string | null ; equipmentType : EquipmentType | null } ) => void ;
151
+ showGrid : ( ) => void ;
150
152
visible : boolean ;
151
153
}
152
154
153
- function DiagramGridLayout ( { studyUuid, showInSpreadsheet, visible } : Readonly < DiagramGridLayoutProps > ) {
155
+ function DiagramGridLayout ( { studyUuid, showInSpreadsheet, showGrid , visible } : Readonly < DiagramGridLayoutProps > ) {
154
156
const theme = useTheme ( ) ;
155
157
const [ layouts , setLayouts ] = useState < Layouts > ( initialLayouts ) ;
156
158
const [ blinkingDiagrams , setBlinkingDiagrams ] = useState < UUID [ ] > ( [ ] ) ;
157
159
const currentBreakpointRef = useRef < string > ( 'lg' ) ;
158
160
const lastModifiedBreakpointRef = useRef < string > ( 'lg' ) ; // Track the last modified breakpoint
159
161
162
+ const { snackInfo } = useSnackMessage ( ) ;
163
+
160
164
// Blinking diagrams management
161
165
const stopDiagramBlinking = useCallback ( ( diagramUuid : UUID ) => {
162
166
setBlinkingDiagrams ( ( old_blinking_diagrams ) => old_blinking_diagrams . filter ( ( uuid ) => uuid !== diagramUuid ) ) ;
@@ -253,10 +257,11 @@ function DiagramGridLayout({ studyUuid, showInSpreadsheet, visible }: Readonly<D
253
257
}
254
258
255
259
if ( diagram ) {
260
+ showGrid ( ) ;
256
261
createDiagram ( diagram ) ;
257
262
}
258
263
} ,
259
- [ createDiagram ]
264
+ [ createDiagram , showGrid ]
260
265
) ;
261
266
262
267
const handleLoadNad = useCallback (
@@ -380,6 +385,21 @@ function DiagramGridLayout({ studyUuid, showInSpreadsheet, visible }: Readonly<D
380
385
} , [ ] ) ;
381
386
useDiagramsGridLayoutInitialization ( { onLoadDiagramLayout } ) ;
382
387
388
+ const onOpenNetworkAreaDiagram = useCallback (
389
+ ( elementId ?: string ) => {
390
+ if ( countOpenedNadDiagrams ( diagrams ) < MAX_NUMBER_OF_NAD_DIAGRAMS ) {
391
+ if ( ! elementId ) {
392
+ return ;
393
+ }
394
+ snackInfo ( {
395
+ messageId : 'NADOpenedInTheGrid' ,
396
+ messageValues : { elementId : elementId } ,
397
+ } ) ;
398
+ }
399
+ } ,
400
+ [ diagrams , snackInfo ]
401
+ ) ;
402
+
383
403
const handleGridLayoutSave = useSaveDiagramLayout ( { layouts, diagrams } ) ;
384
404
385
405
// Debounce the layout save function to avoid excessive calls
@@ -390,6 +410,7 @@ function DiagramGridLayout({ studyUuid, showInSpreadsheet, visible }: Readonly<D
390
410
< DiagramGridHeader
391
411
onLoad = { handleLoadNad }
392
412
onSearch = { showVoltageLevelDiagram }
413
+ onOpenNetworkAreaDiagram = { showGrid }
393
414
onMap = { ! isMapCardAdded ( ) ? onAddMapCard : undefined }
394
415
onLayoutSave = { debouncedGridLayoutSave }
395
416
/>
@@ -451,6 +472,7 @@ function DiagramGridLayout({ studyUuid, showInSpreadsheet, visible }: Readonly<D
451
472
onClose = { handleRemoveMapCard }
452
473
errorMessage = { globalError }
453
474
showInSpreadsheet = { showInSpreadsheet }
475
+ onOpenNetworkAreaDiagram = { onOpenNetworkAreaDiagram }
454
476
/>
455
477
) }
456
478
</ ResponsiveGridLayout >
0 commit comments