|
| 1 | +/** |
| 2 | + * Copyright (c) 2025, RTE (http://www.rte-france.com) |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + */ |
| 7 | +import { Dialog, Fab, Theme } from '@mui/material'; |
| 8 | +import { useCallback, useRef } from 'react'; |
| 9 | +import { UUID } from 'crypto'; |
| 10 | +import { EquipmentType, LineFlowMode, NetworkVisualizationParameters, useStateBoolean } from '@gridsuite/commons-ui'; |
| 11 | +import { useDispatch, useSelector } from 'react-redux'; |
| 12 | +import { AppState } from 'redux/reducer'; |
| 13 | +import { resetMapEquipment, setMapDataLoading, setOpenMap, setReloadMapNeeded } from 'redux/actions'; |
| 14 | +import NetworkMapPanel, { NetworkMapPanelRef } from 'components/network/network-map-panel'; |
| 15 | +import { Close } from '@mui/icons-material'; |
| 16 | +import { FormattedMessage } from 'react-intl'; |
| 17 | +import { CurrentTreeNode } from 'components/graph/tree-node.type'; |
| 18 | + |
| 19 | +const styles = { |
| 20 | + closeButton: (theme: Theme) => ({ |
| 21 | + alignSelf: 'center', |
| 22 | + margin: theme.spacing(1), |
| 23 | + padding: theme.spacing(2), |
| 24 | + }), |
| 25 | +}; |
| 26 | + |
| 27 | +interface MapDialogProps { |
| 28 | + studyUuid: UUID; |
| 29 | + onClose: () => void; |
| 30 | + errorMessage?: string; |
| 31 | + showInSpreadsheet: (equipment: { equipmentId: string | null; equipmentType: EquipmentType | null }) => void; |
| 32 | + onOpenNetworkAreaDiagram: (elementId?: string) => void; |
| 33 | + currentRootNetworkUuid: UUID; |
| 34 | + networkVisuParams: NetworkVisualizationParameters; |
| 35 | + currentNode: CurrentTreeNode; |
| 36 | +} |
| 37 | + |
| 38 | +export const MapDialog = (props: MapDialogProps) => { |
| 39 | + const { |
| 40 | + studyUuid, |
| 41 | + onClose, |
| 42 | + currentRootNetworkUuid, |
| 43 | + networkVisuParams, |
| 44 | + showInSpreadsheet, |
| 45 | + onOpenNetworkAreaDiagram, |
| 46 | + currentNode, |
| 47 | + } = props; |
| 48 | + |
| 49 | + const dispatch = useDispatch(); |
| 50 | + |
| 51 | + const mapOpen = useSelector((state: AppState) => state.mapOpen); |
| 52 | + |
| 53 | + const isInDrawingMode = useStateBoolean(false); |
| 54 | + const networkMapPanelRef = useRef<NetworkMapPanelRef>(null); |
| 55 | + |
| 56 | + const handleCloseMap = useCallback( |
| 57 | + (event?: any, reason?: string) => { |
| 58 | + if (isInDrawingMode.value) { |
| 59 | + networkMapPanelRef.current?.leaveDrawingMode(); |
| 60 | + if (reason && reason === 'escapeKeyDown') { |
| 61 | + return; // Do not close the map but only the drawing mode |
| 62 | + } |
| 63 | + } |
| 64 | + dispatch(setOpenMap(false)); |
| 65 | + dispatch(resetMapEquipment()); |
| 66 | + dispatch(setMapDataLoading(false)); |
| 67 | + dispatch(setReloadMapNeeded(true)); |
| 68 | + onClose(); |
| 69 | + }, |
| 70 | + [dispatch, isInDrawingMode, onClose] |
| 71 | + ); |
| 72 | + |
| 73 | + return ( |
| 74 | + <Dialog open={mapOpen} onClose={handleCloseMap} fullScreen> |
| 75 | + <Fab onClick={handleCloseMap} size="small" aria-label="close" variant="extended" sx={styles.closeButton}> |
| 76 | + <Close fontSize="small" /> |
| 77 | + <FormattedMessage id="close" /> |
| 78 | + </Fab> |
| 79 | + <NetworkMapPanel |
| 80 | + ref={networkMapPanelRef} |
| 81 | + studyUuid={studyUuid} |
| 82 | + visible={mapOpen} |
| 83 | + lineFullPath={networkVisuParams.mapParameters.lineFullPath} |
| 84 | + lineParallelPath={networkVisuParams.mapParameters.lineParallelPath} |
| 85 | + lineFlowMode={networkVisuParams.mapParameters.lineFlowMode as LineFlowMode} |
| 86 | + currentNode={currentNode} |
| 87 | + currentRootNetworkUuid={currentRootNetworkUuid} |
| 88 | + showInSpreadsheet={(eq) => { |
| 89 | + handleCloseMap(); |
| 90 | + showInSpreadsheet(eq); |
| 91 | + }} |
| 92 | + onOpenNetworkAreaDiagram={onOpenNetworkAreaDiagram} |
| 93 | + onPolygonChanged={() => {}} |
| 94 | + isInDrawingMode={isInDrawingMode} |
| 95 | + /> |
| 96 | + </Dialog> |
| 97 | + ); |
| 98 | +}; |
| 99 | + |
| 100 | +export default MapDialog; |
0 commit comments