From be213cce39d25a11dcf9c1c04b28870d0686a857 Mon Sep 17 00:00:00 2001 From: BOUHOURS Antoine Date: Tue, 4 Aug 2026 10:02:53 +0200 Subject: [PATCH] Warn instead of crash when network contains voltage level without substation --- src/components/network/network-map-panel.tsx | 36 +++++++++++++++++++- src/translations/en.json | 1 + src/translations/fr.json | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/components/network/network-map-panel.tsx b/src/components/network/network-map-panel.tsx index 9c57dd3606..5d9872933b 100644 --- a/src/components/network/network-map-panel.tsx +++ b/src/components/network/network-map-panel.tsx @@ -172,7 +172,7 @@ export const NetworkMapPanel = memo(function NetworkMapPanel({ const [isInitialized, setIsInitialized] = useState(false); const mapBoxToken = useMapBoxToken(); - const { snackError } = useSnackMessage(); + const { snackError, snackWarning } = useSnackMessage(); const [filteredNominalVoltages, setFilteredNominalVoltages] = useState(); const [geoData, setGeoData] = useState(); @@ -180,8 +180,23 @@ export const NetworkMapPanel = memo(function NetworkMapPanel({ const basicDataReady = mapEquipments && geoData; + const voltageLevelIdsWithoutSubstation = useMemo(() => { + if (!mapEquipments) { + return []; + } + + const voltageLevelIds = new Set([ + ...mapEquipments.getLines().flatMap((line) => [line.voltageLevelId1, line.voltageLevelId2]), + ...mapEquipments.getTieLines().flatMap((line) => [line.voltageLevelId1, line.voltageLevelId2]), + ...mapEquipments.getHvdcLines().flatMap((line) => [line.voltageLevelId1, line.voltageLevelId2]), + ]); + + return Array.from(voltageLevelIds).filter((voltageLevelId) => !mapEquipments.getVoltageLevel(voltageLevelId)); + }, [mapEquipments]); + const lineFullPathRef = useRef(null); const [isDialogSearchOpen, setIsDialogSearchOpen] = useState(false); + const voltageLevelWarningShownRef = useRef(false); const { getBaseVoltageInterval } = useBaseVoltages(); @@ -210,6 +225,25 @@ export const NetworkMapPanel = memo(function NetworkMapPanel({ const currentNodeRef = useRef(null); const currentRootNetworkUuidRef = useRef(null); + useEffect(() => { + if (!isInitialized) { + voltageLevelWarningShownRef.current = false; + } else if (voltageLevelIdsWithoutSubstation.length > 0 && !voltageLevelWarningShownRef.current) { + const voltageLevelIds = + voltageLevelIdsWithoutSubstation.length > 3 + ? voltageLevelIdsWithoutSubstation.slice(0, 3).join(', ') + ', ...' + : voltageLevelIdsWithoutSubstation.join(', '); + snackWarning({ + messageId: 'networkMapVoltageLevelsWithoutSubstation', + messageValues: { + voltageLevelCount: voltageLevelIdsWithoutSubstation.length, + voltageLevelIds: voltageLevelIds, + }, + }); + voltageLevelWarningShownRef.current = true; + } + }, [isInitialized, snackWarning, voltageLevelIdsWithoutSubstation]); + const [updatedLines, setUpdatedLines] = useState([]); const [updatedTieLines, setUpdatedTieLines] = useState([]); const [updatedHvdcLines, setUpdatedHvdcLines] = useState([]); diff --git a/src/translations/en.json b/src/translations/en.json index 12300342bb..ac0e9e243d 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -68,6 +68,7 @@ "svgNotFound": "Diagram has not been found: {error}; {svgUrl}", "networkLoadingFail": "Network of study with id \"{studyUuid}\" couldn't be loaded", "geoDataLoadingFail": "An error occurred while loading geographical data.", + "networkMapVoltageLevelsWithoutSubstation": "{voltageLevelCount} voltage levels are not attached to a substation and therefore are not displayed. Examples: {voltageLevelIds}", "parameters": "Parameters", "close": "Close", diff --git a/src/translations/fr.json b/src/translations/fr.json index 9cc2628b65..bc0249957a 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -68,6 +68,7 @@ "svgNotFound": "L'image poste n'a pas été trouvée : {error}; {svgUrl}", "networkLoadingFail": "Le réseau de l'étude avec l'identifiant \"{studyUuid}\" n'a pas pu être chargé", "geoDataLoadingFail": "Erreur lors du chargement des données géographiques.", + "networkMapVoltageLevelsWithoutSubstation": "{voltageLevelCount} niveaux de tension ne sont pas rattachés à un site et ne sont donc pas affichés. Exemples : {voltageLevelIds}", "parameters": "Paramètres", "close": "Fermer",